JavaFX: Bringing Rich Experiences To All the Screens Of Your Life

Overview

The class `Math` contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.

Profile: common

Script Variable Summary

accessnametypedescription
publicEDouble

The `double` value that is closer than any other to e, the base of the natural logarithms.

publicPIDouble

The `double` value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.

Script Function Summary

public abs(a: Integer) : Integer

Returns the absolute value of an `int` value.

Returns the absolute value of an `int` value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.

Note that if the argument is equal to the value of `Integer.MIN_VALUE`, the most negative representable `int` value, the result is that same value, which is negative.

java.lang.Integer#MIN_VALUE

Parameters
a
the argument whose absolute value is to be determined
Returns
Integer
the absolute value of the argument.

Profile: common

public abs(a: Long) : Long

Returns the absolute value of a `long` value.

Returns the absolute value of a `long` value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.

Note that if the argument is equal to the value of `Long.MIN_VALUE`, the most negative representable `long` value, the result is that same value, which is negative.

java.lang.Long#MIN_VALUE

Parameters
a
the argument whose absolute value is to be determined
Returns
Long
the absolute value of the argument.

Profile: common

public abs(a: Number) : Number

Returns the absolute value of a `float` value.

Returns the absolute value of a `float` value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned. Special cases:

• If the argument is positive zero or negative zero, the result is positive zero.
• If the argument is infinite, the result is positive infinity.
• If the argument is NaN, the result is NaN.
In other words, the result is the same as the value of the expression:

`Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))`

Parameters
a
the argument whose absolute value is to be determined
Returns
Number
the absolute value of the argument.

Profile: common

public abs(a: Double) : Double

Returns the absolute value of a `double` value.

Returns the absolute value of a `double` value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned. Special cases:

• If the argument is positive zero or negative zero, the result is positive zero.
• If the argument is infinite, the result is positive infinity.
• If the argument is NaN, the result is NaN.
In other words, the result is the same as the value of the expression:

`Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)`

Parameters
a
the argument whose absolute value is to be determined
Returns
Double
the absolute value of the argument.

Profile: common

public acos(a: Double) : Double

Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi.

Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi. Special case:

• If the argument is NaN or its absolute value is greater than 1, then the result is NaN.

Parameters
a
the value whose arc cosine is to be returned.
Returns
Double
the arc cosine of the argument.

Profile: common

public asin(a: Double) : Double

Returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2.

Returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2. Special cases:

• If the argument is NaN or its absolute value is greater than 1, then the result is NaN.
• If the argument is zero, then the result is a zero with the same sign as the argument.

Parameters
a
the value whose arc sine is to be returned.
Returns
Double
the arc sine of the argument.

Profile: common

public atan(a: Double) : Double

Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2.

Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2. Special cases:

• If the argument is NaN, then the result is NaN.
• If the argument is zero, then the result is a zero with the same sign as the argument.

Parameters
a
the value whose arc tangent is to be returned.
Returns
Double
the arc tangent of the argument.

Profile: common

public atan2(y: Double, x: Double) : Double

Returns the angle theta from the conversion of rectangular coordinates (`x``y`) to polar coordinates (r, theta).

Returns the angle theta from the conversion of rectangular coordinates (`x``y`) to polar coordinates (r, theta). This method computes the phase theta by computing an arc tangent of `y/x` in the range of -pi to pi. Special cases:

• If either argument is NaN, then the result is NaN.
• If the first argument is positive zero and the second argument is positive, or the first argument is positive and finite and the second argument is positive infinity, then the result is positive zero.
• If the first argument is negative zero and the second argument is positive, or the first argument is negative and finite and the second argument is positive infinity, then the result is negative zero.
• If the first argument is positive zero and the second argument is negative, or the first argument is positive and finite and the second argument is negative infinity, then the result is the `double` value closest to pi.
• If the first argument is negative zero and the second argument is negative, or the first argument is negative and finite and the second argument is negative infinity, then the result is the `double` value closest to -pi.
• If the first argument is positive and the second argument is positive zero or negative zero, or the first argument is positive infinity and the second argument is finite, then the result is the `double` value closest to pi/2.
• If the first argument is negative and the second argument is positive zero or negative zero, or the first argument is negative infinity and the second argument is finite, then the result is the `double` value closest to -pi/2.
• If both arguments are positive infinity, then the result is the `double` value closest to pi/4.
• If the first argument is positive infinity and the second argument is negative infinity, then the result is the `double` value closest to 3*pi/4.
• If the first argument is negative infinity and the second argument is positive infinity, then the result is the `double` value closest to -pi/4.
• If both arguments are negative infinity, then the result is the `double` value closest to -3*pi/4.

Parameters
y
the ordinate coordinate
x
the abscissa coordinate
Returns
Double
the theta component of the point (r, theta) in polar coordinates that corresponds to the point (x, y) in Cartesian coordinates.

Profile: common

public cbrt(a: Double) : Double

Returns the cube root of a `double` value.

Returns the cube root of a `double` value. For positive finite `x`, ```cbrt(-x) == -cbrt(x)```; that is, the cube root of a negative value is the negative of the cube root of that value's magnitude. Special cases:

• If the argument is NaN, then the result is NaN.
• If the argument is infinite, then the result is an infinity with the same sign as the argument.
• If the argument is zero, then the result is a zero with the same sign as the argument.

Parameters
a
a value.
Returns
Double
the cube root of <code>a</code>.

Profile: common

public ceil(a: Double) : Double

Returns the smallest (closest to negative infinity) `double` value that is greater than or equal to the argument and is equal to a mathematical integer.

Returns the smallest (closest to negative infinity) `double` value that is greater than or equal to the argument and is equal to a mathematical integer. Special cases:

• If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
• If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
• If the argument value is less than zero but greater than -1.0, then the result is negative zero.
Note that the value of `Math.ceil(x)` is exactly the value of `-Math.floor(-x)`.

Parameters
a
a value.
Returns
Double
the smallest (closest to negative infinity) floating-point value that is greater than or equal to the argument and is equal to a mathematical integer.

Profile: common

public cos(a: Double) : Double

Returns the trigonometric cosine of an angle.

Returns the trigonometric cosine of an angle. Special cases:

• If the argument is NaN or an infinity, then the result is NaN.

Parameters
a
an angle, in radians.
Returns
Double
the cosine of the argument.

Profile: common

public cosh(x: Double) : Double

Returns the hyperbolic cosine of a `double` value.

Returns the hyperbolic cosine of a `double` value. The hyperbolic cosine of x is defined to be (ex + e-x)/2 where e is Math#E Euler's number.

Special cases:

• If the argument is NaN, then the result is NaN.
• If the argument is infinite, then the result is positive infinity.
• If the argument is zero, then the result is `1.0`.

Parameters
x
The number whose hyperbolic cosine is to be returned.
Returns
Double
The hyperbolic cosine of <code>x</code>.

Profile: common

public exp(a: Double) : Double

Returns Euler's number e raised to the power of a `double` value.

Returns Euler's number e raised to the power of a `double` value. Special cases:

• If the argument is NaN, the result is NaN.
• If the argument is positive infinity, then the result is positive infinity.
• If the argument is negative infinity, then the result is positive zero.

Parameters
a
the exponent to raise <i>e</i> to.
Returns
Double
the value <i>e</i><sup><code>a</code></sup>, where <i>e</i> is the base of the natural logarithms.

Profile: common

public floor(a: Double) : Double

Returns the largest (closest to positive infinity) `double` value that is less than or equal to the argument and is equal to a mathematical integer.

Returns the largest (closest to positive infinity) `double` value that is less than or equal to the argument and is equal to a mathematical integer. Special cases:

• If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
• If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.

Parameters
a
a value.
Returns
Double
the largest (closest to positive infinity) floating-point value that less than or equal to the argument and is equal to a mathematical integer.

Profile: common

public log(a: Double) : Double

Returns the natural logarithm (base e) of a `double` value.

Returns the natural logarithm (base e) of a `double` value. Special cases:

• If the argument is NaN or less than zero, then the result is NaN.
• If the argument is positive infinity, then the result is positive infinity.
• If the argument is positive zero or negative zero, then the result is negative infinity.

