我正在将我的项目从 Python 2.6 向后移植到 Python 2.4 和 2.5。在我的项目中,我使用了 float("inf")
,现在我发现它在 Python 2.5 上不可用。它有反向移植吗?
最佳答案
无论是长路拼写还是短路拼写对我来说都很好:
$ python2.4 -c "print float('inf')+200"
inf
$ python2.5 -c "print float('inf')+200"
inf
$ python2.5 -c "print float('infinity')+200"
inf
$ python2.4 -c "print float('infinity')+200"
inf
-c
标志表示“将以下参数作为 Python 命令执行”。PEP754(被拒绝)确实提到了您关于特殊 IEEE-754 值的问题。它建议使用类似
1e300000
的东西来生成浮点溢出并创建 inf
,但它确实注意到这很丑陋并且不能保证是可移植的。关于python - 将 float ("inf") 反向移植到 Python 2.4 和 2.5,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1548279/