3 ms·
> For very small numbers (less than about FLT_EPSILON * 0.25) adding 0.5 gives 0.5 exactly, and this then rounds to zero Is that not correct? Isn't it expected
by bhaney 4y ago
> For very small numbers (less than about FLT_EPSILON * 0.25) adding 0.5 gives 0.5 exactly, and this then rounds to zero
Is that not correct? Isn't it expected that very small numbers round to zero?
- zerocrates 4y agoThis 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.
- teraflop 4y agoThe 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.
- bhaney 4y ago> supposed to find the ceiling Oh duh. I somehow forgot that over the span of a few sentences. Thanks.