Lua exp()
In Lua, the math.exp() function is a standard function that is used to calculate the exponential value of a number, i.e, the exponential constant ‘e’ (which is roughly equal to 2.718281828459045) raised to a given value.
Exponents are a very common part of mathematical operations across a wide variety of fields and disciplines such as physics, engineering, probability and statistics, and even machine learning! This means that the math.exp() function is a very useful and widely applicable tool for Lua developers.
As a side-note, the math.log() function in the math library returns the inverse of the math.exp() function.
Syntax
As exp() is a method that is a part of the standard Lua math library, to use this function it must be called as math.exp().
math.exp(mycoolvalue) -- Returns the result of e raised to the power of mycoolvalue
Example 1
To find the exponential value of 0,
print(math.exp(0))
This results in the following output:
1.0
Example 2
Similarly, to find the exponential value of 8,
print(math.exp(8))
This results in the following output:
2980.9579870417
As math.log() is the inverse of math.exp(),
print(math.log(2980.9579870417))
This results in the following output:
8.0
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Lua on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.
- Beginner Friendly.4 hours