0

I'm surprised to see the result returned by Python interpreter (3.9.10).

In [5]: -0.0401 + 0.0032
Out[5]: -0.036899999999999995

Shouldn't the same math operation return −0.0369?

Florent
  • 1,791
  • 22
  • 40
  • this is the closest float representation of `-0.0369` – user_na Oct 23 '22 at 09:47
  • @user_na - Probably not (if it were, Python likely wouldn't output all those digits), but it's the closest representation of the result of adding the closest representation of -0.0401 and the closest representation of 0.0032. :-) Just like if you print 0.3, you get 0.3 (despite it not being precisely representable), but if you print 0.1 + 0.2, you get 0.30000000000000004. – T.J. Crowder Oct 23 '22 at 09:50
  • 1
    @T.J.Crowder yes you are right, thanks for clarification! Thats what I meant, but the way I wrote it was to sloppy to understand what is actually the point. – user_na Oct 23 '22 at 09:52

0 Answers0