Docly Developers
Section16 pages

Math functions

JS functions for Maths.

Math calculations()Example of doing math calculations within JS. Numbers are IEEE 754 double-precision values, as in standard JavaScript: 0.1 + 0.2 gives…Math.atan(value)Returns the arctangent (in radians) of a number. The returned value is between -π/2 and π/2.Math.random()Returns a pseudo-random number from 0 (inclusive) to 1 (exclusive). It is not cryptographically secure — do not use it for passwords…Math.cos(angle)Returns the cosine of a number in radians. The returned value is between -1 and 1.Math.PI()Returns the number PI.Math.sin(angle)Returns the sine of a number in radians. The returned value is between -1 and 1.Math.sqrt(value)Calculates and returns the square root of a number.Math.tan(angle)Returns the tangent of a number in radians.Math.abs(value)Turns any number into a positive number. If positive no change, if negative the value is multiplied by -1.Math.pow(base, exponent)Returns the value of a base raised to a powerMath.ceil(value)Always rounds a number upwards.Math.floor(value)Always rounds a number downwards.Math.round(value)Rounds a number to the closest whole number. A value exactly halfway is rounded up (towards +∞), as in standard JavaScript: 5.5 gives 6 and…Math.min(values...)Returns the smallest of the given numbers. Docly addition: you can also pass an array, Math.min(values).Math.max(values...)Returns the largest of the given numbers. Docly addition: you can also pass an array, Math.max(values).Math.trunc(value)Removes the decimals of a number, rounding towards zero: 4.7 gives 4 and -4.7 gives -4 (Math.floor(-4.7) gives -5).