It turns out such an error when calculating the exponent if the input is given a value of 710 and higher. How can one calculate the exponent in this case, even with an error?

 >>> math.exp(710) Traceback (most recent call last): File "<input>", line 1, in <module> OverflowError: math range error 
  • And what does Google say? sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1) - Igor Lavrynenko
  • Sorry, this line is incomprehensible to me. Is it possible to get around this limitation? - Mavar
  • You can, neglecting accuracy - Igor Lavrynenko
  • Thank. How to do it, what will this function look like? math.exp(710) - Mavar
  • one
    Possible duplicate question: OverflowError: math range error - Igor Lavrynenko

1 answer 1

It is necessary to use a wider float type. For example, you can use the numpy package types.

 import numpy as np val = 711 print(np.exp(val, dtype=np.float128)) 
  • Thanks for the advice. Is it possible to do this without third-party libraries? - Mavar
  • one
    @Mavar, if only to write the function of calculating the exponent. - mkkik