[
https://issues.apache.org/jira/browse/GROOVY-8077?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15856639#comment-15856639
]
Tomas Rokicki commented on GROOVY-8077:
---------------------------------------
Same problem with the comparators:
groovy:000> a = new Double(0)
===> 0.0
groovy:000> b = new Double(-1)
===> -1.0
groovy:000> a * b < 0
===> true
Definitely affects float and double. Does not affect BigDecimal or BigInteger.
> 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)