class Math
no package
This class defines mathematical functions and constants.
See also:
Static variables
staticread onlyNEGATIVE_INFINITY:Float
A special Float
constant which denotes negative infinity.
For example, this is the result of -1.0 / 0.0
.
Operations with NEGATIVE_INFINITY
as an operand may result in
NEGATIVE_INFINITY
, POSITIVE_INFINITY
or NaN
.
If this constant is converted to an Int
, e.g. through Std.int()
, the
result is unspecified.
staticread onlyNaN:Float
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.
staticread onlyPI:Float
Represents the ratio of the circumference of a circle to its diameter,
specified by the constant, π. PI
is approximately 3.141592653589793
.
staticread onlyPOSITIVE_INFINITY:Float
A special Float
constant which denotes positive infinity.
For example, this is the result of 1.0 / 0.0
.
Operations with POSITIVE_INFINITY
as an operand may result in
NEGATIVE_INFINITY
, POSITIVE_INFINITY
or NaN
.
If this constant is converted to an Int
, e.g. through Std.int()
, the
result is unspecified.
Static methods
staticabs(v:Float):Float
Returns the absolute value of v
.
- If
v
is positive or0
, the result is unchanged. Otherwise the result is-v
. - If
v
isNEGATIVE_INFINITY
orPOSITIVE_INFINITY
, the result isPOSITIVE_INFINITY
. - If
v
isNaN
, the result isNaN
.
staticacos(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
.
staticasin(v:Float):Float
Returns the trigonometric arc of the specified angle v
, in radians.
If v
is NaN
or infinite, the result is NaN
.
staticatan(v:Float):Float
Returns the trigonometric arc tangent of the specified angle v
,
in radians.
If v
is NaN
or infinite, the result is NaN
.
staticatan2(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
, NEGATIVE_INFINITY
or POSITIVE_INFINITY
,
the result is NaN
.
staticceil(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
, NEGATIVE_INFINITY
or POSITIVE_INFINITY
, the result is unspecified.
staticcos(v:Float):Float
Returns the trigonometric cosine of the specified angle v
, in radians.
If v
is NaN
or infinite, the result is NaN
.
staticexp(v:Float):Float
Returns Euler's number, raised to the power of v
.
exp(1.0)
is approximately 2.718281828459
.
- If
v
isPOSITIVE_INFINITY
, the result isPOSITIVE_INFINITY
. - If
v
isNEGATIVE_INFINITY
, the result is0.0
. - If
v
isNaN
, the result isNaN
.
staticfloor(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
, NEGATIVE_INFINITY
or POSITIVE_INFINITY
, the result is unspecified.
staticlog(v:Float):Float
Returns the natural logarithm of v
.
This is the mathematical inverse operation of exp,
i.e. log(exp(v)) == v
always holds.
- If
v
is negative (includingNEGATIVE_INFINITY
) orNaN
, the result isNaN
. - If
v
isPOSITIVE_INFINITY
, the result isPOSITIVE_INFINITY
. - If
v
is0.0
, the result isNEGATIVE_INFINITY
.
staticmax(a:Float, b:Float):Float
Returns the greater of values a
and b
.
- If
a
orb
areNaN
, the result isNaN
. - If
a
orb
arePOSITIVE_INFINITY
, the result isPOSITIVE_INFINITY
. - If
a
andb
areNEGATIVE_INFINITY
, the result isNEGATIVE_INFINITY
.
staticmin(a:Float, b:Float):Float
Returns the smaller of values a
and b
.
- If
a
orb
areNaN
, the result isNaN
. - If
a
orb
areNEGATIVE_INFINITY
, the result isNEGATIVE_INFINITY
. - If
a
andb
arePOSITIVE_INFINITY
, the result isPOSITIVE_INFINITY
.
staticrandom():Float
Returns a pseudo-random number which is greater than or equal to 0.0
,
and less than 1.0
.
staticround(v:Float):Int
Rounds v
to the nearest integer value.
Ties are rounded up, so that 0.5
becomes 1
and -0.5
becomes 0
.
If v
is outside of the signed Int32
range, or is NaN
, NEGATIVE_INFINITY
or POSITIVE_INFINITY
, the result is unspecified.
staticsin(v:Float):Float
Returns the trigonometric sine of the specified angle v
, in radians.
If v
is NaN
or infinite, the result is NaN
.