Language version: | ActionScript 3.0
|
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 static function abs(val:Number):Number
Language version: | ActionScript 3.0
|
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.
|
public static function acos(val:Number):Number
Language version: | ActionScript 3.0
|
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 .
|
public static function asin(val:Number):Number
Language version: | ActionScript 3.0
|
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.
|
public static function atan(val:Number):Number
Language version: | ActionScript 3.0
|
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.
|
public static function atan2(y:Number, x:Number):Number
Language version: | ActionScript 3.0
|
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
See also
public static function ceil(val:Number):Number
Language version: | ActionScript 3.0
|
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
public static function cos(angleRadians:Number):Number
Language version: | ActionScript 3.0
|
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
public static function exp(val:Number):Number
Language version: | ActionScript 3.0
|
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
| Number —
e to the power of the parameter val .
|
See also
public static function floor(val:Number):Number
Language version: | ActionScript 3.0
|
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 .
|
public static function log(val:Number):Number
Language version: | ActionScript 3.0
|
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 .
|
public static function max(val1:Number, val2:Number, ... rest):Number
Language version: | ActionScript 3.0
|
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
public static function min(val1:Number, val2:Number, ... rest):Number
Language version: | ActionScript 3.0
|
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
public static function pow(base:Number, pow:Number):Number
Language version: | ActionScript 3.0
|
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 .
|
public static function random():Number
Language version: | ActionScript 3.0
|
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()
public static function round(val:Number):Number
Language version: | ActionScript 3.0
|
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
public static function sin(angleRadians:Number):Number
Language version: | ActionScript 3.0
|
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
public static function sqrt(val:Number):Number
Language version: | ActionScript 3.0
|
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).
|
public static function tan(angleRadians:Number):Number
Language version: | ActionScript 3.0
|
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
public static const E:Number = 2.71828182845905
Language version: | ActionScript 3.0
|
A mathematical constant for the base of natural logarithms, expressed as e.
The approximate value of e
is 2.71828182845905.
public static const LN10:Number = 2.302585092994046
Language version: | ActionScript 3.0
|
A mathematical constant for the natural logarithm of 10, expressed as loge10,
with an approximate value of 2.302585092994046.
public static const LN2:Number = 0.6931471805599453
Language version: | ActionScript 3.0
|
A mathematical constant for the natural logarithm of 2, expressed as loge2,
with an approximate value of 0.6931471805599453.
public static const LOG10E:Number = 0.4342944819032518
Language version: | ActionScript 3.0
|
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.
public static const LOG2E:Number = 1.442695040888963387
Language version: | ActionScript 3.0
|
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.
public static const PI:Number = 3.141592653589793
Language version: | ActionScript 3.0
|
A mathematical constant for the ratio of the circumference of a circle to its diameter,
expressed as pi, with a value of 3.141592653589793.
public static const SQRT1_2:Number = 0.7071067811865476
Language version: | ActionScript 3.0
|
A mathematical constant for the square root of one-half, with an approximate
value of 0.7071067811865476.
public static const SQRT2:Number = 1.4142135623730951
Language version: | ActionScript 3.0
|
A mathematical constant for the square root of 2, with an approximate
value of 1.4142135623730951.
© 2004-2022 Adobe Systems Incorporated. All rights reserved.
Wed Sep 28 2022, 6:12 PM GMT+01:00