math.log

Full name
math.log
Library
math
Syntax

math.log(x[, base])

Description

If used with an argument, x, the math.log function returns the natural or Naperian logarithm of x. If the second parameter, base, is added, the math.log function returns the logarithm of x in the indicated base.

Parameters
  • x: Number to calculate the logarithm from.
  • base  (Optional) Base of the logarithm. If not indicated, the number e (2.718281...) is considered as the base.
Result

The result returned by the math.log function is a real number.

Examples

We can calculate the natural logarithm of the number 8 with the following code:

math.log(8)

2.0794415416798357

If we wanted to calculate the logarithm of 8 in base 2, we could do it as follows:

math.log(8, 2)

3.0

Submitted by admin on Sat, 01/30/2021 - 10:13