3

I get an Overflow error when i try this calculation,

output=math.exp(1391.12694245)*100

i know this happens because that the number used is 'outside the range of a double'. but is there any way for solving this and getting the value of output. Can someone please help?

DYZ
  • 55,249
  • 10
  • 64
  • 93
  • its infinity value ryt.. – Edison Augusthy Mar 01 '17 at 06:31
  • http://stackoverflow.com/a/16905023/478656 - use `from decimal import Decimal; Decimal(1391.12694245).exp()*100` – TessellatingHeckler Mar 01 '17 at 07:15
  • Can you give more information about the problem you're trying to solve? The normal `float` range is more than enough for most real-world tasks, and using extended precision is usually the wrong solution - it may be that you simply need to reformulate your calculation to avoid the overflow. – Mark Dickinson Mar 01 '17 at 11:53

1 Answers1

1

Use extra precision floating point numbers from numpy:

import numpy as np
np.exp(np.array([1391.12694245],dtype=np.float128))*100
# array([ 1.4413011e+606], dtype=float128)
DYZ
  • 55,249
  • 10
  • 64
  • 93
  • 2
    This is platform specific: `float128` isn't available on all platforms (and usually isn't a 128-bit floating-point type even when it *is* present). – Mark Dickinson Mar 01 '17 at 08:37