Parameters
a
a value
Returns
Double
the value ln&nbsp;<code>a</code>, the natural logarithm of <code>a</code>.

Profile: common

public log10(a: Double) : Double

Returns the base 10 logarithm of a `double` value.

Returns the base 10 logarithm of a `double` value. Special cases:

• If the argument is NaN or less than zero, then the result is NaN.
• If the argument is positive infinity, then the result is positive infinity.
• If the argument is positive zero or negative zero, then the result is negative infinity.
• If the argument is equal to 10n for integer n, then the result is n.

Parameters
a
a value
Returns
Double
the base 10 logarithm of <code>a</code>.

Profile: common

public max(a: Integer, b: Integer) : Integer

Returns the greater of two `int` values.

Returns the greater of two `int` values. That is, the result is the argument closer to the value of `Integer.MAX_VALUE`. If the arguments have the same value, the result is that same value.

java.lang.Long#MAX_VALUE

Parameters
a
an argument.
b
another argument.
Returns
Integer
the larger of <code>a</code> and <code>b</code>.

Profile: common

public max(a: Long, b: Long) : Long

Returns the greater of two `long` values.

Returns the greater of two `long` values. That is, the result is the argument closer to the value of `Long.MAX_VALUE`. If the arguments have the same value, the result is that same value.

java.lang.Long#MAX_VALUE

Parameters
a
an argument.
b
another argument.
Returns
Long
the larger of <code>a</code> and <code>b</code>.

Profile: common

public max(a: Number, b: Number) : Number

Returns the greater of two `float` values.

Returns the greater of two `float` values. That is, the result is the argument closer to positive infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other negative zero, the result is positive zero.

Parameters
a
an argument.
b
another argument.
Returns
Number
the larger of <code>a</code> and <code>b</code>.

Profile: common

public max(a: Double, b: Double) : Double

Returns the greater of two `double` values.

Returns the greater of two `double` values. That is, the result is the argument closer to positive infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other negative zero, the result is positive zero.

Parameters
a
an argument.
b
another argument.
Returns
Double
the larger of <code>a</code> and <code>b</code>.

Profile: common

public min(a: Integer, b: Integer) : Integer

Returns the smaller of two `int` values.

Returns the smaller of two `int` values. That is, the result the argument closer to the value of `Integer.MIN_VALUE`. If the arguments have the same value, the result is that same value.

java.lang.Long#MIN_VALUE

Parameters
a
an argument.
b
another argument.
Returns
Integer
the smaller of <code>a</code> and <code>b</code>.

Profile: common

public min(a: Long, b: Long) : Long

Returns the smaller of two `long` values.

Returns the smaller of two `long` values. That is, the result is the argument closer to the value of `Long.MIN_VALUE`. If the arguments have the same value, the result is that same value.

java.lang.Long#MIN_VALUE

Parameters
a
an argument.
b
another argument.
Returns
Long
the smaller of <code>a</code> and <code>b</code>.

Profile: common

public min(a: Number, b: Number) : Number

Returns the smaller of two `float` values.

Returns the smaller of two `float` values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other is negative zero, the result is negative zero.

Parameters
a
an argument.
b
another argument.
Returns
Number
the smaller of <code>a</code> and <code>b.</code>

Profile: common

public min(a: Double, b: Double) : Double

Returns the smaller of two `double` values.

Returns the smaller of two `double` values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other is negative zero, the result is negative zero.

Parameters
a
an argument.
b
another argument.
Returns
Double
the smaller of <code>a</code> and <code>b</code>.

Profile: common

public pow(a: Double, b: Double) : Double

Returns the value of the first argument raised to the power of the second argument.

Returns the value of the first argument raised to the power of the second argument. Special cases:

