question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ToleranceMatcher is unable to compare NaN doubles

See original GitHub issue

Code:

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:closed
  • Created 6 years ago
  • Comments:15 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
LeoColmancommented, Jan 8, 2019

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”

0reactions
breandancommented, Jan 8, 2019

Done, please use #530 to discuss custom generators for restricted subsets of floating point values.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found