10. December 2009 11:33
Javascript: The Math Object
Javascript also includes a predefined object for math functions. There are methods for constants like PI and methods for other mathematical needs.
The predefined constants are:
PI – Which represents Pi, the value is 3.1416
E – Stands for Euler’s constant “e”, which has the value 2.718
LN2 – Stands for the natural log of 2, which is about 0.693.
LN10 – Is the natural log of 10, which is about 2.302
LOG10E – Is the base 10 log of e, valued at 0.434
SQRT1_2 – The square root of one half, valued at 0.707
SQRT2 – The square root of two, about 1.414
The methods of the Math object:
| Method |
Format/Usage |
| Abs-- Absolute Value |
Math.abs(a number) |
| Acos—Arc Cosine (measured in radians) |
Math.acos(a number) |
| Asin—Arc Sine (measured in radians) |
Math.asin(a number) |
| Atan –Arc Tangent (measured in rads) |
Math.atan(a number) |
| Cos – Cosine |
Math.cos(a number in radians) |
| Sin –Sine |
Math.sin(a number in radians) |
| Tan –Tangent |
Math.tan(a number in radians) |
| Ceil—Ceiling Rounds number up to nearest integer. |
Math.ceil(a number) |
| Floor—Rounds to the lowest integer. |
Math.floor(a number) |
| Exp—Returns “e” to the power of a number. |
Math.exp(a number) |
| Log –Returns the natural logarithm of a number . |
Math.log(a number) |
| Pow –Returns the base number to given power. |
Math.pow(the base, the exponent) |
| Max—Returns the higher of two values. |
Math.max(number 1, number 2) |
| Min—Returns the lesser of two values. |
Math.min(number 1, number 2) |
| Round—Rounds to the closest integer. |
Math.round(a number) |
| Sqrt—Returns the square root of a number. |
Math.sqrt(a number) |
57281694-ee83-4530-8b77-c753cf79d48e|0|.0