ToleranceMatcher is unable to compare NaN doubles
See original GitHub issueCode:
Double.NaN shouldBe Double.NaN
Expected result: no errors, NaN == NaN
Actual result: java.lang.AssertionError: NaN should be equal to NaN
So, we have to have separate comparison for NaN values. JUnit does this - code below does not throw any exceptions:
assertEquals(Double.NaN, Double.NaN)
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (14 by maintainers)
Top Results From Across the Web
ScalaTest Scalactic - Custom Double Equality with tolerance ...
areEqual(expected, number) when comparing non-nan doubles in order to be able to use the tolerance implicit in that comparison.
Read more >Double.NaN Field (System) - Microsoft Learn
In general, Double operators cannot be used to compare Double.NaN with other Double values, although comparison methods (such as Equals and CompareTo) can....
Read more >Changelog - Kotest
Error doesn't work on FeatureSpec #1864; Incomplete edge cases with the double generator #1869; Unexpected ToleranceMatcher behavior at infinite doubles # ...
Read more >Double "NaN" Problem, how do i check the double before ...
It says it cannot be dereferenced or something. You are calling isNan() on a primitive double which will not work. Either create a...
Read more >NUM07-J. Do not attempt comparisons with NaN
NaN (not-a-number) is unordered, so the numerical comparison operators < , <= , > ... input validation checks that fail to consider the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, you must either filter or handle NaN and Infinities.
The point in generators is that you’re saying “My program can handle absolutely any Double!” and both NaN and Infinities are valid doubles to be passed.
What we can discuss is if we should support out-of-the-box a matcher for “Numeric, non-corner-case Doubles”
Done, please use #530 to discuss custom generators for restricted subsets of floating point values.