python中可以表示的最小数字是多少?

pop*_*eds 5 python floating-point

python中可以表示的最小数字是多少?

我见过小2.05623357236e-296但可以有更小的吗?

Bha*_*Rao 8

查看 sys.float_info

>>> import sys
>>> 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)
Run Code Online (Sandbox Code Playgroud)

来自文档

min       DBL_MIN      minimum positive normalized float 
min_exp   DBL_MIN_EXP  minimum integer e such that radix**(e-1) is a normalized float
Run Code Online (Sandbox Code Playgroud)

在我的系统上,它被称为 min=2.2250738585072014e-308


nne*_*neo 5

检查sys.float_info.min.请注意,这是最小标准化值; 最小非正规化值可能更小,但数值精度将受到影响.

对于通常的64位浮点数,标准化的最小值约为2.2e-308.非规范化的min可以少得多,直到4.94e-324:

>>> 5e-324
4.9406564584124654e-324
Run Code Online (Sandbox Code Playgroud)

值得指出的是,decimal模块的Decimal类型可以代表任意小的数字,仅受可用内存的限制.

  • 这是数字浮点表示的技术区别.维基百科有一个很好的纲要:https://en.m.wikipedia.org/wiki/Denormal_number (2认同)