Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Python sys.float_info.min value
#1
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).
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Quote
#2
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.
perfringo likes this post
Quote
#3
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
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Quote
#4
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'
>>> 
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)