0

I had a serious error propagation in my computations (Mathematica 10.4.1 Windows 64 bit). After some investigation, I realized the problem comes from something like this: FullForm[1. - (0.3 + 0.4)] gives 0.30000000000000004`.

Is it a bug? How to fix it?

  • 3
    No, it is not a bug. It's called floating point numbers. A number like 0.3 cannot be represented exactly by a binary floating point number. For example, displaying the machine precision number 0.3 as floating point number with higher precision with FullForm[SetPrecision[0.3, 20]] will return 0.29999999999999998889776975374843459576`20.. – Henrik Schumacher Aug 07 '18 at 09:50
  • This one is similar and the answer fits here well: What is special about 70.329862, this is closely related too: 104032 – Kuba Aug 07 '18 at 09:53
  • One fix is to use rational numberts: 1-(3/10+4/10) – bill s Aug 07 '18 at 12:29
  • 2
    I'm voting to close this question as off-topic because this is about machine precision representation of base 10 values in binary, not specific to Mathematica – Daniel Lichtblau Aug 07 '18 at 13:19
  • @DanielLichtblau so are many similar questions, e.g. both I linked above. Do you agree with closing it as a duplicate instead or have I missed the point here? – Kuba Aug 07 '18 at 14:21
  • I'm fine with calling it a duplicate. In most cases, as best I recall, the poster is unaware of the FullForm and does not realize there are nonzero decimal digits involved. – Daniel Lichtblau Aug 07 '18 at 18:47

0 Answers0