MATLAB Answers

Why "-pi/8 <= 0.0099 < pi/8" return logical 0?

2 views (last 30 days)
Yutian Lei
Yutian Lei on 1 Jun 2020
Commented: Yutian Lei on 1 Jun 2020
Hi! I'm running this simple program to approximate the angle of a line to 0, pi/4, pi/2 or 3*pi/4. But in the case shown as follows, when degree = 0.0099, it should be apprximated to 0. But I don't know why the expression "-pi/8 <= 0.0099 < pi/8" returns 0 and "pi/8 <= 0.0099 < 3*pi/8" will return 1? Is it a bug or something I don't know?
Really make me crazy... appreciate a lot if someone can help

  0 Comments

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 1 Jun 2020
>> -pi/8 <= 0.0099
ans =
logical
1
>> ans < pi/8
ans =
logical
0
>> pi/8 <= 0.0099
ans =
logical
0
>> ans < 3*pi/8
ans =
logical
1
>> (-pi/8 <= 0.0099) && (0.0099 < pi/8) % proper way to compare
ans =
logical
1
>>

More Answers (0)

Categories


Translated by