Python 我们能说math.floor(x)==int(x)是相似的吗?
当我想将浮点值转换为整数值时,我可以选择math.floor或将其转换为int,这两个结果是相同的 性能::int似乎快了30% 反汇编程序:我不打算粘贴结果,因为它们对于上述性能测试中的floorTest和intTest都是相同的 现在的问题是: 我们可以说math.floor与将浮点值转换为int具有相同的效果吗 我这样问的原因是,我可能在监督一些要点。否,int和math.floor有不同的行为:Python 我们能说math.floor(x)==int(x)是相似的吗?,python,Python,当我想将浮点值转换为整数值时,我可以选择math.floor或将其转换为int,这两个结果是相同的 性能::int似乎快了30% 反汇编程序:我不打算粘贴结果,因为它们对于上述性能测试中的floorTest和intTest都是相同的 现在的问题是: 我们可以说math.floor与将浮点值转换为int具有相同的效果吗 我这样问的原因是,我可能在监督一些要点。否,int和math.floor有不同的行为: >>> import math >>> f = 1.23
>>> import math
>>> f = 1.23456
>>> int(f)
1
>>> int(-f)
-1
>>> math.floor(f)
1
>>> math.floor(-f)
-2
否,int和math.floor具有不同的行为:
>>> import math
>>> f = 1.23456
>>> int(f)
1
>>> int(-f)
-1
>>> math.floor(f)
1
>>> math.floor(-f)
-2