In my program big numbers is shown off and for this reason I want any number to be converted to power of 10 (E-notation). I tried an idea that came to my mind but I get an error that says:
JavaScript
x
2
1
OverflowError: cannot convert float infinity to integer
2
How I succeed that I want?
Advertisement
Answer
In Python float
s are usually double-precision IEEE-754 floating point numbers; it has 11 exponent bits, which in practice means that it can represent a number ~2^1024 at maximum. If you’ve got a result greater than that: Python will convert it to IEEE 754 infinity instead:
JavaScript
1
5
1
>>> 1e308
2
1e+308
3
>>> 1e309
4
inf
5
Thus a number this big is not representable as a float
.
A number greater than this is still representable in Python as a decimal or as an integer/long.