views:

79

answers:

4

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

1-math.exp(-4*1000000*-0.0641515994108)
+1  A: 

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.

Glenn Maynard
+1  A: 

This may give you a clue why:

http://www.wolframalpha.com/input/?i=math.exp%28-4*1000000*-0.0641515994108%29

Notice the 111442 exponent.

Alin Purcaru
+2  A: 

It's taking forever to calculate the math.exp of your expression in linux calc - actually around 3 minutes on my PC. The output didn't fit on screen, but here's the last part of it:

726010648480305493300522352836922089000185648300194009610305493006135730490386584903260037098857167005998834853353849878257551705055200815156678800063649767281196946006597464164408022826249192982979471655619747905493062253840990336999370303244230577613821648743839927863042905208596188092081464806377115751732875357745315291044273551778030532958448876945823382009068300296989661016734060397273448898955374347664311061172638570784565172799866765349003412688322131606252336319258232181478631097072395214997803765632768319180742163082159605289068316174359384254098097941517931574597518348211636396784347296494773409042119486708173230021139983563898694245481259688612002595939606220621873888556890064305540364372659871984724727216392448932894693397621489532333066118603627477828722037386140637745276497614541869221866894910987002535261016242004851751522615794874023339715208078186840990372953245115578124908001300437866752032892556456645511926470907016296096769614475814017170522470444349012782298548600625629235963800902717920615588515058315726.41339872515460701437

Question: how on earth did you come up with that kind of an expression? ;)

kovshenin
P.S. I can post the whole output if you're interested ;)
kovshenin
A: 

I think the value gets too large to fit into a double in python which is why you get the OverflowError. The largest value I can compute the exp of on my machine in Python is just sligthly larger than 709.78271.

MAK