Skip to main content

Math

The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.

All of the methods and constants under Math class is static

Reference

Static methods

MethodSignatureReturn TypeDescription
absabs(n : number)numberReturns the absolute value of a number
acosacos(n : number)numberReturns the arc cosine (inverse cosine) of a number in radians
asinasin(n : number)numberReturns the arc sine (inverse sine) of a number in radians
atan2atan2(y : number, x : number)numberReturns the angle (in radians) between the positive x-axis and the point (x, y)
atanatan(n : number)numberReturns the arc tangent (inverse tangent) of a number in radians
cbrtcbrt(n : number)numberReturns the cube root of a number
ceilceil(n : number)numberReturns the smallest integer greater than or equal to a number
clampclamp(value : number, min : number, max : number)numberRestricts a value to be within the given range [min, max]
coscos(n : number)numberReturns the cosine of a number (in radians)
degToRaddegToRad(degrees : number)numberConverts an angle from degrees to radians
expexp(n : number)numberReturns Euler’s number (e) raised to the power of the given number
floorfloor(n : number)numberReturns the largest integer less than or equal to a number
fractfract(n : number)numberReturns the fractional part of a number (n - floor(n))
hypothypot(a : number, b : number)numberReturns the Euclidean distance √(a² + b²)
lerplerp(a : number, b : number, t : number)numberLinearly interpolates between a and b using t (a + (b - a) * t)
log2log2(n : number)numberReturns the base-2 logarithm of a number
log10log10(n : number)numberReturns the base-10 logarithm of a number
loglog(n : number)numberReturns the natural logarithm (base e) of a number
maxmax(a : number, b : number)numberReturns the larger of two numbers
minmin(a : number, b : number)numberReturns the smaller of two numbers
powpow(base : number, power : int)numberReturns the result of raising a number to the given integer power
radToDegradToDeg(radians : number)numberConverts an angle from radians to degrees
randomrandom()numberReturns a pseudo-random number in the range [0, 1)
roundround(n : number)numberRounds a number to the nearest integer
signsign(n : number)numberReturns the sign of a number (-1, 0, or 1)
sinsin(n : number)numberReturns the sine of a number (in radians)
sqrtsqrt(n : number)numberReturns the square root of a number
tantan(n : number)numberReturns the tangent of a number (in radians)
trunctrunc(n : number)numberReturns the integer part of a number by removing its fractional digits

Static constants

ConstantTypeDescription
PInumberThe mathematical constant π (3.14159...)
EnumberEuler’s number (2.71828...)
  • Math.PI
  • Math.E