Re:There Are Only Four Billion Floats, So Test Them All (2014)
by conistonwater on Thursday September 14, 2017 @07:02PM
(#15253187)
I don't like testing for NaN's using == and != either, but the only values that compare the same while having a different bit patterns are ±0 and all the NaN's, so as long as you get those right, the plain equality is fine. Also, I think your test has a corner case with 0x7ff8000000000000 and 0xfff8000000000000, because NaN's can have sign bits too, while the intention in the post is to treat any NaN as matching any NaN. So the test for equality could be something like "isnan(a) == isnan(b) && (isnan(a) || (a == b && signbit(a) == signbit(b)))" without any bitwise manipulation.
[ Parent
| on HN ]
There are no comments on this comment yet.