In Java I can distinguish between 0D and -0D:
new Double("0").equals(new Double("-0")) // false
But apparently this seems not to work anymore after GWT transpiled my Java to JavaScript. I even get false
in GWT dev-mode but true
in GWT super-dev-mode.
I've read that in JavaScript
0.0 === -0.0 // true
but
Object.is(0, -0) // false
How can I force GWT to use the Object.is
comparision? Or is there any other solution to check if I got a negative or positive zero?
OK, after some more research, I came up with a solution using JSNI:
native boolean isNegative(double value)
/*-{
return 1 / value < 0;
}-*/;
As 1/-0
produces -Infinity
in JavaScript, this one works.