Languages
[Edit]
EN

JavaScript - Math.log2() method example

1 points
Created by:
Root-ssh
178290

The Math.log2() method returns the logarithm with base 2 of a number. 

The Math.log2() method is presented on the following chart:

Math.log2(x) function visualization - JavaScript Math Object.
Math.log2(x) function visualization - JavaScript Math Object.

1. Documentation

Edit
SyntaxMath.log2(x)
Parametersx - integer or float number value in range 0 to +Infinity (primitive value).
Result

number value calcualted as log_2(x) mathematical function (primitive value).

If x is nagative it returns NaN.

If x is equal to 0 it returns -Infinity.

If x is equal to +Infinity it returns -Infinity.

Description

log2 is a static method that takes one parameter and returns an approximation of the log_2(x) mathematical function (logarithm with base 2). log2 is called binary logarithm.

Note: this method has been introduced in ES 2015.


2. Custom method implemenetation example

Edit

3. Canvas plot example

Edit

References

Edit
  1. Binary logarithm - Wikipedia

Alternative titles

  1. JavaScript - Math.log2() documentation with examples
  2. js - Math.log2() method documentation with examples
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - Math documentation (EN)

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join