Quirrel4.41.0

math.log

Defined in module "math"
from "math" import log
pure fastcall log(x: number): float

Returns the natural logarithm of x

Parameters

xnumberthe number to take the logarithm of

Return value

The natural logarithm of x, as a float.

Notes

The result is always a float, even when x is an integer: type(log(1)) is "float".

log(0) does not throw. It returns negative infinity. A negative x does not throw either; it returns NaN. Both print differently between compilers and platforms, so do not print them from portable code.

Example

examples/math/log.nut
from "math" import log

println("log(1) =", log(1))
println("log(2) =", log(2))

// the result is a float even when x is an integer
println("type(log(1)) =", type(log(1)))
Output:
log(1) = 0
log(2) = 0.693147
type(log(1)) = float

See also

log10Returns the base-10 logarithm of x
expReturns e raised to the power of x
powReturns x raised to the power y
mathmodule index