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

조회 수: 2 (최근 30일)
Gustavo Lunardon
Gustavo Lunardon 2021년 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
Image Analyst
Image Analyst 2021년 10월 15일
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 2021년 10월 15일
Exactly and well said. I should have included a statement to that effect in my comment

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 10월 15일

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by