gpt4 book ai didi

python - float 的精度

转载 作者:太空宇宙 更新时间:2023-11-04 10:03:59 26 4
gpt4 key购买 nike

Python 中 float 的精度是多少?它总是 double 还是特定于实现或平台?它在 CPython 和 PyPy 中有什么不同吗?

最佳答案

来自 Python 文档:

Floating point numbers are usually implemented using double in C; information about the precision and internal representation of floating point numbers for the machine on which your program is running is available in sys.float_info.

sys.float_info是一个结构序列,包含有关浮点类型的信息。它包含有关精度和内部表示的低级信息。

import sys

print(sys.float_info.mant_dig)

mant_dig 属性指向 float 精度: float 尾数中基数的位数

Almost all platforms map Python floats to IEEE 754 double precision.

关于python - float 的精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41975576/

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