# floating point rounding (1/x)*x

I'm trying to figure out what the smallest positive integer x such that the floating point expression round(round(1/x)*x) is not equal to 1 in single precision.

I have that the answer is 41, but when I let the number 3 for example be x, isn't 1/3 = 0.333, and when rounded = 0, 0 * 3 = 0? So why is the answer 41?

• With your interpretation, the smallest x would be 2, not 3. Apr 26 '20 at 17:48

That's probably not what was meant by "round". I suspect "round" probably meant to round to the nearest single-precision float. In particular, you can easily verify that 41 is the smallest number with this property:

>>> from numpy import *
>>> float32(float32(1.0/3.0)*3.0)
1.0
>>> float32(float32(1.0/40.0)*40.0)
1.0
>>> float32(float32(1.0/41.0)*41.0)
0.99999994


But you should double-check the definition of the function round() with whoever told you this problem. We can't read their mind.

• This will probably also depend on which rounding method your floating-point library uses. Sep 29 '15 at 6:42