Math object

Math object

Math object has no constructor thus you cannot create instances of it. Consider Math as a namespace – collection of static methods and constants.

Properties (constants)

E
– float, e – Euler’s constant, the base of natural logarithms.
LN2
– float, value of natural logarithm of 2.
LN10
– float, value of natural logarithm of 10.
LOG2E
– float, value of base 2 logarithm of e constant.
LOG10E
– float, value of base 10 logarithm of e constant.
PI
– float, Pi constant – the ratio of the circumference of a circle to its diameter.
SQRT1_2
– float, value of square root of 0.5.
SQRT2
– float, value of square root of 2.0.

Methods

abs
( integer | float )

Returns abs (positive) value of integer or float argument.

sin
cos
( integer | float ) returns: float

Returns value of sine or cosine of its argument.

tan
( integer | float ) returns: float

Returns tangent of its argument.

atan
( integer | float, [integer | float] ) returns: float

Returns arctangent if its arguments. Calls (in C runtime) function atan() for single argument or atan2() for two arguments.

asin
acos
( integer | float ) returns: float

Returns arcsine or arccosine if its argument.

sqrt
( integer | float ) returns: float
Returns the square root of the argument.
ceil
( float ) returns: float

Returns the smallest integral value greater than or equal to the argument.

floor
( float ) returns: float

Returns the largest integral value that is less than or equal to the argument

round
( float ) returns: float

Returns the closest integral value to the argument. Math.round(3.2) -> 3.0 and Math.round(3.7) -> 4.0

exp
( integer | float ) returns: float

Returns the exponential value of the argument, if successful. On overflow, the function returns INF (infinite) and on underflow, exp returns 0.0. To test number on infinity use Float.isFinite(value) method.

log
log2
log10
( integer | float ) returns: float

The log functions return logarithms of the argument if successful. If argument is negative, these functions return an indefinite (NaN). If argument is 0, they return INF (infinite). To test number on infinity use Float.isFinite(value) method.

pow
( number, exponent ) returns: float | integer

Calculates number raised to the power of exponent: result = numberexponent

random
(  ) returns: float

Returns random float number in range 0.0 … 1.0