Home  >  Article  >  Web Front-end  >  How to find logarithm in JavaScript

How to find logarithm in JavaScript

青灯夜游
青灯夜游Original
2021-11-24 14:45:565004browse

Method for finding logarithms: 1. Use the LN2 attribute and the syntax "Math.LN2" to return the natural logarithm of 2; 2. Use the LN10 attribute and the syntax "Math.LN10"; 3. Use LOG2E Attribute, syntax "Math.LOG2E"; 4. Use log() method, syntax "Math.log(x)".

How to find logarithm in JavaScript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

JavaScript method of finding logarithms:

1. Use the LN2 attribute of the Math object

## The #LN2 attribute is

, which returns the natural logarithm of 2 (approximately equal to 0.693), and its value is approximately 0.69314718055994528623. How to find logarithm in JavaScript

Syntax:

Math.LN2

2. Use the LN10 attribute of the Math object

LN10 attribute is

, Returns the natural logarithm of 10 (approximately 2.302), which is approximately 2.3025850929940459011. How to find logarithm in JavaScript

Grammar:

Math.LN10

3. Use the LOG2E attribute of the Math object

The LOG2E attribute is log2e and can be returned The logarithm of e with base 2 (approximately equal to 1.4426950408889634)

Syntax:

Math.LOG2E

4. Use the LOG10E attribute of the Math object

LOG10E attribute is

, which can return the logarithm of e with base 10 (approximately equal to 0.434). How to find logarithm in JavaScript

Grammar:

Math.LOG10E

5. Use the log() method of the Math object

log() method can Returns the natural logarithm of a number (based on E).

Syntax:

Math.log(x)

x: required. Any number or expression.​

  • If x is a negative number, return NaN.

  • If x is 0, return -Infinity.

Example:


Math.log(2);

Outputable:


0.6931471805599453

[Related recommendations:

javascript learning tutorial

The above is the detailed content of How to find logarithm in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn