0

The numpy remainder function is returning results I don't understand when given floating point numbers. I am not sure if this is a bug or a failure on my part to understand the documentation. For example

np.remainder(0.5, 0.001)
Out[165]: 0.00099999999999998961

np.remainder(0.499, 0.001)
Out[161]: 0.00099999999999998875

which should both be zero given my understanding of the function. The documentation says the function is equivalent to x1 - floor(x1 / x2) * x2, but checking this gives the answer I expect:

0.5 - np.floor(0.5/0.001)*0.001
Out[166]: 0.0

Also,

np.remainder(0.499*1000, 0.001*1000)
Out[160]: 0.0

Insight into why this might be the case given floating point arithmetic would be greatly appreciated.

MathBio
  • 367
  • 1
  • 2
  • 13
  • Not sure how numpy handles floating points, but maybe you can gain more understanding of the floating vs decimal representation by reading: http://floating-point-gui.de/basic/ – Ivan Bilan Feb 20 '16 at 21:48
  • It seems like this is a known issue: https://github.com/numpy/numpy/issues/7224 – user2966694 Feb 20 '16 at 21:54

0 Answers0