Precision/Rounding in Matlab

Perhaps I should read over the famous article, "What Every Computer Scientist Should Know About Floating-Point Arithmetic."
I'm trying to do a simple comparison of two numbers:
>> isequal(52.8/10, 5.28)
ans =
0
>> isequal(5.28,5.28)
ans =
1
Obviously, this is the "wrong" answer. 52.8/10 should be equal to 5.28. It's not.
How do you handle cases like this in matlab? How are you CERTAIN that you are checking for equality correctly?
Thanks.

Respuestas (1)

the cyclist
the cyclist el 4 de Ag. de 2011

0 votos

I suggest you look at the Accepted answer to this question, and follow the link in it. http://www.mathworks.com/matlabcentral/answers/69-why-does-1-2-3-1-3-not-equal-zero

2 comentarios

Russell
Russell el 4 de Ag. de 2011
Thank you. That answered it nicely.
the cyclist
the cyclist el 4 de Ag. de 2011
Glad to hear it. You might want to "Accept" the answer, to help future users.

Iniciar sesión para comentar.

Categorías

Preguntada:

el 4 de Ag. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by