I just tried to solve the following equation with WolframAlpha and got some very weird results:

\sum_{i=1}^{x}x^2*i = 318338237039211050000

  1. WolframAlpha tells me, one of the real solutions is x = 158847.000000000;

  2. It also tells me that (of course) 158847.000000000 = 158847;

  3. WA then tells me, that the equation using x=158847.000000000 is true;

  4. But the same equation using x=158847 is false.

Shouldn't be 3) and 4) both true? Can anyone explain these results to me?


This is the nature of comparisons for floating point equality. For example, there is no fixed precision decimal representation for 1/3 such that (3 * 1/3) = 1 is true. And you can make (2/3 + 1/3) = 1 be true or (1/3 + 1/3) = 2/3 be true but not both. See What Every Computer Scientist Should Know About Floating Point.

|improve this answer|||||
  • here is a good video explaining what david is saying: youtube.com/watch?v=PZRI1IfStY0 – Keltari Feb 24 '14 at 2:18
  • I understand this for 1/3, but I don't see the difficulties in storing .0 as binary floating point – sloewen Feb 25 '14 at 1:10
  • There is nothing special about where the decimal point is. Numbers on one side of the decimal point are not different from numbers on the other side of the decimal point. – David Schwartz Feb 25 '14 at 1:18
  • But where are the rounding errors with this number. Isn't 1.00110110001111111_2×2^17 the exact floating point representation of it? And since there is this exact representation, shouldn't there be no rounding errors? – sloewen Feb 25 '14 at 9:59
  • The problem is more likely with 31833823703921105000. – David Schwartz Feb 25 '14 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.