Re:There Are Only Four Billion Floats–So Test Them All (2014)
by zerocrates on Thursday February 09, 2023 @04:49PM
(#34732037)
This is in the context of the implementation of a ciel() function: a very small but still positive float should have a ciel() of 1. As said near this part, IEEE default rounding is round half to nearest even: 0.5 rounds to 0, the closest even integer, so if your addition of 0.5 to the argument to ciel() results in exactly 0.5, the result will incorrectly be 0 instead of 1.
Re:There Are Only Four Billion Floats–So Test Them All (2014)
by teraflop on Thursday February 09, 2023 @04:51PM
(#34732061)
The quote is talking about code that is supposed to find the ceiling of a number, and does so by adding 0.5 and then rounding to the nearest value (breaking ties by rounding towards even).
If you have a very small but non-zero positive number, it gets rounded to 0.5 after the addition, and then the second rounding incorrectly rounds toward 0 instead of 1.
The result is that you have a value x such that x > ceil(x), which shouldn't ever happen.
Is that not correct? Isn't it expected that very small numbers round to zero?