StrictMath
contains methods for performing basic
numeric operations such as the elementary exponential, logarithm,
square root, and trigonometric functions.
To help ensure portability of Java programs, the definitions of
some of the numeric functions in this package require that they
produce the same results as certain published algorithms. These
algorithms are available from the well-known network library
netlib
as the package "Freely Distributable Math
Library," fdlibm
. These
algorithms, which are written in the C programming language, are
then to be understood to be transliterated into Java and executed
with all floating-point and integer operations following the rules
of Java arithmetic. The following transformations are used in the
transliteration:
double
in C is expressed using Java platform methods that
perform bit-wise conversions from double
to long
and long
to double
.
int
values in C are mapped to signed int
values in Java with updates to operations to replicate
unsigned semantics where the results on the same textual operation
would differ. For example, >>
shifts on unsigned C values
are replaced with >>>
shifts on signed Java values. Sized
comparisons on unsigned C values (<
, <=
, >
,
>=
) are replaced with semantically equivalent calls to
compareUnsigned
.
The Java math library is defined with respect to
fdlibm
version 5.3. Where fdlibm
provides
more than one definition for a function (such as
acos
), use the "IEEE 754 core function" version
(residing in a file whose name begins with the letter
e
). The methods which require fdlibm
semantics are sin
, cos
, tan
,
asin
, acos
, atan
,
exp
, log
, log10
,
cbrt
, atan2
, pow
,
sinh
, cosh
, tanh
,
hypot
, expm1
, and log1p
.
The platform uses signed two's complement integer arithmetic with
int and long primitive types. The developer should choose
the primitive type to ensure that arithmetic operations consistently
produce correct results, which in some cases means the operations
will not overflow the range of values of the computation.
The best practice is to choose the primitive type and algorithm to avoid
overflow. In cases where the size is int
or long
and
overflow errors need to be detected, the methods whose names end with
Exact
throw an ArithmeticException
when the results overflow.
Math
class discusses how the shared
quality of implementation criteria for selected Math
and
StrictMath
methods relate to the IEEE 754
recommended operations.
Modifier and Type | Class and Description |
---|---|
private static class |
Modifier and Type | Field and Description |
---|---|
public static final double | E
The |
public static final double | PI
The |
public static final double | TAU
The |
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
public static int | Returns: the absolute value of the argument.the argument whose absolute value is to be determined. a)Returns the absolute value of an |
public static long | Returns: the absolute value of the argument.the argument whose absolute value is to be determined. a)Returns the absolute value of a |
public static float | Returns: the absolute value of the argument.the argument whose absolute value is to be determined a)Returns the absolute value of a |
public static double | Returns: the absolute value of the argument.the argument whose absolute value is to be determined a)Returns the absolute value of a |
public static int | Returns: the absolute value of the argument, unless overflow occursthe argument whose absolute value is to be determined a)Returns the mathematical absolute value of an |
public static long | Returns: the absolute value of the argument, unless overflow occursthe argument whose absolute value is to be determined a)Returns the mathematical absolute value of an |
public static double | Returns: the arc cosine of the argument.the value whose arc cosine is to be returned. a)Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi. |
public static int | Returns: the resultthe first value x, int the second value y)Returns the sum of its arguments,
throwing an exception if the result overflows an |
public static long | Returns: the resultthe first value x, long the second value y)Returns the sum of its arguments,
throwing an exception if the result overflows a |
public static double | Returns: the arc sine of the argument.the value whose arc sine is to be returned. a)Returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2. |
public static double | Returns: the arc tangent of the argument.the value whose arc tangent is to be returned. a)Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2. |
public static double | Returns: the theta component of the point (r, theta) in polar coordinates that corresponds to the point (x, y) in Cartesian coordinates.the ordinate coordinate y, double the abscissa coordinate x)Returns the angle theta from the conversion of rectangular
coordinates ( |
public static double | |
public static double | Returns: 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.a value. a)Returns the smallest (closest to negative infinity)
|
public static int | Returns: the smallest (closest to negative infinity)int value that is greater than or equal to the algebraic quotient.the dividend x, int the divisor y)Returns the smallest (closest to negative infinity)
|
public static long | Returns: the smallest (closest to negative infinity)long value that is greater than or equal to the algebraic quotient.the dividend x, int the divisor y)Returns the smallest (closest to negative infinity)
|
public static long | Returns: the smallest (closest to negative infinity)long value that is greater than or equal to the algebraic quotient.the dividend x, long the divisor y)Returns the smallest (closest to negative infinity)
|
public static int | Returns: the smallest (closest to negative infinity)int value that is greater than or equal to the algebraic quotient.the dividend x, int the divisor y)Returns the smallest (closest to negative infinity)
|
public static long | Returns: the smallest (closest to negative infinity)long value that is greater than or equal to the algebraic quotient.the dividend x, long the divisor y)Returns the smallest (closest to negative infinity)
|
public static int | Returns: the ceiling modulusx - (ceilDiv(x, y) * y) the dividend x, int the divisor y)Returns the ceiling modulus of the |
public static int | Returns: the ceiling modulusx - (ceilDiv(x, y) * y) the dividend x, int the divisor y)Returns the ceiling modulus of the |
public static long | Returns: the ceiling modulusx - (ceilDiv(x, y) * y) the dividend x, long the divisor y)Returns the ceiling modulus of the |
public static int | Returns: a clamped value that fits intomin..max intervalvalue to clamp value, int minimal allowed value min, int maximal allowed value max)Clamps the value to fit between min and max. |
public static long | Returns: a clamped value that fits intomin..max intervalvalue to clamp value, long minimal allowed value min, long maximal allowed value max)Clamps the value to fit between min and max. |
public static double | Returns: a clamped value that fits intomin..max intervalvalue to clamp value, double minimal allowed value min, double maximal allowed value max)Clamps the value to fit between min and max. |
public static float | Returns: a clamped value that fits intomin..max intervalvalue to clamp value, float minimal allowed value min, float maximal allowed value max)Clamps the value to fit between min and max. |
public static double | Returns: a value with the magnitude ofmagnitude
and the sign of sign .the parameter providing the magnitude of the result magnitude, double the parameter providing the sign of the result sign)Returns the first floating-point argument with the sign of the second floating-point argument. |
public static float | Returns: a value with the magnitude ofmagnitude
and the sign of sign .the parameter providing the magnitude of the result magnitude, float the parameter providing the sign of the result sign)Returns the first floating-point argument with the sign of the second floating-point argument. |
public static double | Returns: the cosine of the argument.an angle, in radians. a)Returns the trigonometric cosine of an angle. |
public static double | Returns: The hyperbolic cosine ofx .The number whose hyperbolic cosine is to be returned. x)Returns the hyperbolic cosine of a |
public static int | Returns: the resultthe value to decrement a)Returns the argument decremented by one,
throwing an exception if the result overflows an |
public static long | Returns: the resultthe value to decrement a)Returns the argument decremented by one,
throwing an exception if the result overflows a |
public static int | Returns: the quotientx / y the dividend x, int the divisor y)Returns the quotient of the arguments, throwing an exception if the
result overflows an |
public static long | Returns: the quotientx / y the dividend x, long the divisor y)Returns the quotient of the arguments, throwing an exception if the
result overflows a |
public static double | Returns: the value ea ,
where e is the base of the natural logarithms.the exponent to raise e to. a)Returns Euler's number e raised to the power of a
|
public static double | Returns: the value ex - 1.the exponent to raise e to in the computation of
e x)x -1.Returns ex -1. |
public static double | Returns: the largest (closest to positive infinity) floating-point value that less than or equal to the argument and is equal to a mathematical integer.a value. a)Returns the largest (closest to positive infinity)
|
public static int | Returns: the largest (closest to positive infinity)int value that is less than or equal to the algebraic quotient.the dividend x, int the divisor y)Returns the largest (closest to positive infinity)
|
public static long | Returns: the largest (closest to positive infinity)long value that is less than or equal to the algebraic quotient.the dividend x, int the divisor y)Returns the largest (closest to positive infinity)
|
public static long | Returns: the largest (closest to positive infinity)long value that is less than or equal to the algebraic quotient.the dividend x, long the divisor y)Returns the largest (closest to positive infinity)
|
public static int | Returns: the largest (closest to positive infinity)int value that is less than or equal to the algebraic quotient.the dividend x, int the divisor y)Returns the largest (closest to positive infinity)
|
public static long | Returns: the largest (closest to positive infinity)long value that is less than or equal to the algebraic quotient.the dividend x, long the divisor y)Returns the largest (closest to positive infinity)
|
public static int | Returns: the floor modulusx - (floorDiv(x, y) * y) the dividend x, int the divisor y)Returns the floor modulus of the |
public static int | Returns: the floor modulusx - (floorDiv(x, y) * y) the dividend x, int the divisor y)Returns the floor modulus of the |
public static long | Returns: the floor modulusx - (floorDiv(x, y) * y) the dividend x, long the divisor y)Returns the floor modulus of the |
private static double | floorOrCeil(double
the value to be floored or ceiled a, double result for values in (-1, 0) negativeBoundary, double result for values in (0, 1) positiveBoundary, double the sign of the result sign)Internal method to share logic between floor and ceil. |
public static double | Returns: (a × b + c) computed, as if with unlimited range and precision, and rounded once to the nearestdouble valuea value a, double a value b, double a value c)Returns the fused multiply add of the three arguments; that is,
returns the exact product of the first two arguments summed
with the third argument and then rounded once to the nearest
|
public static float | Returns: (a × b + c) computed, as if with unlimited range and precision, and rounded once to the nearestfloat valuea value a, float a value b, float a value c)Returns the fused multiply add of the three arguments; that is,
returns the exact product of the first two arguments summed
with the third argument and then rounded once to the nearest
|
public static int | Returns: the unbiased exponent of the argumenta f)float valueReturns the unbiased exponent used in the representation of a
|
public static int | Returns: the unbiased exponent of the argumenta d)double valueReturns the unbiased exponent used in the representation of a
|
public static double | Returns: sqrt(x2 +y2) without intermediate overflow or underflowa value x, double a value y)Returns sqrt(x2 +y2) without intermediate overflow or underflow. |
public static double | Returns: the remainder whenf1 is divided by
f2 .the dividend. f1, double the divisor. f2)Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard. |
public static int | Returns: the resultthe value to increment a)Returns the argument incremented by one,
throwing an exception if the result overflows an |
public static long | Returns: the resultthe value to increment a)Returns the argument incremented by one,
throwing an exception if the result overflows a |
public static double | Returns: the value lna , the natural logarithm of
a .a value a)Returns the natural logarithm (base e) of a |
public static double | Returns: the base 10 logarithm ofa .a value a)Returns the base 10 logarithm of a |
public static double | Returns: the value ln(x + 1), the natural
log of x + 1a value x)Returns the natural logarithm of the sum of the argument and 1. |
public static int | Returns: the larger ofa and b .an argument. a, int another argument. b)Returns the greater of two |
public static long | Returns: the larger ofa and b .an argument. a, long another argument. b)Returns the greater of two |
public static float | Returns: the larger ofa and b .an argument. a, float another argument. b)Returns the greater of two |
public static double | Returns: the larger ofa and b .an argument. a, double another argument. b)Returns the greater of two |
public static int | Returns: the smaller ofa and b .an argument. a, int another argument. b)Returns the smaller of two |
public static long | Returns: the smaller ofa and b .an argument. a, long another argument. b)Returns the smaller of two |
public static float | Returns: the smaller ofa and b. an argument. a, float another argument. b)Returns the smaller of two |
public static double | Returns: the smaller ofa and b .an argument. a, double another argument. b)Returns the smaller of two |
public static int | Returns: the resultthe first value x, int the second value y)Returns the product of the arguments,
throwing an exception if the result overflows an |
public static long | Returns: the resultthe first value x, int the second value y)Returns the product of the arguments, throwing an exception if the result
overflows a |
public static long | Returns: the resultthe first value x, long the second value y)Returns the product of the arguments,
throwing an exception if the result overflows a |
public static long | Returns: the resultthe first value x, int the second value y)Returns the exact mathematical product of the arguments. |
public static long | Returns: the resultthe first value x, long the second value y)Returns as a |
public static int | Returns: the resultthe value to negate a)Returns the negation of the argument,
throwing an exception if the result overflows an |
public static long | Returns: the resultthe value to negate a)Returns the negation of the argument,
throwing an exception if the result overflows a |
public static double | Returns: The floating-point number adjacent tostart in the
direction of direction .starting floating-point value start, double value indicating which of
direction)start 's neighbors or start should
be returnedReturns the floating-point number adjacent to the first argument in the direction of the second argument. |
public static float | Returns: The floating-point number adjacent tostart in the
direction of direction .starting floating-point value start, double value indicating which of
direction)start 's neighbors or start should
be returnedReturns the floating-point number adjacent to the first argument in the direction of the second argument. |
public static double | Returns: The adjacent floating-point value closer to negative infinity.starting floating-point value d)Returns the floating-point value adjacent to |
public static float | Returns: The adjacent floating-point value closer to negative infinity.starting floating-point value f)Returns the floating-point value adjacent to |
public static double | Returns: The adjacent floating-point value closer to positive infinity.starting floating-point value d)Returns the floating-point value adjacent to |
public static float | Returns: The adjacent floating-point value closer to positive infinity.starting floating-point value f)Returns the floating-point value adjacent to |
public static double | Returns: the valuea b .base. a, double the exponent. b)Returns the value of the first argument raised to the power of the second argument. |
public static double | Returns: a pseudorandomdouble greater than or equal
to 0.0 and less than 1.0 .Returns a |
public static double | Returns: the closest floating-point value toa that is
equal to a mathematical integer.a value. a)Returns the |
public static int | Returns: the value of the argument rounded to the nearestint value.a floating-point value to be rounded to an integer. a)Returns the closest |
public static long | Returns: the value of the argument rounded to the nearestlong value.a floating-point value to be rounded to a
a)long .Returns the closest |
public static double | Returns: d × 2scaleFactor number to be scaled by a power of two. d, int power of 2 used to scale scaleFactor)d Returns |
public static float | Returns: f × 2scaleFactor number to be scaled by a power of two. f, int power of 2 used to scale scaleFactor)f Returns |
public static double | Returns: the signum function of the argumentthe floating-point value whose signum is to be returned d)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. |
public static float | Returns: the signum function of the argumentthe floating-point value whose signum is to be returned f)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. |
public static double | Returns: the sine of the argument.an angle, in radians. a)Returns the trigonometric sine of an angle. |
public static double | Returns: The hyperbolic sine ofx .The number whose hyperbolic sine is to be returned. x)Returns the hyperbolic sine of a |
public static double | Returns: the positive square root ofa .a value. a)Returns the correctly rounded positive square root of a
|
public static int | Returns: the resultthe first value x, int the second value to subtract from the first y)Returns the difference of the arguments,
throwing an exception if the result overflows an |
public static long | Returns: the resultthe first value x, long the second value to subtract from the first y)Returns the difference of the arguments,
throwing an exception if the result overflows a |
public static double | Returns: the tangent of the argument.an angle, in radians. a)Returns the trigonometric tangent of an angle. |
public static double | Returns: The hyperbolic tangent ofx .The number whose hyperbolic tangent is to be returned. x)Returns the hyperbolic tangent of a |
public static double | Returns: the measurement of the angleangrad
in degrees.an angle, in radians angrad)Converts an angle measured in radians to an approximately equivalent angle measured in degrees. |
public static int | Returns: the argument as an intthe long value value)Returns the value of the |
public static double | Returns: the measurement of the angleangdeg
in radians.an angle, in degrees angdeg)Converts an angle measured in degrees to an approximately equivalent angle measured in radians. |
public static double | Returns: the size of an ulp of the argumentthe floating-point value whose ulp is to be returned d)Returns the size of an ulp of the argument. |
public static float | Returns: the size of an ulp of the argumentthe floating-point value whose ulp is to be returned f)Returns the size of an ulp of the argument. |
public static long | Returns: the resultthe first value x, long the second value y)Returns as a |