Math


Object
    |
    +-Math

public class Math
extends Object

The Math class is a top-level class whose methods and properties you can use without using a constructor.

Use the methods and properties of this class to access and manipulate mathematical constants and functions. All the properties and methods of the Math class are static and must be called using the syntax Math.method(parameter) or Math.constant. In ActionScript, constants are defined with the maximum precision of double-precision IEEE-754 floating-point numbers.

Several Math class methods use the measure of an angle in radians as a parameter.You can use the following equation to calculate radian values before calling the method and then provide the calculated value as the parameter, or you can provide the entire right side of the equation (with the angle's measure in degrees in place of degrees) as the radian parameter.

To calculate a radian value, use the following formula:

radians = degrees * Math.PI/180

The following is an example of passing the equation as a parameter to calculate the sine of a 45˚ angle:

Math.sin(45 * Math.PI/180) is the same as Math.sin(.7854)

Availability: ActionScript 1.0; Flash Lite 2.0 - In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports.

Property summary

Modifiers

Property

Description

static

E:Number

A mathematical constant for the base of natural logarithms, expressed as e.

static

LN10:Number

A mathematical constant for the natural logarithm of 10, expressed as loge10, with an approximate value of 2.302585092994046.

static

LN2:Number

A mathematical constant for the natural logarithm of 2, expressed as loge2, with an approximate value of 0.6931471805599453.

static

LOG10E:Number

A mathematical constant for the base-10 logarithm of the constant e (Math.E), expressed as log10e, with an approximate value of 0.4342944819032518.

static

LOG2E:Number

A mathematical constant for the base-2 logarithm of the constant e (Math.E), expressed as log2e, with an approximate value of 1.442695040888963387.

static

PI:Number

A mathematical constant for the ratio of the circumference of a circle to its diameter, expressed as pi, with a value of 3.141592653589793.

static

SQRT1_2:Number

A mathematical constant for the square root of one-half, with an approximate value of 0.7071067811865476.

static

SQRT2:Number

A mathematical constant for the square root of 2, with an approximate value of 1.4142135623730951.

Properties inherited from class Object

constructor (Object.constructor property), __proto__ (Object.__proto__ property), prototype (Object.prototype property), __resolve (Object.__resolve property)


Method summary

Modifiers

Signature

Description

static

abs(x:Number) : Number

Computes and returns an absolute value for the number specified by the parameter x.

static

acos(x:Number) : Number

Computes and returns the arc cosine of the number specified in the parameter x, in radians.

static

asin(x:Number) : Number

Computes and returns the arc sine for the number specified in the parameter x, in radians.

static

atan(tangent:Number) : Number

Computes and returns the value, in radians, of the angle whose tangent is specified in the parameter tangent.

static

atan2(y:Number, x:Number) : Number

Computes and returns the angle of the point y/x in radians, when measured counterclockwise from a circle's x axis (where 0,0 represents the center of the circle).

static

ceil(x:Number) : Number

Returns the ceiling of the specified number or expression.

static

cos(x:Number) : Number

Computes and returns the cosine of the specified angle in radians.

static

exp(x:Number) : Number

Returns the value of the base of the natural logarithm (e), to the power of the exponent specified in the parameter x.

static

floor(x:Number) : Number

Returns the floor of the number or expression specified in the parameter x.

static

log(x:Number) : Number

Returns the natural logarithm of parameter x.

static

max(x:Number, y:Number) : Number

Evaluates x and y and returns the larger value.

static

min(x:Number, y:Number) : Number

Evaluates x and y and returns the smaller value.

static

pow(x:Number, y:Number) : Number

Computes and returns x to the power of y.

static

random() : Number

Returns a pseudo-random number n, where 0 <= n < 1.

static

round(x:Number) : Number

Rounds the value of the parameter x up or down to the nearest integer and returns the value.

static

sin(x:Number) : Number

Computes and returns the sine of the specified angle in radians.

static

sqrt(x:Number) : Number

Computes and returns the square root of the specified number.

static

tan(x:Number) : Number

Computes and returns the tangent of the specified angle.

Methods inherited from class Object

addProperty (Object.addProperty method), hasOwnProperty (Object.hasOwnProperty method), isPropertyEnumerable (Object.isPropertyEnumerable method), isPrototypeOf (Object.isPrototypeOf method), registerClass (Object.registerClass method), toString (Object.toString method), unwatch (Object.unwatch method), valueOf (Object.valueOf method), watch (Object.watch method)