Availability: |
| ||||||||
JavaScript syntax: | - | Math | |||||||
Object properties: | constructor | ||||||||
Class constants: | E, LN10, LN2, LOG10E, LOG2E, PI, SQRT1_2, SQRT2 | ||||||||
Functions: | abs(), acos(), asin(), atan(), atan2(), ceil(), cos(), exp(), floor(), log(), max(), min(), pow(), random(), round(), sin(), sqrt(), tan() |
The Math object is merely a single object owned by the Global Object and which cannot be instantiated. It has some named properties, some of which are functions while others are constants.
The prototype for the Math prototype object is the Object prototype object.
Although it cannot be instantiated, it does have a constructor which in turn has a prototype property. By adding functions to that prototype, you can extend the capabilities of the Math object. Several examples are provided in nearby topics to illustrate the addition of extra trigonometric and hyperbolic functions.
The Math object provides a collection of static constant values by way of properties belonging to the integral Math object. because the mathematical mechanisms of any application tend to be provided by the operating system, you should find that between different browsers on any particular platform, the values that these constants yield will be very consistent.
The ECMA standard lays down strict values for these properties and in general, the browser manufacturers try to comply - however, there is always the possibility that an implementation may use a non-compliant calculation.
However, it may not be quite so reliable across platforms. You might enumerate one of these constants as you are authoring and then hard code that value into your script. When that script is executed on another platform, even in the same browser, the internal mathematics support may yield a different value.
You should always refer to the static constants using their symbolic names rather than hard code a possibly platform dependant value into your script.
Note for the trigonometric functions in general that certain implied identities cannot be assumed in JavaScript. For example:
Math.sin(Math.PI/2) may not yield exactly 1
Math.cos(Math.PI) may not return precisely zero
Math.acos(0) may not return the same value as Math.PI
Math.SQRT1_2 may not be exactly equal to the reciprocal of Math.SQRT2
Property | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
constructor | 1.0 ![]() | 1.0 ![]() | 2.0 ![]() | 3.02 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
ECMA 262 edition 2 - section - 10.1.5
ECMA 262 edition 2 - section - 15.1.4.1
ECMA 262 edition 2 - section - 15.8
ECMA 262 edition 3 - section - 10.1.5
ECMA 262 edition 3 - section - 15.1.5.1
ECMA 262 edition 3 - section - 15.8
Prev | Home | Next |
MaskFilter() | Up | Math.abs() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |