python - python float 的精度(小数点)是多少?

标签 python floating-point

我正在尝试确定 python float 与零进行比较时的精确度。请注意以下几点:

1e-323 == 0
> False
1e-324 == 0
> True

我认为阈值是 324 个小数点,至少对于我正在运行的实现(python 2.7、CPython)是这样。这在任何地方都有记录吗?它依赖于实现吗?

最佳答案

implementation-specific :

numbers.Real (float)

These represent machine-level double precision floating point numbers. You are at the mercy of the underlying machine architecture (and C or Java implementation) for the accepted range and handling of overflow. Python does not support single-precision floating point numbers; the savings in processor and memory usage that are usually the reason for using these are dwarfed by the overhead of using objects in Python, so there is no reason to complicate the language with two kinds of floating point numbers.

但是,您可以在运行时查询此信息:

>>> sys.float_info
sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)

关于python - python float 的精度(小数点)是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52064050/

相关文章:

python - 如何在 google appengine 上构建 python 代理服务器

javascript - 用适当的替换覆盖 toFixed() 以修复浮点错误 javascript

floating-point - 如何将 vhdl 定点库包含到 ghdl-0.33?

python - 使用 xpath 获取表中的最大值

python - 在Django home中添加动态生成的matplotlib图片

c - 避免 float 的不准确性

c - 读取 float

python - 使用 "x *= -1."优于 "x *= -1"的优势?

python - 装饰器导致所有函数返回 True

python - 提取两个标记之间的所有子字符串