[issue37787] Minimum denormal or ** bug
Tim Peters
report at bugs.python.org
Wed Aug 7 11:57:43 EDT 2019
Tim Peters <tim at python.org> added the comment:
Python delegates exponentiation with a Python float result to the platform C's double precision `pow()` function. So this is just what the Windows C pow(2.0, -1075.0) returns. All native floating point operations are subject various kinds of error, and this is one.
>>> import math
>>> math.pow(2.0, -1075.0)
5e-324
>>> math.pow(2.0, -1074.0) # same thing
5e-324
To avoid intermediate libm rounding errors, use ldexp instead:
>>> math.ldexp(1, -1074) # 2.0 ** -1074
5e-324
>>> math.ldexp(1, -1075) # 2.0 ** -1075
0.0
----------
nosy: +tim.peters
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37787>
_______________________________________
More information about the Python-bugs-list
mailing list