0

I'm using the Table command to generate a list of values:

FullForm /@ Table[10. - x, {x, 2.7, 2.8, .1}]

and I get the following result:

{7.3`,7.199999999999999`}

Why do I get 7.199999999999999' instead of 7.2?

Moreover, if I try to calculate the Complement of {7.2} in this list, I get {7.2,7.3}, which is not what I would expect. At the same time, using the Complement option SameTest->(#1==#2&) gets me {7.3}.

This behavior is observed in Mathematica 7/8/9, and even on WolframAlpha.

P.S. I know that using Range[7.3,7.2,-0.1] would be clearer, I'm just curious about the aforementioned problem.

Ivan
  • 1
  • 2
  • Closely related questions: http://mathematica.stackexchange.com/q/4818/3066
    http://mathematica.stackexchange.com/q/5580/3066
    – m_goldberg May 19 '14 at 14:05
  • It appears that the problem is not with Table but rather with substraction. The question is why 10.-(2.7+0.1)//FullForm and 10.-2.8//FullForm produce different results. – Ivan May 19 '14 at 14:18
  • The numbers in question are not exactly representable in base 2, which is the form used for machine arithmetic. So there will be discrepancies from round-off when one does arithmetic operations. The example in question: `InputForm[2.7+.1]

    Out[8]//InputForm= 2.8000000000000003 `

    – Daniel Lichtblau May 19 '14 at 14:37
  • Ok, I think this is it. Thanks! – Ivan May 19 '14 at 14:53

1 Answers1

0

Why should it have anything to do with 'Table' ? Try 10. - (2.7 + 0.1) // FullForm it shows the same result, since you 'denude' the floating point residuals by 'Fullform'

Wouter
  • 1,343
  • 7
  • 11
  • Ok, thanks for the example, it seems that Table is good, but now I don't understand why 10.-(2.7+0.1)//FullForm and 10.-2.8//FullForm produce different results. – Ivan May 19 '14 at 14:13
  • Check the Help file for floating point arithmetic, and, on passing, check the concepts Accuracy and Precission. – Wouter May 19 '14 at 15:00