Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Math.log

Math.log(x) → Float
Math.log(x, base) → Float

Returns the logarithm of x. If additional second argument is given, it will be the base of logarithm. Otherwise it is e (for the natural logarithm).

Domain: (0, INFINITY)

Codomain: (-INFINITY, INFINITY)

Example
Math.log(0)          #=> -Infinity
Math.log(1)          #=> 0.0
Math.log(Math::E)    #=> 1.0
Math.log(Math::E**3) #=> 3.0
Math.log(12, 3)      #=> 2.2618595071429146
See also .lgamma .log10 .ldexp .log2 also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0