Ben Woodworth
10/29/2022, 5:04 AM0f shouldBe -0f
failing like I expect, but NaN shouldBe NaN
failing when I'd want it to pass. (also worth noting, 0f shouldBeExactly -0f
does fail, and so does 0f shouldBeEqualComparingTo -0f
)
I saw several discussions in the issue tracker which conclude that "IEEE says they're equal". Which I do understand, but I would've expected shouldBeExactly
to work like I expect here
(failing for ±0
and passing for NaN
), and maybe a similar shouldEqual
that's the opposite for these cases
(passing for ±0
and failing for NaN
) going off ==
behind the scenes, in turn following the IEEE spec.
I couldn't find one, but is there a function out there to accomplish this? Something that confirms values are "the same", e.g. for an identity function that should work for any/all values thrown at it. I'll probably write my own Float/Double shouldBinaryEqual
functions but I would be curious what others thinkBen Woodworth
10/29/2022, 5:44 AMDavio
10/29/2022, 6:51 AMBen Woodworth
11/02/2022, 2:49 AMDavio
11/02/2022, 9:43 AMDouble.NaN == Double.NaN
which yields false by design, it says so in the JDK docs for Double:
Ifandv1
are both NaN, thenv2
v1
has the value== v2
. Therefore, for two NaN arguments the reflexive property of an equivalence relation is not satisfied by thefalse
operator.==
Davio
11/02/2022, 9:46 AMDavio
11/02/2022, 9:48 AMBen Woodworth
11/02/2022, 4:28 PMNaN shouldBe NaN
passes because boxed equals has slightly different behaviorBen Woodworth
11/02/2022, 4:30 PMDavio
11/02/2022, 6:00 PM