Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

Math.log

Math.log(x, base = Math::E) → Float

Returns the base base logarithm of x.

  • Domain: [0, INFINITY].

  • Range: [-INFINITY, INFINITY)].

Examples:

Example
log(0.0)        # => -Infinity
log(1.0)        # => 0.0
log(E)          # => 1.0
log(INFINITY)   # => Infinity

log(0.0, 2.0)   # => -Infinity
log(1.0, 2.0)   # => 0.0
log(2.0, 2.0)   # => 1.0

log(0.0, 10.0)  # => -Infinity
log(1.0, 10.0)  # => 0.0
log(10.0, 10.0) # => 1.0
See also .lgamma .log10 .ldexp .log2 also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0