python - 如何在python中输入浮点无穷大文字

标签 python floating-point portability numerical

如何在 python 中输入浮点无穷大字面量?

听说过

 inf = float('inf')

是不可移植的。因此,我有以下建议:

 inf = 1e400

这些是标准的还是可移植的?最佳做法是什么?

最佳答案

python 2.6如果 CPU 支持,它是可移植的

The float() function will now turn the string nan into an IEEE 754 Not A Number value, and +inf and -inf into positive or negative infinity. This works on any platform with IEEE 754 semantics.

关于python - 如何在python中输入浮点无穷大文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2919754/

相关文章:

python - 在二维和一维数组之间按元素使用 numpy isin

python - 使用可变数量的 WHERE 子句来匹配任意数量的关键字 pysqlite

python - Python如何管理int和long?

c - 为什么这个浮点循环在 1,000,000 处终止?

ruby-on-rails - Ruby BigDecimal 健全性检查( float newb)

python - 如何获取自己的文件名

floating-point - 将 powerpc 移植到 intel 的数字代码使用 float 给出了不同的结果

python - Python 中的可移植性大列表

c - 在**可移植 C** 中,如何启动将命令的标准输入连接到启动程序的标准输出的命令?

python - 如何用正则表达式可移植地解析(Unicode)度数符号?