Export (0) Print
Expand All

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.
print(pi);
var cosPi : double = Math.cos(pi); // Should be minus one.
print(cosPi);
var sinPi : double = Math.sin(pi); // Should be zero.
print(sinPi.toFixed(10));

The output of this code is:

3.141592653589793
-1
0.0000000000

Community Additions

ADD
Show:
© 2014 Microsoft