| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Math/log | [Back] [Original] |
Get to know MDN better
Esta pgina foi traduzida do ingls pela comunidade. Saiba mais e junte-se comunidade MDN Web Docs.
This feature is well established and works across many devices and browser versions. Its been available across browsers since julho de 2015.
A funo Math.log() retorna o logaritmo natural(base e) de um nmero, que :
Math.log(x)
xUm nmero.
O logaritmo natural (base e) de um nmero dado. Se o nmero negativo, NaN retornado.
Se o valor de x negativo, o retorno ser sempre NaN.
Por log() ser um mtodo esttico de Math, voc sempre o usar como Math.log(), ao invs de um mtodo de um objeto de Math que voc criou(Math no um construtor).
Caso voc precise do logaritmo natural de 2 ou 10, use as constantes Math.LN2 ou Math.LN10 . Caso voc precise de um logaritmo de base 2 ou 10, use Math.log2() ou Math.log10() . Caso voc precise utilizar logaritmo de outras bases, use Math.log(x) / Math.log(outraBase) como no exemplo abaixo; talvez voc queira pr-calcular 1 / Math.log(outraBase) .
Math.log()Math.log(-1); // NaN, out of range
Math.log(0); // -Infinity
Math.log(1); // 0
Math.log(10); // 2.302585092994046
Math.log() como uma base diferenteAs funes a seguir retornam o logaritmo de y na base x (ie. logxy\log_x y):
function getBaseLog(x, y) {
return Math.log(y) / Math.log(x);
}
Caso voc execute getBaseLog(10, 1000) ser retornado 2.9999999999999996 devido ao arredondamento de ponto-flutuante, o qual bem prximo do retorno exato de 3.
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-math.log |
This page was last modified on 8 de nov. de 2023 by MDN contributors.
MathMath.abs()Math.acos()Math.acosh()Math.asin()Math.asinh()Math.atan()Math.atan2()Math.atanh()Math.cbrt()Math.ceil()Math.clz32()Math.cos()Math.cosh()Math.exp()Math.expm1()f16round()Math.floor()fround()Math.hypot()imul()Math.log()Math.log1p()Math.log2()Math.log10()Math.max()Math.min()Math.pow()Math.random()Math.round()Math.sign()Math.sin()Math.sinh()Math.sqrt()sumPrecise()Math.tan()Math.tanh()Math.trunc()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |