Webmaster in a Nutshell, 3rd Edition By Robert Eckstein, Stephen Spainhour
Table of Contents
Chapter 11. JavaScript
Math
Core JavaScript 1.0; JScript 1.0; ECMA v1
Mathematical functions and constants
Math. constant Math. function ( )
Description
The Math object is a placeholder for grouping mathematical constants and functions. It does not define a class of objects as Date and String do. There is no Math( ) constructor, and functions like Math.sin( ) are simply functions, not methods that operate on an object.
Constants
Math.E
The constant e , the base of the natural logarithm.
Math.LN10
The natural logarithm of 10.
Math.LN2
The natural logarithm of 2.
Math.LOG10E
The base-10 logarithm of e .
Math.LOG2E
The base-2 logarithm of e .
Math.PI
The constant .
Math.SQRT1_2
1 divided by the square root of 2.
Math.SQRT2
The square root of 2.
Functions
Math.abs( x )
Returns the absolute value of x .
Math.acos( x )
Returns the arc cosine of x ; the return value is between 0 and radians.
Math.asin( x )
Returns the arc sine of x ; the return value is between - /2 and /2 radians.
Math.atan( x )
Returns the arc tangent of x ; the return value is between - /2 and /2 radians.
Math.atan2( y , x )
Returns a value between - and radians that specifies the counterclockwise angle between the positive X-axis and the point ( x , y ). Note the order of the arguments to this function.
Math.ceil( x )
Returns the nearest integer greater than or equal to x .
Math.cos( x )
Returns the cosine of the specified value x .
Math.exp( x )
Returns the constant e raised to the power of x .
Math.floor( x )
Returns the nearest integer less than or equal to x .
Math.log( x )
Returns the natural logarithm of x .
Math.max( args... )
Returns the largest of the arguments. Returns -Infinity if there are no arguments. Returns NaN if any of the arguments is NaN or is a non-numeric value that cannot be converted to a number. Prior to ECMA v3, this function requires exactly 2 arguments.
Math.min( args... )
Returns the smallest of the arguments. Returns Infinity if there are no arguments. Returns NaN if any argument is NaN or is a non-numeric value that cannot be converted to a number. Prior to ECMA v3, this function requires exactly 2 arguments.
Math.pow( x , y )
Returns x to the power of y .
Math.random( )
Returns a pseudorandom number between 0.0 and 1.0. JS 1.1; JScript 1.0; ECMA v1.
Math.round( x )
Returns the integer closest to x .
Math.sin( x )
Returns the sine of x .
Math.sqrt( x )
Returns the square root of x . Returns NaN if x is less than zero.