JavaScripture
Contribute Feedback

JavaScript 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.

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.

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.

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.

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:

 

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:

 

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:

 

ceil(x : Number) : Number

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

Example:

Run

Results:

 

cos(x : Number) : Number

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

Example:

Run

Results:

 

exp(x : Number) : Number

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

Example:

Run

Results:

 

floor(x : Number) : Number

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

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 and for base 2, you can use Math.log(x) * Math.LOG2E. See also exp().

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).

Example:

Run

Results:

 

round(x : Number) : Number

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

Example:

Run

Results:

 

sin(x : Number) : Number

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

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: