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.
Re:There Are Only Four Billion Floats, So Test Them All (2014)
by brucedawson on Thursday September 14, 2017 @07:11PM
(#15253244)
I wouldn't want to write the test that way because it seems very complex. The other way I'd be tempted to write it would be to compare the bit patterns and treat mismatched bit patterns as a failure unless both numbers are NaN.
To some extent it comes down to personal taste and how much knowledge of FP you want embedded in the test.
I doubt it's that I know more than Bruce Dawson about FP; is it about working in the distant past (2014, cough) without compiler support for C99 stuff like fpclassify and signbit?