Design & Download
Your JS Library
in Seconds!!!

Snippet: log() - Finding Any Logarithm

Written by Christopher West (cwest) on December 06, 2015.
Gets the logarithm of a given number with an optional given base.
function log(x, opt_base) {
  x = Math.log(x);
  return opt_base ? (x / Math.log(opt_base)) : x;
}

log(...) API Documentation

Description

Gets the logarithm of a given number with an optional given base.

Parameters

  1. x {number}:
    The number whose logarithm should be found.
  2. opt_base {number=}:
    Optional. Defaults to Math.E. The base of the logarithm to find for x.

Returns

Basically returns the equivalent of Math.log(x) / Math.log(opt_base || Math.E).