2

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?

user40377
  • 21
  • 1

1 Answers1

1

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.

D.W.
  • 167,959
  • 22
  • 232
  • 500