我正在尝试创建负责查找比给定tempMaxAngle小90的数字的除数的函数。例如,我的函数应该返回6为tempMaxAngle = 7或30为tempMaxAngle = 31或22.5为tempMaxAngle = 23,等等。不幸的是它没有正常工作 - 我得到奇怪的值。这是我的algorythm:
function maxAngle = angletest(tempMaxAngle)
format long g;
tempMaxAngle = tempMaxAngle*10;
tempMaxAngle = floor(tempMaxAngle)/10;
while mod(90,tempMaxAngle)>0
modResult =mod(90,tempMaxAngle)
tempMaxAngle = tempMaxAngle - 0.1
end
maxAngle=tempMaxAngle;
end
tempMaxAngle = 7的部分结果(部分结果):
tempMaxAngle =
6.9
modResult =
0.299999999999995
tempMaxAngle =
6.8
modResult =
1.59999999999999
tempMaxAngle =
6.7
modResult =
2.89999999999998
tempMaxAngle =
6.6
modResult =
4.19999999999998
tempMaxAngle =
6.5
modResult =
5.49999999999998
tempMaxAngle =
6.4
modResult =
0.399999999999966
tempMaxAngle =
6.3
modResult =
1.79999999999996
tempMaxAngle =
6.2
modResult =
3.19999999999997
tempMaxAngle =
6.1
modResult =
4.59999999999996
tempMaxAngle =
6
modResult =
5.99999999999995
tempMaxAngle =
5.9
modResult =
1.49999999999994
tempMaxAngle =
5.8
modResult =
2.99999999999993
tempMaxAngle =
5.7
modResult =
4.49999999999993
tempMaxAngle =
5.60000000000001
modResult =
0.399999999999929
为什么它一直在修复那种值而不是简单的6.9,6.8,6.7等,以及类似的模数函数?我该如何解决?