• If the second argument is positive or negative zero, then the result is 1.0.
• If the second argument is 1.0, then the result is the same as the first argument.
• If the second argument is NaN, then the result is NaN.
• If the first argument is NaN and the second argument is nonzero, then the result is NaN.
• If
• the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or
• the absolute value of the first argument is less than 1 and the second argument is negative infinity,
then the result is positive infinity.
• If
• the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or
• the absolute value of the first argument is less than 1 and the second argument is positive infinity,
then the result is positive zero.
• If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN.
• If
• the first argument is positive zero and the second argument is greater than zero, or
• the first argument is positive infinity and the second argument is less than zero,
then the result is positive zero.
• If
• the first argument is positive zero and the second argument is less than zero, or
• the first argument is positive infinity and the second argument is greater than zero,
then the result is positive infinity.
• If
• the first argument is negative zero and the second argument is greater than zero but not a finite odd integer, or
• the first argument is negative infinity and the second argument is less than zero but not a finite odd integer,
then the result is positive zero.
• If
• the first argument is negative zero and the second argument is a positive finite odd integer, or
• the first argument is negative infinity and the second argument is a negative finite odd integer,
then the result is negative zero.
• If
• the first argument is negative zero and the second argument is less than zero but not a finite odd integer, or
• the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer,
then the result is positive infinity.
• If
• the first argument is negative zero and the second argument is a negative finite odd integer, or
• the first argument is negative infinity and the second argument is a positive finite odd integer,
then the result is negative infinity.
• If the first argument is finite and less than zero
• if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument
• if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument
• if the second argument is finite and not an integer, then the result is NaN.
• If both arguments are integers, then the result is exactly equal to the mathematical result of raising the first argument to the power of the second argument if that result can in fact be represented exactly as a `double` value.

(In the foregoing descriptions, a floating-point value is considered to be an integer if and only if it is finite and a fixed point of the method <tt>ceil</tt> or, equivalently, a fixed point of the method <tt>floor</tt>. A value is a fixed point of a one-argument method if and only if the result of applying the method to the value is equal to the value.)

Parameters
a
the base.
b
the exponent.
Returns
Double
the value <code>a<sup>b</sup></code>.

Profile: common

public random() : Double

Returns a `double` value with a positive sign, greater than or equal to `0.0` and less than `1.0`.

Returns a `double` value with a positive sign, greater than or equal to `0.0` and less than `1.0`. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.

When this method is first called, it creates a single new pseudorandom-number generator, exactly as if by the expression

`new java.util.Random`
This new pseudorandom-number generator is used thereafter for all calls to this method and is used nowhere else.

This method is properly synchronized to allow correct use by more than one thread. However, if many threads need to generate pseudorandom numbers at a great rate, it may reduce contention for each thread to have its own pseudorandom-number generator.

java.util.Random#nextDouble()

Returns
Double
a pseudorandom <code>double</code> greater than or equal to <code>0.0</code> and less than <code>1.0</code>.

Profile: common

public round(a: Double) : Long

Returns the closest `long` to the argument.

Returns the closest `long` to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type `long`. In other words, the result is equal to the value of the expression:

`(long)Math.floor(a + 0.5d)`

Special cases:

• If the argument is NaN, the result is 0.
• If the argument is negative infinity or any value less than or equal to the value of `Long.MIN_VALUE`, the result is equal to the value of `Long.MIN_VALUE`.
• If the argument is positive infinity or any value greater than or equal to the value of `Long.MAX_VALUE`, the result is equal to the value of `Long.MAX_VALUE`.

Parameters
a
a floating-point value to be rounded to a <code>long</code>.
Returns
Long
the value of the argument rounded to the nearest <code>long</code> value.

Profile: common

public round(a: Number) : Integer

Returns the closest `int` to the argument.

Returns the closest `int` to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type `int`. In other words, the result is equal to the value of the expression:

`(int)Math.floor(a + 0.5f)`

Special cases:

• If the argument is NaN, the result is 0.
• If the argument is negative infinity or any value less than or equal to the value of `Integer.MIN_VALUE`, the result is equal to the value of `Integer.MIN_VALUE`.
• If the argument is positive infinity or any value greater than or equal to the value of `Integer.MAX_VALUE`, the result is equal to the value of `Integer.MAX_VALUE`.

Parameters
a
a floating-point value to be rounded to an integer.
Returns
Integer
the value of the argument rounded to the nearest <code>int</code> value.

Profile: common

public signum(a: Double) : Double

Returns the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero.

Returns the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero.

