I have a function that returns log10 values. On converting them to normal numbers, I obtain an overflow error.
OverflowError: (34, ‘Numerical result out of range’)
I checked the log values and this error occurs for say, 508.038057662.
I reckon that while python easily performs 10**509, this error must be due to the decimal points overflowing the register. Therefore I tried using numpy.float64 like such,
result = np.array([ (10**multiplicity(timeseries,om,ph,bins,pos_arr)) for ph in np.linspace(0,twopi,num = bins+1)], dtype = np.float64)
The error is the same. Am I declaring the float64 wrong??
Here multiplicity() is the function that returns log10 values. I require a “list” of values.
The problem is not down to “the decimal points overflowing”, but is caused by the data type you are using.
Python can happily calculate 10**509 as a
longsince these have unlimited precision:However, this result is too big to store in a
float:We can check the maximum
floatquite easily:Looking at this question is seems that the Numpy
float64has the same range of values as a standardfloatso using that instead isn’t going to fix your problem.Instead, you’ll have to use one of the third-party modules that provide arbitrary precision floating points such as mpmath or bigfloat.