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
math.c
View on GitHub ↗
static VALUE
math_log(int argc, const VALUE *argv, VALUE unused_obj)
{
return rb_math_log(argc, argv);
}
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