0.9-0.89 is 0.01000000​0000000000​2081668171​17217

1 Ansicht (letzte 30 Tage)
john
john am 15 Aug. 2013
Hi, why
0.9-0.89 is 0.010000000000000000208166817117217?
I want to use it in:
if a-b<c sprintf('error') end......
when I use vpa, than I get error in if..
thank you

Akzeptierte Antwort

Image Analyst
Image Analyst am 15 Aug. 2013
  2 Kommentare
James Tursa
James Tursa am 15 Aug. 2013
@John, For your particular example:
>> num2strexact(0.9)
ans =
0.90000000000000002220446049250313080847263336181640625
>> num2strexact(0.89)
ans =
0.89000000000000001332267629550187848508358001708984375
>> num2strexact(0.9-0.89)
ans =
1.00000000000000088817841970012523233890533447265625e-2
As you can see above, none of the numbers involved can be represented exactly in IEEE double precision floating point. You can find NUM2STREXACT here:
john
john am 15 Aug. 2013
OK , thank you

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by