home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

Math Object

Name

Math Object---placeholder for mathematical functions and constants

Availability

Navigator 2.0, Internet Explorer 3.0

Synopsis

Math.constant
Math.function()

Constants

E

the constant e, the base of the natural logarithm.

LN10

the natural logarithm of 10

LN2

the natural logarithm of 2

LOG10E

the base-10 logarithm of e

LOG2E

the base-2 logarithm of e

PI

the constant pi

SQRT1_2

1 divided by the square root of 2

SQRT2

the square root of 2

Functions

abs()

compute an absolute value

acos()

compute an arc cosine

asin()

compute an arc sine

atan()

compute an arc tangent

atan2()

compute the angle from the X axis to a point

ceil()

round a number up

cos()

compute a cosine

exp()

compute an exponent of e

floor()

round a number down

log()

compute a natural logarithm

max()

return the larger of two numbers

min()

return the smaller of two numbers

pow()

compute xy

random()

compute a random number; not available on all platforms

round()

round to the nearest integer

sin()

compute a sine

sqrt()

compute a square root

tan()

compute a tangent

Description

Math is a read-only reference to a placeholder object that contains mathematical functions and constants. These functions and constants are conveniently grouped by this Math object, and are invoked with syntax like this:

y = Math.sin(x);
area = radius * radius * Math.PI;

Math is actually a "global" property of the Window object, and as such, is usually referred to as Math, rather than as window.Math.

Math is not a class of objects like Date and String are. The Date class, for example, defines methods that operate on Date objects; on instances of the class. Math, on the other hand is simply an object that contains references to functions. These functions happen to be invoked through the Math object, but they do not operate on that object, as methods would.


Previous Home Next
Location.search Book Index Math.abs()

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell