Floating point overflow and underflow
Shashank Tiwari
shanky.tiwari at gmail.com
Tue Jan 7 18:47:37 EST 2020
In Python3 an operation as follows:
>>> 10135.1941 * (10**8)
gives the result: 1013519410000.0001
Similarly, using the pow function also gives the same overflow/underflow
error.
>>> 10135.1941 * pow(10,8)
1013519410000.0001
Like multiplication, division of large or very small floating point numbers
gives similar overflow/underflow errors.
Usage of Decimal doesn't seem to fix it either.
>>> from decimal import *
>>> Decimal(10135.1941 * pow(10,8))
Decimal('1013519410000.0001220703125')
>>> Decimal(10135.1941)*pow(10,8)
Decimal('1013519410000.000061700120568')
>>> Decimal(10135.1941) * Decimal(pow(10,8))
Decimal('1013519410000.000061700120568')
>>> Decimal(10135.1941 * (10**8))
Decimal('1013519410000.0001220703125')
How could one do high precision multiplication and division of floating
points numbers (decimals) in Python3 without any overflow/underflow errors?
Thanks, Shanky
More information about the Python-list
mailing list