Lua .log()

abereFejiro9953409650's avatar
Published Nov 13, 2023
Contribute to Docs

The .log() function in Lua’s math library calculates the natural logarithmic value of a given number. The natural logarithm is to the base e, where e is Euler’s number, an irrational constant approximately equal to 2.71828.

  • 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

Syntax

math.log(number)
  • number: The number for which the natural logarithm is calculated.

Example

In this example, math.log() calculates the natural logarithmic value of 20:

local num = 20
local result = math.log(num)
local output = string.format("The natural Logarithm of %.0f: %.4f", num, result)
print(output)

The above example will result in the following output:

The natural Logarithm of 20: 2.9957

All contributors

Contribute to 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