class Math
Available on all platforms
This class defines mathematical functions and constants.
Class Fields
static var NEGATIVE_INFINITY:Float
A special Float constant which denotes negative infinity.
For example, this is the result of -1.0 / 0.0.
Operations with NEGATIVEINFINITY as an operand may result in NEGATIVEINFINITY, POSITIVE_INFINITY or NaN.
If this constant is converted to an Int, e.g. through Std.int(), the result is unspecified.
A special Float constant which denotes an invalid number.
NaN stands for "Not a Number". It occurs when a mathematically incorrect operation is executed, such as taking the square root of a negative number: Math.sqrt(-1).
All further operations with NaN as an operand will result in NaN.
If this constant is converted to an Int, e.g. through Std.int(), the result is unspecified.
In order to test if a value is NaN, you should use Math.isNaN() function.
@php In PHP versions prior to 5.3.1 VC 9 there may be unexpected results when performing arithmetic operations with NaN on Windows, see [https://bugs.php.net/bug.php?id=42143]
Represents the ratio of the circumference of a circle to its diameter,
specified by the constant, π. PI
is approximately 3.141592653589793.
static var POSITIVE_INFINITY:Float
A special Float constant which denotes negative infinity.
For example, this is the result of 1.0 / 0.0.
Operations with POSITIVEINFINITY as an operand may result in NEGATIVEINFINITY, POSITIVE_INFINITY or NaN.
If this constant is converted to an Int, e.g. through Std.int(), the result is unspecified.
static function abs(v:Float):Float
Returns the absolute value of v
.
If v
is positive or 0, the result is unchanged. Otherwise the result
is -v
.
If v
is NEGATIVEINFINITY or POSITIVEINFINITY, the result is
POSITIVE_INFINITY.
If v
is NaN, the result is NaN.
static function acos(v:Float):Float
Returns the trigonometric arc cosine of the specified angle v
,
in radians.
If v
is NaN or infinite, the result is NaN.
static function atan2(y:Float, x:Float):Float
Returns the trigonometric arc tangent whose tangent is the quotient of two specified numbers, in radians.
If parameter x
or y
is NaN, NEGATIVEINFINITY or POSITIVEINFINITY,
the result is NaN.
static function ceil(v:Float):Int
Returns the smallest integer value that is not less than v
.
If v
is outside of the signed Int32 range, or is NaN, NEGATIVEINFINITY
or POSITIVEINFINITY, the result is unspecified.
static function cos(v:Float):Float
Returns the trigonometric cosine of the specified angle v
, in radians.
If v
is NaN or infinite, the result is NaN.
static function floor(v:Float):Int
Returns the largest integer value that is not greater than v
.
If v
is outside of the signed Int32 range, or is NaN, NEGATIVEINFINITY
or POSITIVEINFINITY, the result is unspecified.
static function random():Float
Returns a pseudo-random number which is greater than or equal to 0.0, and less than 1.0.