JavaScripture
Contribute via GitHub Feedback

Math : Object

Contains math related constants and functions.

Math Properties

E : Number  

The constant e = 2.718...

Example:

Run

Results:

 

LN10 : Number  

The value of the natural log of 10. It is the reciprocal of LOG10E. Useful for computing the log base 10 of a number. See also log10().

Example:

Run

Results:

 

LN2 : Number  

The value of the natural log of 2. It is the reciprocal of LOG2E. Useful for computing the log base 2 of a number. See also log2().

Example:

Run

Results:

 

LOG10E : Number  

The value of the log base 10 of e. It is the reciprocal of LN10. Useful for computing the log base 10 of a number. See also log10().

Example:

Run

Results:

 

LOG2E : Number  

The value of the log base 2 of e. It is the reciprocal of LN2. Useful for computing the log base 2 of a number. See also log2().

Example:

Run

Results:

 

PI : Number  

The constant pi = 3.14...

Example:

Run

Results:

 

SQRT1_2 : Number  

The value of 1 / sqrt(2).

Example:

Run

Results:

 

SQRT2 : Number  

The value of sqrt(2).

Example:

Run

Results:

 

Math Methods

abs(x : Number) : Number

Returns the absolute value of x.

Example:

Run

Results:

 

acos(x : Number) : Number

Returns the angle (in radians between 0 and pi) whose cosine is x. See also cos().

Example:

Run

Results:

 

acosh(x : Number) : Number

Returns the hyperbolic angle whose hyperbolic cosine is x. See also cosh().

Example:

Run

Results:

 

asin(x : Number) : Number

Returns the angle (in radians between -pi/2 and pi/2) whose sine is x. See also sin().

Example:

Run

Results:

 

asinh(x : Number) : Number

Returns the hyperbolic angle whose hyperbolic sine is x. See also sinh().

Example:

Run

Results:

 

atan(x : Number) : Number

Returns the angle (in radians between -pi/2 and pi/2) whose tangent is x. See also atan2() and tan().

Example:

Run

Results:

 

atan2(y : Number, x : Number) : Number

Returns the angle (in radians between -pi and pi) between the positive x axis and the line segment from the origin to the point at (x, y). See also atan() and tan().

Example:

Run

Results:

 

atanh(x : Number) : Number

Returns the hyperbolic angle whose hyperbolic tangent is x. See also tanh().

Example:

Run

Results:

 

cbrt(x : Number) : Number

Returns cube root of x.

Example:

Run

Results:

 

ceil(x : Number) : Number

Returns the next integer greater than or equal to x. See also round(), floor(), and trunc().

Example:

Run

Results:

 

clz(x : Number) : Number

Returns the number of leading 0 bits in the 32 bit unsigned integer representation of x.

Example:

Run

Results:

 

cos(x : Number) : Number

Returns the cosine of x (in radians). See also acos().

Example:

Run

Results:

 

cosh(x : Number) : Number

Returns the hyperbolic cosine of x. See also acosh().

Example:

Run

Results:

 

exp(x : Number) : Number

Returns e raised to the x power. See also log() and expm1().

Example:

Run

Results:

 

expm1(x : Number) : Number

Returns e raised to the x power minus 1. This is more accurate than using exp(x) - 1 when x is close to 0.

Example:

Run

Results:

 

floor(x : Number) : Number

Returns the previous integer less than or equal to x. See also round(), ceil(), and trunc().

Example:

Run

Results:

 

fround(x : Number) : Number

Returns the closest single precision (32 bit) floating point number to x.

Example:

Run

Results:

 

hypot(x : Number, y : Number, [z : Number, [...]]) : Number

Returns length of a vector with components [x, y, ...]. This is the square root of the sum of the squares of the components.

Example:

Run

Results:

 

imul(x : Number, y : Number) : Number

Returns the product of x and y treating both values as 32 bit integer values and truncating the result to a 32 bit integer value.

Example:

Run

Results:

 

log(x : Number) : Number

Returns the natural logarithm (base e) of x. To compute the logarithm with respect to a different base b, use the formula Math.log(x) / Math.log(b). For base 10, you can use Math.log(x) * Math.LOG10E (or log10() with ECMAScript 2015). For base 2, you can use Math.log(x) * Math.LOG2E (or log2() with ECMAScript 2015). See also exp() and log1p().

Example:

Run

Results:

 

log10(x : Number) : Number

Returns the base 10 logarithm of x. See also log(), LOG10E, and LN10.

Example:

Run

Results:

 

log1p(x : Number) : Number

Returns the natural logarithm (base e) of x + 1. This is more accurate than using log(x + 1) when x is close to 0.

Example:

Run

Results:

 

log2(x : Number) : Number

Returns the base 2 logarithm of x. See also log(), LOG2E, and LN2.

Example:

Run

Results:

 

max(x1 : Number, x2 : Number, [...]) : Number

Returns the largest number among the parameters.

Example:

Run

Results:

 

min(x1 : Number, x2 : Number, [...]) : Number

Returns the smallest number among the parameters.

Example:

Run

Results:

 

pow(x : Number, y : Number) : Number

Returns x raised to the y power.

Example:

Run

Results:

 

random() : Number

Returns a random number between 0 (inclusive) and 1 (exclusive). See also crypto.getRandomValues().

Example:

Run

Results:

 

round(x : Number) : Number

Returns the closest integer to x. See also floor(), ceil(), and trunc().

Example:

Run

Results:

 

sign(x : Number) : Number

Returns -1 if x is less than 0, 0 if x is 0, and 1 if x is greater than 0.

Example:

Run

Results:

 

sin(x : Number) : Number

Returns the sine of x (in radians). See also asin().

Example:

Run

Results:

 

sinh(x : Number) : Number

Returns the hyperbolic sine of x. See also asinh().

Example:

Run

Results:

 

sqrt(x : Number) : Number

Returns the square root of x.

Example:

Run

Results:

 

tan(x : Number) : Number

Returns the tangent of x (in radians). See also atan().

Example:

Run

Results:

 

tanh(x : Number) : Number

Returns the hyperbolic tan of x. See also atanh().

Example:

Run

Results:

 

trunc(x : Number) : Number

Returns the integer portion of x. This is the same as floor(x) for positive numbers and ceil(x) for negative numbers. See also round().

Example:

Run

Results: