Difference between revisions of "JavaScript Math Object"

From Techotopia
Jump to: navigation, search
Line 55: Line 55:
 
<td>sqrt</td>
 
<td>sqrt</td>
 
<td>Square root</td>
 
<td>Square root</td>
 +
</table>
 +
 +
In addition the math object contains a number of properties for accessing mathematical constants:
 +
 +
<table border="1" cellspacing="0">
 +
<tr>
 +
<th>Property</th>
 +
<th>Description</th>
 +
<tr>
 +
<td>E<td>Euler's constant</td>
 +
<tr>
 +
<td>LN2<td>Natural log of 2</td>
 +
<tr>
 +
<td>LN10<td>Natural log of 10</td>
 +
<tr>
 +
<td>LOG2E<td>Log base -2 of E</td>
 +
<tr>
 +
<td>LOG10E<td>Log base -10 of E</td>
 +
<tr>
 +
<td>PI<td>Value of Pi</td>
 +
<tr>
 +
<td>SQRT1_2</td>Square root of 0.5</td>
 +
<tr>
 +
<td>SQRT2</td>Square root of 2</td>
 
</table>
 
</table>

Revision as of 20:44, 17 May 2007

The JavaScript Math object provides a collections of mathematical constants and methods for performing such tasks as generating random numbers, rounding, obtaining values such as PI and performing calculations.

The following table lists the methods available with the Math object:

Method Description
abs Absolute value
sin, cos, tan Standard trigonometric functions; argument in radians
acos, asin, atan, atan2 Inverse trigonometric functions; return values in radians
exp, log Exponential and natural logarithm, base e
ceil Returns least integer greater than or equal to argument
floor Returns greatest integer less than or equal to argument
min, max Returns greater or lesser (respectively) of two arguments
pow Exponential; first argument is base, second is exponent
random Returns a random number between 0 and 1.
round Rounds argument to nearest integer
sqrt Square root

In addition the math object contains a number of properties for accessing mathematical constants:

Square root of 0.5</td>

<tr> <td>SQRT2</td>Square root of 2</td>

</table>
 
Property Description
EEuler's constant
LN2Natural log of 2
LN10Natural log of 10
LOG2ELog base -2 of E
LOG10ELog base -10 of E
PIValue of Pi
SQRT1_2