Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: OverflowError: math range error

I get a Overflow error when i try this calculation, but i cant figure out why.

1-math.exp(-4*1000000*-0.0641515994108) 
like image 990
Harpal Avatar asked Oct 29 '10 10:10

Harpal


People also ask

How do I fix OverflowError math range error in Python?

The Python "OverflowError: math range error" occurs when the result of a mathematical calculation is too large. Use a try/except block to handle the error or use the numpy module if you have to manipulate larger numbers.

How do you get rid of the overflow error in Python?

These errors can be handled by using exception handling. In the below section we will see about this exception handling. In the above programs, we saw the Overflow error that occurred when the current value exceeds the limit value. So to handle this we have to raise overflowError exception.


1 Answers

The number you're asking math.exp to calculate has, in decimal, over 110,000 digits. That's slightly outside of the range of a double, so it causes an overflow.

like image 136
Glenn Maynard Avatar answered Sep 17 '22 14:09

Glenn Maynard