I'm facing an issue with the exponential function in postgresql. If I use this select statement select exp(5999)
, I'm getting:
ERROR: value out of range: overflow
SQL state: 22003
If I use this select statement select exp(5999.1)
, I'm getting the exponential result.
In other case if I use this statement select exp(9999.1)
, I'm getting the following error:
ERROR: argument for function "exp" too big
SQL state: 22003
Please let me know why this issue happening and what is the solution for this kind of issue?
I think your first problem is caused by the fact that the output type of
exp()
is the same as the input type. Because you're using an integral value, it's complaining that the result won't fit in an integer.That's likely why
exp(5999.1)
, and probablyexp(5999.0)
works, the floating point type has a larger range.Your second error is slightly different, it's complaining not of overflow during the calculation, but of the fact the input argument is too large. It's possible that it has some sanity checking on the input somewhere.
Even floating point values run out of range eventually. e9999 is somewhere around 104300, a rather large number and probably well beyond what you'd expect to see in a database application.
In fact, I'd be interested in the use case of such large numbers in a database application. This sounds like something better suited to a bignum package like MPIR.