Bug in equality checks? 28.15e-3 == 28.15/1000 false

1 visualización (últimos 30 días)
Gustavo Lunardon
Gustavo Lunardon el 15 de Oct. de 2021
Comentada: Paul el 15 de Oct. de 2021
Why does this happen? It does not regocnize equality on 7.48e-3 == 7.48/1000, but it does on 7.47e-3 == 7.47/1000 as well. Another example below.
28.1e-3 == 28.1/1000
ans = logical
1
28.15e-3 == 28.15/1000
ans = logical
0

Respuesta aceptada

Star Strider
Star Strider el 15 de Oct. de 2021
Wellcome to the world of floating-point approximation error!
This is roughly equivalent to expressing in decimals. The result is 0.3 an infinite number of 3 following it, never being excactly equal to .
.
  9 comentarios
Image Analyst
Image Analyst el 15 de Oct. de 2021
I think the abs() is needed because one quantized expression could be above or below the other quantized expression, and I don't think you'd know which it will be in general.
Paul
Paul el 15 de Oct. de 2021
Exactly and well said. I should have included a statement to that effect in my comment

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 15 de Oct. de 2021

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by