Python math.floor()和//产生不同的结果

Python math.floor()和//产生不同的结果,python,python-3.x,math,Python,Python 3.x,Math,在Python3.4中,我希望操作math.floor和//产生相同的结果。他们没有 import math n=20844627638611523 print (math.floor(n/2)) print (n//2) 印刷品: 10422313819305762 10422313819305761 为什么?问题出在表达式n/2中。这将返回一个浮点值1.0422313819305762e+16-您在最后一个数字中丢失了一点精度。丢失后,后续的floor操作将返回意外结果。这与math.

在Python3.4中,我希望操作math.floor和//产生相同的结果。他们没有

import math

n=20844627638611523
print (math.floor(n/2))
print (n//2)
印刷品:

10422313819305762
10422313819305761

为什么?

问题出在表达式n/2中。这将返回一个浮点值1.0422313819305762e+16-您在最后一个数字中丢失了一点精度。丢失后,后续的floor操作将返回意外结果。

这与math.floor代替int基本相同。