Math Operations
The Math object is a static class. All methods and properties are static. The Math class can not be created using the "new" operator.
Math Constructors:
None.
Math Examples:
//round to next lowest integer
var n = Math.floor( 1.23 ); //n is now 1
//round up to next highest integer
var n = Math.ceil( 1.23 ); //n is now 2
Math Properties:
- E Euler's constant and the base of natural logarithms, approximately 2.718.
- var n = Math.E;
- LOG2E Base 2 logarithm of E (approximately 1.442).
- LOG10E Base 10 logarithm of E (approximately 0.434).
- LN2 Natural logarithm of 2, approximately 0.693.
- LN10 Natural logarithm of 10, approximately 2.302.
- PI Ratio of the circumference of a circle to its diameter, approximately 3.14159.
- SQRT2 Square root of 2, approximately 1.414.
- SQRT1_2 Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707.
Math Methods:
- abs(nValue) Returns the absolute value of nValue.
- var negValue = -10;
- var absValue= Math.abs(negValue);
- /* absValue will now equal 10 */
- acos(nValue) Returns the arc cosine of nValue.
- asin(nValue) Returns the arc sine of nValue.
- atan(nValue) Returns the arc tangent of nValue.
- atan2(yValue, xValue) Returns the angle (in radians) from the X axis to a point (y,x).
- ceil(nValue) Returns the smallest integer greater than or equal to nValue.
- cos(nValue) Returns the cosine of nValue.
- exp(nValue) Returns E to the power of nValue.
- floor(nValue) Returns the largest integer less than or equal to nValue.
- log(nValue) Returns the natural log of nValue.
- max(aValue, bValue) Returns the maximum value of aValue and bValue.
- min(aValue, bValue) Returns the minimum value of aValue and bValue.
- pow(baseValue, exponentValue) Returns baseValue to the power of exponentValue (baseValue ^ exponentValue)
- random() Returns a random number.
- round(nValue) Returns the value of nValue rounded to the nearest integer.
- sin(nValue) Returns the sin of nValue.
- sqrt(nValue) Returns the square root of nValue.
- tan(nValue) Returns the tangent of nValue.