Tomas Rokicki created GROOVY-8077:
-------------------------------------
Summary: double comparison (apparently) uses .equals and not ==
Key: GROOVY-8077
URL: https://issues.apache.org/jira/browse/GROOVY-8077
Project: Groovy
Issue Type: Bug
Components: Compiler
Affects Versions: 2.4.8
Environment: Windows (but probably generic)
Reporter: Tomas Rokicki
groovy:000> f1 = new Double(-1)
===> -1.0
groovy:000> f2 = new Double(0)
===> 0.0
groovy:000> f3 = new Double(1)
===> 1.0
groovy:000> (f1 * f2) == (f2 * f3)
===> false
This should return true. It appears (f1*f2)==(f2*f3) is being compiled to
Double#equals(Double) where it should be compiled to unboxed float comparisons.
IEEE874 requires -0.0 be equal to 0.0 when using a normal arithmetic
comparison. Note that Java does the correct thing with ==.
Double#equals(Double) (and #compareTo and #hashCode) are defined to distinguish
negative zero from zero so hash tables "work properly".
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)