0

I googled the answer. They said use Double.compare(). It does not work.

Double.compare(-0d, 0d) < 0

This gives me false. Should be true.

Math.signum() does not work with -0d. The document says it will give me back -0d.

On the other hand, if I have a formula that calculate the value to be -zero, compare gives me a different answer.

def xyz = -0d
Double.compare(xyz, 0d) < 0 will give me false
def xyz = 0d * -1d
Double.compare(xyz, 0d) < 0 will give me true

Is this a bug in Grails?

tom6502
  • 180
  • 7

1 Answers1

0

Why do you expect comparing -0d with 0d to be not equal?

Double.compare(-0d, 0d) < 0// returns false

cause

Double.compare(-0d, 0d) == 0 //returns true
Michal_Szulc
  • 4,097
  • 6
  • 32
  • 59
  • Let me try Math.signum() again. I may have read the document wrong. signum() may work. compare() is just not reliable to me. Worst case scenario is to turn the number into a string and to look for the minus letter in the first letter. – tom6502 Oct 29 '21 at 18:39