on Python 3.6.2, Win10-x64
Just something curious that I encountered and couldn't quite explain.
In:
x = 10.0
for i in range(10):
print(str(i) + " | " + str(x))
x *= x
Out:
0 | 10.0
1 | 100.0
2 | 10000.0
3 | 100000000.0
4 | 1e+16
5 | 1e+32
6 | 1.0000000000000002e+64
7 | 1.0000000000000003e+128
8 | 1.0000000000000005e+256
9 | inf
How come it just turns into inf? Why doesn't it throw an exception?
If I replace the *= in the last line with **= for example, then by the second iteration it raises OverflowError: (34, 'Result too large'), which makes sense (since it is a mere 10.000.000.000^10.000.000.000).
Does this mean that there is a kind of "soft" limit on floats that -- when exceeded -- turns them into inf? And if so, what is that limit and is it the same regardless of the arithmetic operation? And wouldn't that imply something like inf == this_limit + anything?
.
ADD:
I get that there is the sys.float_info.max. Is that the limit?
I just got an idea and tested some stuff out:
print(sys.float_info.max)
print(sys.float_info.max + 1)
print(sys.float_info.max * 2)
print(sys.float_info.max * 1.000000000000001)
print(sys.float_info.max * 1.0000000000000001)
This gives me:
1.7976931348623157e+308
1.7976931348623157e+308
inf
inf
1.7976931348623157e+308
This is strange to me...