Hi, I was unit testing some code using graphics::Point when I can across this interesting test failure:
sys::TestErr: Test failed:
Equal but different hash codes: 0 0 (0x8000000000000000) ?= 0 0 (0x0)
The 2 x Point instances being compared have the same values (as indicated) but the hash codes were different.
Digging deeper, I was introduced to the concept of negative zero in floating point numbers; an artefact from the IEEE 754 standard.
And because -0.0 is different to 0.0 they generate different hash codes, which is then being fed back into the graphics geometry classes, such as Point.
As mathematically pure-0.0 may be, I'm not sure how useful it is when it comes to general purpose object equality?
I was just wondering what thoughts, perspectives, or experience others may have on this; should geometric objects such as Size or Point distinguish between 0.0 and -0.0?
SlimerDude Mon 13 Jan
Hi, I was unit testing some code using
graphics::Point
when I can across this interesting test failure:The 2 x
Point
instances being compared have the same values (as indicated) but the hash codes were different.Digging deeper, I was introduced to the concept of negative zero in floating point numbers; an artefact from the IEEE 754 standard.
And because
-0.0
is different to0.0
they generate different hash codes, which is then being fed back into thegraphics
geometry classes, such asPoint
.As mathematically pure
-0.0
may be, I'm not sure how useful it is when it comes to general purpose object equality?I was just wondering what thoughts, perspectives, or experience others may have on this; should geometric objects such as
Size
orPoint
distinguish between0.0
and-0.0
?