Python Forum
Python sys.float_info.min value - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html)
+--- Forum: Bar (https://python-forum.io/forum-27.html)
+--- Thread: Python sys.float_info.min value (/thread-25187.html)



Python sys.float_info.min value - perfringo - Mar-23-2020

There is sys.float_info in Python:

>>> 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)
>>> sys.float_info.min
2.2250738585072014e-308
Python seems to recognise this value to be larger than zero:

>>> 0 < sys.float_info.min
True
However, if I add this greater than zero value to integer it's not making value greater:

>>> 1 < (1 + sys.float_info.min)
False
>>> 1 == (1 + sys.float_info.min)
True
Any explanation why is that (some precision and/or normalised thingy)?

Technical stuff aside, this is somehow contra-intuitive (being larger than zero but not impacting value comparison).


RE: Python sys.float_info.min value - Gribouillis - Mar-23-2020

Suppose that instead of binary format, the computer stored the numbers in decimal format in exponential notation with 7 significant digits, this is how it would look
>>> "{:e}".format(1.e-8)
'1.000000e-08'
>>> "{:e}".format(1)
'1.000000e+00'
>>> "{:e}".format(1+1.e-8)
'1.000000e+00'
You would see a positive number for 1e-8 but you wouldn't see the difference between 1 and 1+1e-8 because the difference is beyond the last significant digit.

In real life, the same phenomenon occurs with binary numbers in memory in the IEEE 754 format, which is just a kind of exponential notation for binary numbers.


RE: Python sys.float_info.min value - perfringo - Mar-27-2020

Python recognises change in value up to 1.e-15 (or at least it does on my machine):

>>> 1 + 1.e-15 == 1    # values are not even                                                            
False
>>> 1 + 1.e-16 == 1    # now values are even for Python                                                             
True



RE: Python sys.float_info.min value - Gribouillis - Mar-27-2020

If you download my anyfloat module, you can visualize the internal binary representation of the floating numbers
>>> from anyfloat import anyfloat
>>> a = anyfloat.from_float(1 + 1e-15)
>>> a.bin()
'0 01111111111 0000000000000000000000000000000000000000000000000101'
>>> a = anyfloat.from_float(1)
>>> a.bin()
'0 01111111111 0000000000000000000000000000000000000000000000000000'
>>> a = anyfloat.from_float(1 + 1e-16)
>>> a.bin()
'0 01111111111 0000000000000000000000000000000000000000000000000000'
>>> a = anyfloat.from_float(1 + 1e-13)
>>> a.bin()
'0 01111111111 0000000000000000000000000000000000000000000111000010'
>>>