-
-
Notifications
You must be signed in to change notification settings - Fork 32k
The floating-point information provided by sys.float_info
is mostly incorrect.
#93488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
min_10_exp
in sys.float_info
sys.float_info
is mostly incorrect.
Thanks for the report. Assuming that you're on a system that uses IEEE 754 binary64 floating-point (which is in practice a very safe assumption), the
Please could you elaborate? What other values do you consider incorrect? |
Updated the issue. |
The significand is 53 bits, 52 of which are actually stored in the significand field. There is a leading bit that is implicit. (See, for example, Section 3.4 of IEEE-754.) |
@oda-gitso Ah thanks; I missed that bit of the original report. Indeed |
I wasn't aware that it takes into consideration the sign bit. But in any case, the other values that I have mentioned are completely wrong. You can reproduce the error by running the examples that I provided above. |
|
They're correct. Again, as documented, those constants refer to normal values. The result of |
Any absolute value smaller than
That's Here's the smallest normal float value from hex format:
|
Now I get it. I didn't know about the subnormal numbers. Thanks for the explanation, @mdickinson & @eryksun. |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Running
sys.float_info
shows that the smallest number a float can store ismin_10_exp=-307
. However, by trial and error, it turns out that the true minimum value is10.0 ** -323
Therefore,
min_10_exp=-307
should be corrected tomin_10_exp=-323
.The same apply for
min
, it should be:The max value is correct:
It turns out that a lot of information provided by this attribute(
float_info
) is not correct, the correct ones are:Following the 64bits version of IEEE 754 standard, the sign is coded on 1 bit, the exponent on 11 bit, and 52-bit for the mantissa, 11 + 1 + 52 = 64 bits; the precision being 52 bits, thus 15 significant digits. This means that
dig=15
is correct andmant_dig=52
instead ofmant_dig=53
.Your environment
The text was updated successfully, but these errors were encountered: