This documentation is archived and is not being maintained.

Math Object

An intrinsic object that provides basic mathematics functionality and constants. This object cannot be constructed explicitly.

The new operator cannot create the Math object and returns an error if you attempt to do so. The scripting engine creates the Math object when the engine is loaded. All of its methods and properties are available to a script at all times.

The following example illustrates a use of the Math object. Note that since floating-point numbers have limited precision, calculations involving them can accumulate small rounding errors. You can use the toFixed method of the Number object to display numbers without small rounding errors.

var pi : double = Math.PI;         // Should be about 3.14.
var cosPi : double = Math.cos(pi); // Should be minus one.
var sinPi : double = Math.sin(pi); // Should be zero.

The output of this code is: