Method: Math#log
- Defined in:
- math.c
#log(x) ⇒ Float (private) #log(x, base) ⇒ Float (private)
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)
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
434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'math.c', line 434 static VALUE math_log(int argc, const VALUE *argv, VALUE obj) { VALUE x, base; double d; rb_scan_args(argc, argv, "11", &x, &base); d = math_log1(x); if (argc == 2) { d /= math_log1(base); } return DBL2NUM(d); } |