MATLAB: “-pi/8 <= 0.0099 < pi/8" return logical 0

comparisonnot a bug

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

Best Answer

>> -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
>>