这里发生了什么?
print 'steps divided',125**(1.0/3), 5.0%1
>> steps divided 5.0 0.0
print 'steps combined',(125**(1.0/3))%1
>> steps combined 1.0
奇怪的是,这些步骤适用于其他数字....例如8:
print 'steps divided',8**(1.0/3), 2.0%1
>> steps divided 2.0 0.0
print 'steps combined',(8**(1.0/3))%1
>> steps combined 0.0
答案 0 :(得分:0)
我认为这解决了你的问题......
>>> 125**(1.0/3), 5.0%1
(4.999999999999999, 0.0)
>>> 4.999999999999%1
0.9999999999989999
125**(1.0/3)
真的是4.999...
,而不是5.0
。
因此,您正在执行4.999999999999999%1
,它会为您提供.0.9999999999989999
的输出,并将其舍入为1.