math.exp(x)
The math.exp()
function in lua returns the value of ( e^x ) (where ( e ) is the base of natural logarithms).
Syntax
math.exp(x)
Parameters
x
A number.
Return value
A nonnegative number representing ( e^x ), where ( e ) is the base of the natural logarithm.
Description
Because math.exp()
is a static function, it is always used as math.exp()
, rather than as a method of a lua object. This function is useful for calculations involving exponential growth or decay.
Beware that ( e ) raised to a number very close to 0 will be very close to 1 and may suffer from loss of precision.
Examples
Using math.exp()
print(math.exp(-math.huge)) -- 0
print(math.exp(-1)) -- 0.36787944117144233
print(math.exp(0)) -- 1
print(math.exp(1)) -- 2.718281828459045
print(math.exp(math.huge)) -- Infinity
See also
math.log()
math.pow()
math.sqrt()
math.abs()