gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:07:54 31 4
gpt4 key购买 nike

我正在尝试确定 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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com