我正在尝试创建负责查找小于给定 tempMaxAngle 的 90 位数的除数的函数。例如,对于 tempMaxAngle=7,我的函数应返回 6,对于 tempMaxAngle=31,应返回 30,对于 tempMaxAngle=23,应返回 22.5,等等。不幸的是,它不能正常工作——我得到了奇怪的值。这是我的算法:
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 等以及类似的模函数?我该如何解决?