Special Cases:

• If the argument is NaN, then the result is NaN.
• If the argument is positive zero or negative zero, then the result is the same as the argument.

Parameters
a
the floating-point value whose signum is to be returned
Returns
Double
the signum function of the argument

Profile: common

public signum(a: Number) : Number

Returns the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, -1.0f if the argument is less than zero.

Returns the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, -1.0f if the argument is less than zero.

Special Cases:

• If the argument is NaN, then the result is NaN.
• If the argument is positive zero or negative zero, then the result is the same as the argument.

Parameters
a
the floating-point value whose signum is to be returned
Returns
Number
the signum function of the argument

Profile: common

public sin(a: Double) : Double

Returns the trigonometric sine of an angle.

Returns the trigonometric sine of an angle. Special cases:

• If the argument is NaN or an infinity, then the result is NaN.
• If the argument is zero, then the result is a zero with the same sign as the argument.

Parameters
a
an angle, in radians.
Returns
Double
the sine of the argument.

Profile: common

public sinh(x: Double) : Double

Returns the hyperbolic sine of a `double` value.

Returns the hyperbolic sine of a `double` value. The hyperbolic sine of x is defined to be (ex - e-x)/2 where e is Math#E Euler's number.

Special cases:

• If the argument is NaN, then the result is NaN.
• If the argument is infinite, then the result is an infinity with the same sign as the argument.
• If the argument is zero, then the result is a zero with the same sign as the argument.

Parameters
x
The number whose hyperbolic sine is to be returned.
Returns
Double
The hyperbolic sine of <code>x</code>.

Profile: common

public sqrt(a: Double) : Double

Returns the correctly rounded positive square root of a `double` value.

Returns the correctly rounded positive square root of a `double` value. Special cases:

• If the argument is NaN or less than zero, then the result is NaN.
• If the argument is positive infinity, then the result is positive infinity.
• If the argument is positive zero or negative zero, then the result is the same as the argument.
Otherwise, the result is the `double` value closest to the true mathematical square root of the argument value.

Parameters
a
a value.
Returns
Double
the positive square root of <code>a</code>. If the argument is NaN or less than zero, the result is NaN.

Profile: common

public tan(a: Double) : Double

Returns the trigonometric tangent of an angle.

Returns the trigonometric tangent of an angle. Special cases:

• If the argument is NaN or an infinity, then the result is NaN.
• If the argument is zero, then the result is a zero with the same sign as the argument.

Parameters
a
an angle, in radians.
Returns
Double
the tangent of the argument.

Profile: common

public tanh(x: Double) : Double

Returns the hyperbolic tangent of a `double` value.

Returns the hyperbolic tangent of a `double` value. The hyperbolic tangent of x is defined to be (ex - e-x)/(ex + e-x), in other words, Math#sinh sinh(<i>x</i>)/Math#cosh cosh(<i>x</i>). Note that the absolute value of the exact tanh is always less than 1.

Special cases:

• If the argument is NaN, then the result is NaN.
• If the argument is zero, then the result is a zero with the same sign as the argument.
• If the argument is positive infinity, then the result is `+1.0`.
• If the argument is negative infinity, then the result is `-1.0`.

Parameters
x
The number whose hyperbolic tangent is to be returned.
Returns
Double
The hyperbolic tangent of <code>x</code>.

Profile: common

public toDegrees(angrad: Double) : Double

Converts an angle measured in radians to an approximately equivalent angle measured in degrees.

Converts an angle measured in radians to an approximately equivalent angle measured in degrees. The conversion from radians to degrees is generally inexact; users should not expect `cos(toRadians(90.0))` to exactly equal `0.0`.

Parameters
an angle, in radians
Returns
Double
the measurement of the angle <code>angrad</code> in degrees.

Profile: common

public toRadians(angdeg: Double) : Double

Converts an angle measured in degrees to an approximately equivalent angle measured in radians.

Converts an angle measured in degrees to an approximately equivalent angle measured in radians. The conversion from degrees to radians is generally inexact.

Parameters
angdeg
an angle, in degrees
Returns
Double
the measurement of the angle <code>angdeg</code> in radians.

Profile: common