Skip to content

Abnormal behavior with comparison operators #189

Description

@GoldenTotem

Negative double zero is considered as less than 0, and not equals to positive zero. And NaN is considered large than Infinity.

#debug
var a as double = 0.0;
var b as double = -0.0;
print(a);
print(b);
print(a==b);
print(-a);
print(-b);
print(-b==a);
print(a>0);
print(a==0);
print(b<0);
print(b==0);
print(0.0/0.0 > 1.0/0.0);//NaN > Positive Infinity

output:

0.0
-0.0
false
-0.0
0.0
true
false
true
true
false
true

That's may because it calls Double.compare().

import com.blamejared.crafttweaker.api.CraftTweakerGlobals;

public class Test {
    public static void run() {
        double a = 0.0;
        double b = -0.0;
        CraftTweakerGlobals.print(Double.toString(a));
        CraftTweakerGlobals.print(Double.toString(b));
        CraftTweakerGlobals.print(Boolean.toString(Double.compare(a, b) == 0));
        CraftTweakerGlobals.print(Double.toString(-a));
        CraftTweakerGlobals.print(Double.toString(-b));
        CraftTweakerGlobals.print(Boolean.toString(Double.compare(-b, a) == 0));
        CraftTweakerGlobals.print(Boolean.toString(Double.compare(a, (double)0) > 0));
        CraftTweakerGlobals.print(Boolean.toString(Double.compare(a, (double)0) == 0));
        CraftTweakerGlobals.print(Boolean.toString(Double.compare(b, (double)0) < 0));
        CraftTweakerGlobals.print(Boolean.toString(Double.compare(b, (double)0) == 0));
        CraftTweakerGlobals.print(Boolean.toString(Double.compare(0.0 / 0.0, 1.0 / 0.0) > 0));
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions