PackageTop Level
Classpublic final class Math
InheritanceMath Inheritance Object

Language version: ActionScript 3.0
Runtime version: 

The Math class contains methods and constants that represent common mathematical functions and values.

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

 

To calculate degrees from radians, use the following formula:


 degrees = radians * 180/Math.PI

 

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)

Note: The Math functions acos, asin, atan, atan2, cos, exp, log, pow, sin, and sqrt may result in slightly different values depending on the algorithms used by the CPU or operating system. Flash runtimes call on the CPU (or operating system if the CPU doesn't support floating point calculations) when performing the calculations for the listed functions, and results have shown slight variations depending upon the CPU or operating system in use.



Public Properties
 PropertyDefined by
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Public Methods
 MethodDefined by
  
[static] Computes and returns an absolute value for the number specified by the parameter val.
Math
  
[static] Computes and returns the arc cosine of the number specified in the parameter val, in radians.
Math
  
[static] Computes and returns the arc sine for the number specified in the parameter val, in radians.
Math
  
[static] Computes and returns the value, in radians, of the angle whose tangent is specified in the parameter val.
Math
  
[static] 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).
Math
  
[static] Returns the ceiling of the specified number or expression.
Math
  
cos(angleRadians:Number):Number
[static] Computes and returns the cosine of the specified angle in radians.
Math
  
[static] Returns the value of the base of the natural logarithm (e), to the power of the exponent specified in the parameter x.
Math
  
[static] Returns the floor of the number or expression specified in the parameter val.
Math
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
  
[static] Returns the natural logarithm of the parameter val.
Math
  
max(val1:Number, val2:Number, ... rest):Number
[static] Evaluates val1 and val2 (or more values) and returns the largest value.
Math
  
min(val1:Number, val2:Number, ... rest):Number
[static] Evaluates val1 and val2 (or more values) and returns the smallest value.
Math
  
pow(base:Number, pow:Number):Number
[static] Computes and returns base to the power of pow.
Math
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
  
[static] Returns a pseudo-random number n, where 0 <= n < 1.
Math
  
[static] Rounds the value of the parameter val up or down to the nearest integer and returns the value.
Math
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
  
sin(angleRadians:Number):Number
[static] Computes and returns the sine of the specified angle in radians.
Math
  
[static] Computes and returns the square root of the specified number.
Math
  
tan(angleRadians:Number):Number
[static] Computes and returns the tangent of the specified angle.
Math
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Public Constants
 ConstantDefined by
  E : Number = 2.71828182845905
[static] A mathematical constant for the base of natural logarithms, expressed as e.
Math
  LN10 : Number = 2.302585092994046
[static] A mathematical constant for the natural logarithm of 10, expressed as loge10, with an approximate value of 2.302585092994046.
Math
  LN2 : Number = 0.6931471805599453
[static] A mathematical constant for the natural logarithm of 2, expressed as loge2, with an approximate value of 0.6931471805599453.
Math
  LOG10E : Number = 0.4342944819032518
[static] A mathematical constant for the base-10 logarithm of the constant e (Math.E), expressed as log10e, with an approximate value of 0.4342944819032518.
Math
  LOG2E : Number = 1.442695040888963387
[static] A mathematical constant for the base-2 logarithm of the constant e, expressed as log2e, with an approximate value of 1.442695040888963387.
Math
  PI : Number = 3.141592653589793
[static] A mathematical constant for the ratio of the circumference of a circle to its diameter, expressed as pi, with a value of 3.141592653589793.
Math
  SQRT1_2 : Number = 0.7071067811865476
[static] A mathematical constant for the square root of one-half, with an approximate value of 0.7071067811865476.
Math
  SQRT2 : Number = 1.4142135623730951
[static] A mathematical constant for the square root of 2, with an approximate value of 1.4142135623730951.
Math
Method detail
abs()method
public static function abs(val:Number):Number

Language version: ActionScript 3.0
Runtime version: 

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

Parameters
val:Number — The number whose absolute value is returned.

Returns
Number — The absolute value of the specified parameter.
acos()method 
public static function acos(val:Number):Number

Language version: ActionScript 3.0
Runtime version: 

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

Parameters
val:Number — A number from -1.0 to 1.0.

Returns
Number — The arc cosine of the parameter val.
asin()method 
public static function asin(val:Number):Number

Language version: ActionScript 3.0
Runtime version: 

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

Parameters
val:Number — A number from -1.0 to 1.0.

Returns
Number — A number between negative pi divided by 2 and positive pi divided by 2.
atan()method 
public static function atan(val:Number):Number

Language version: ActionScript 3.0
Runtime version: 

Computes and returns the value, in radians, of the angle whose tangent is specified in the parameter val. The return value is between negative pi divided by 2 and positive pi divided by 2.

Parameters
val:Number — A number that represents the tangent of an angle.

Returns
Number — A number between negative pi divided by 2 and positive pi divided by 2.
atan2()method 
public static function atan2(y:Number, x:Number):Number

Language version: ActionScript 3.0
Runtime version: 

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). The return value is between positive pi and negative pi. Note that the first parameter to atan2 is always the y coordinate.

Parameters
y:Number — The y coordinate of the point.
 
x:Number — The x coordinate of the point.

Returns
Number — A number.

See also

ceil()method 
public static function ceil(val:Number):Number

Language version: ActionScript 3.0
Runtime version: 

Returns the ceiling of the specified number or expression. The ceiling of a number is the closest integer that is greater than or equal to the number.

Parameters
val:Number — A number or expression.

Returns
Number — An integer that is both closest to, and greater than or equal to, the parameter val.

See also

cos()method 
public static function cos(angleRadians:Number):Number

Language version: ActionScript 3.0
Runtime version: 

Computes and returns the cosine of the specified angle in radians. To calculate a radian, see the overview of the Math class.

Parameters
angleRadians:Number — A number that represents an angle measured in radians.

Returns
Number — A number from -1.0 to 1.0.

See also

exp()method 
public static function exp(val:Number):Number

Language version: ActionScript 3.0
Runtime version: 

Returns the value of the base of the natural logarithm (e), to the power of the exponent specified in the parameter x. The constant Math.E can provide the value of e.

Parameters
val:Number — The exponent; a number or expression.

Returns
Numbere to the power of the parameter val.

See also

floor()method 
public static function floor(val:Number):Number

Language version: ActionScript 3.0
Runtime version: 

Returns the floor of the number or expression specified in the parameter val. The floor is the closest integer that is less than or equal to the specified number or expression.

Parameters
val:Number — A number or expression.

Returns
Number — The integer that is both closest to, and less than or equal to, the parameter val.
log()method 
public static function log(val:Number):Number

Language version: ActionScript 3.0
Runtime version: 

Returns the natural logarithm of the parameter val.

Parameters
val:Number — A number or expression with a value greater than 0.

Returns
Number — The natural logarithm of parameter val.
max()method 
public static function max(val1:Number, val2:Number, ... rest):Number

Language version: ActionScript 3.0
Runtime version: 

Evaluates val1 and val2 (or more values) and returns the largest value.

Parameters
val1:Number — A number or expression.
 
val2:Number — A number or expression.
 
... rest — A number or expression. Math.max() can accept multiple arguments.

Returns
Number — The largest of the parameters val1 and val2 (or more values).

See also

min()method 
public static function min(val1:Number, val2:Number, ... rest):Number

Language version: ActionScript 3.0
Runtime version: 

Evaluates val1 and val2 (or more values) and returns the smallest value.

Parameters
val1:Number — A number or expression.
 
val2:Number — A number or expression.
 
... rest — A number or expression. Math.min() can accept multiple arguments.

Returns
Number — The smallest of the parameters val1 and val2 (or more values).

See also

pow()method 
public static function pow(base:Number, pow:Number):Number

Language version: ActionScript 3.0
Runtime version: 

Computes and returns base to the power of pow.

Parameters
base:Number — A number to be raised by the power of the parameter pow.
 
pow:Number — A number specifying the power that the parameter base is raised by.

Returns
Number — The value of base raised to the power of pow.
random()method 
public static function random():Number

Language version: ActionScript 3.0
Runtime version: 

Returns a pseudo-random number n, where 0 <= n < 1. The number returned is calculated in an undisclosed manner, and is "pseudo-random" because the calculation inevitably contains some element of non-randomness.

Returns
Number — A pseudo-random number.

See also

flash.crypto.generateRandomBytes()
round()method 
public static function round(val:Number):Number

Language version: ActionScript 3.0
Runtime version: 

Rounds the value of the parameter val up or down to the nearest integer and returns the value. If val is equidistant from its two nearest integers (that is, if the number ends in .5), the value is rounded up to the next higher integer.

Parameters
val:Number — The number to round.

Returns
Number — The parameter val rounded to the nearest whole number.

See also

sin()method 
public static function sin(angleRadians:Number):Number

Language version: ActionScript 3.0
Runtime version: 

Computes and returns the sine of the specified angle in radians. To calculate a radian, see the overview of the Math class.

Parameters
angleRadians:Number — A number that represents an angle measured in radians.

Returns
Number — A number; the sine of the specified angle (between -1.0 and 1.0).

See also

sqrt()method 
public static function sqrt(val:Number):Number

Language version: ActionScript 3.0
Runtime version: 

Computes and returns the square root of the specified number.

Parameters
val:Number — A number or expression greater than or equal to 0.

Returns
Number — If the parameter val is greater than or equal to zero, a number; otherwise NaN (not a number).
tan()method 
public static function tan(angleRadians:Number):Number

Language version: ActionScript 3.0
Runtime version: 

Computes and returns the tangent of the specified angle. To calculate a radian, see the overview of the Math class.

Parameters
angleRadians:Number — A number that represents an angle measured in radians.

Returns
Number — The tangent of the parameter angleRadians.

See also

Constant detail
Econstant
public static const E:Number = 2.71828182845905

Language version: ActionScript 3.0
Runtime version: 

A mathematical constant for the base of natural logarithms, expressed as e. The approximate value of e is 2.71828182845905.

LN10constant 
public static const LN10:Number = 2.302585092994046

Language version: ActionScript 3.0
Runtime version: 

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

LN2constant 
public static const LN2:Number = 0.6931471805599453

Language version: ActionScript 3.0
Runtime version: 

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

LOG10Econstant 
public static const LOG10E:Number = 0.4342944819032518

Language version: ActionScript 3.0
Runtime version: 

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

The Math.log() method computes the natural logarithm of a number. Multiply the result of Math.log() by Math.LOG10E to obtain the base-10 logarithm.

LOG2Econstant 
public static const LOG2E:Number = 1.442695040888963387

Language version: ActionScript 3.0
Runtime version: 

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

The Math.log method computes the natural logarithm of a number. Multiply the result of Math.log() by Math.LOG2E to obtain the base-2 logarithm.

PIconstant 
public static const PI:Number = 3.141592653589793

Language version: ActionScript 3.0
Runtime version: 

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

SQRT1_2constant 
public static const SQRT1_2:Number = 0.7071067811865476

Language version: ActionScript 3.0
Runtime version: 

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

SQRT2constant 
public static const SQRT2:Number = 1.4142135623730951

Language version: ActionScript 3.0
Runtime version: 

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