math.exp

Shared

Returns e raised to the power of a number


Syntax

local result = math.exp(
    exponent
)

Parameters

TypeNameDescription
numberexponentPower to raise e to

Returns

TypeNameDescription
numberresulte raised to the given exponent (approximately 2.71828^exponent)

Examples

e to the power of 1
local result = math.exp(1)

engine.print("info", result) -- 2.718281828459
e to the power of 0
local result = math.exp(0)

engine.print("info", result) -- 1.0
e to the power of 2
local result = math.exp(2)

engine.print("info", result) -- 7.3890560989307
e to a negative power
local result = math.exp(-1)

engine.print("info", result) -- 0.36787944117144
Exponential decay formula
local initial = 100
local rate = 0.05
local time = 10
local remaining = initial * math.exp(-rate * time)

engine.print("info", remaining) -- 60.653065971263
Verify exp and log are inverses
local value = 3.5
local result = math.exp(math.log(value))

engine.print("info", result) -- 3.5

On this page