[
https://issues.apache.org/jira/browse/GROOVY-3309?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149436#comment-18149436
]
ASF GitHub Bot commented on GROOVY-3309:
----------------------------------------
daniellansun opened a new pull request, #3334:
URL: https://github.com/apache/groovy/pull/3334
https://issues.apache.org/jira/browse/GROOVY-3309
Boolean comparisons that go through `ScriptBytecodeAdapter` (`==`, `!=`,
`<`, `<=`, `>`, `>=`) are now false when one operand is a `Double` or `Float`
NaN and the other is numeric. That includes a NaN compared with itself, and
mixed types such as `Double.NaN > 0`. It matches a primitive `double` or
`float` (JLS 15.20.1 / 15.21.1) and the primitive comparisons fixed in
GROOVY-12538.
This is a Groovy 7 behavioral change and should not be backported to 6.0.x.
Code that used `value == Double.NaN` or `x != x` on a boxed NaN should use
`Double.isNaN` or `Float.isNaN` instead.
`<=>` is unchanged and still follows `Double.compare`. `is` / `===`, Groovy
truth, and `equals` / `in` / `switch` / `List.contains` are also unchanged.
Because this is a runtime helper change, already-compiled classes pick it up
without recompilation.
`testGroovy3309` now runs as a regular test; its assertions are unchanged.
Additional coverage is in `Groovy3309`.
> comparisons with NaN should always return false
> -----------------------------------------------
>
> Key: GROOVY-3309
> URL: https://issues.apache.org/jira/browse/GROOVY-3309
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 1.5.7, 1.6-rc-2
> Environment: os x, jse 5 and 6
> Reporter: Andy Fyfe
> Assignee: Daniel Sun
> Priority: Major
> Fix For: 4.x
>
>
> The following assertions should all pass; the third fails.
> {code}
> assert !(Double.NaN == 0)
> assert !(Double.NaN < 0)
> assert !(Double.NaN > 0)
> {code}
> A NaN should also not equal a NaN.
> {code}assert Double.NaN != Double.NaN{code}
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)