python - 检查 python int 是否太大而无法转换为 float

标签 python floating-point integer

有什么方法可以检查长整数是否太大而无法在 python 中转换为 float ?

最佳答案

>>> import sys
>>> sys.float_info.max
1.7976931348623157e+308

实际上,如果您尝试将太大的整数转换为 float ,则会引发异常。

>>> float(2 * 10**308)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C double

关于python - 检查 python int 是否太大而无法转换为 float,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3220074/

相关文章:

c++ - 一个 double 是否将方程中的每个 int 都提升为 double?

Python:在 while 循环中返回多个值的优雅方式

Python 返回#DIV/0!来自 Google 表格而不是公式结果

c++ - double 类型的舍入问题

C++ 浮点加法(从头开始): Negative results cannot be computed

c - 为什么 C 编译器在为有符号类型分配过高的整数值时不发出警告?

python - 在python中将整数列表转换为范围

c++ - C++ 中的 FOR(限制循环!)

python - 从可变字符串中提取数字

python - 使用 Plotnine 按排序顺序绘图