Python's binary floating point numbers have a finite range. Python stores binary floats using at most 17 decimal digits of accuracy. In addition, the largest float you can store is 1.79769_10 308 (which Python represents as 1.79769e+308). If you try to calculate or store a larger number, you may get a result such as this:
Long integers can be larger than floats, so you might get an "overflow error" or incorrect results when using large integers with binary floats or with the float() function (which converts numbers to binary floats). The following code attempts to convert 10 1,000 to a float. Because the resulting number is too big for Python and the computer to handle, it raises an error:
Traceback (most recent call last): File "<stdin>", line 1, in <module>
OverflowError: long int too large to convert to float
The following code also gives an incorrect result because of the 17-digit size limit on floats. (A number doesn't equal itself plus 1, no matter how big it is!)
Was this article helpful?