MATLAB Answers

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

3 次查看(过去 30 天)
Gustavo Lunardon
Gustavo Lunardon2021-10-15
评论: Paul ,2021-10-15
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

采纳的回答

Star Strider
Star Strider 2021-10-15
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 个评论
Paul
Paul 2021-10-15
Exactly and well said. I should have included a statement to that effect in my comment

请先登录,再进行评论。

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by