Skip to content

Instantly share code, notes, and snippets.

@westc
Created April 7, 2018 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westc/25888e8e87e871c0648825cc6607954b to your computer and use it in GitHub Desktop.
Save westc/25888e8e87e871c0648825cc6607954b to your computer and use it in GitHub Desktop.
Find the logarithm of a given number using the given base.
var log;
(function(CACHE_LOG_INVERSE_BASE) {
log = function(x, opt_base) {
opt_base = opt_base || Math.E;
return Math.log(x)
* (
CACHE_LOG_INVERSE_BASE[opt_base] = CACHE_LOG_INVERSE_BASE.hasOwnProperty(opt_base)
? CACHE_LOG_INVERSE_BASE[opt_base]
: (5 / Math.log(Math.pow(opt_base, 5)))
);
};
})({});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment