Class FastMath
Math
and
StrictMath
for large scale computation.
FastMath is a drop-in replacement for both Math and StrictMath. This
means that for any method in Math (say Math.sin(x)
or
Math.cbrt(y)
), user can directly change the class and use the
methods as is (using FastMath.sin(x)
or FastMath.cbrt(y)
in the previous example).
FastMath speed is achieved by relying heavily on optimizing compilers to native code present in many JVMs today and use of large tables. The larger tables are lazily initialized on first use, so that the setup time does not penalize methods that don't need them.
Note that FastMath is extensively used inside Hipparchus, so by calling some algorithms, the overhead when the the tables need to be initialized will occur regardless of the end-user calling FastMath methods directly or not. Performance figures for a specific JVM and hardware can be evaluated by running the FastMathTestPerformance tests in the test directory of the source distribution.
FastMath accuracy should be mostly independent of the JVM as it relies only on IEEE-754 basic operations and on embedded tables. Almost all operations are accurate to about 0.5 ulp throughout the domain range. This statement, of course is only a rough global observed behavior, it is not a guarantee for every double numbers input (see William Kahan's Table Maker's Dilemma).
FastMath additionally implements the following methods not found in Math/StrictMath:
The following methods are found in Math/StrictMath since 1.6 only, they are provided by FastMath even in 1.5 Java virtual machines-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
abs
(double x) Absolute value.static float
abs
(float x) Absolute value.static int
abs
(int x) Absolute value.static long
abs
(long x) Absolute value.static <T extends CalculusFieldElement<T>>
Tabs
(T x) Absolute value.static int
absExact
(int x) Absolute value.static long
absExact
(long x) Absolute value.static double
acos
(double x) Compute the arc cosine of a number.static <T extends CalculusFieldElement<T>>
Tacos
(T x) Compute the arc cosine of a number.static double
acosh
(double a) Compute the inverse hyperbolic cosine of a number.static <T extends CalculusFieldElement<T>>
Tacosh
(T a) Compute the inverse hyperbolic cosine of a number.static int
addExact
(int a, int b) Add two numbers, detecting overflows.static long
addExact
(long a, long b) Add two numbers, detecting overflows.static double
asin
(double x) Compute the arc sine of a number.static <T extends CalculusFieldElement<T>>
Tasin
(T x) Compute the arc sine of a number.static double
asinh
(double a) Compute the inverse hyperbolic sine of a number.static <T extends CalculusFieldElement<T>>
Tasinh
(T a) Compute the inverse hyperbolic sine of a number.static double
atan
(double x) Arctangent functionstatic <T extends CalculusFieldElement<T>>
Tatan
(T x) Arctangent functionstatic double
atan2
(double y, double x) Two arguments arctangent functionstatic <T extends CalculusFieldElement<T>>
Tatan2
(T y, T x) Two arguments arctangent functionstatic double
atanh
(double a) Compute the inverse hyperbolic tangent of a number.static <T extends CalculusFieldElement<T>>
Tatanh
(T a) Compute the inverse hyperbolic tangent of a number.static double
cbrt
(double x) Compute the cubic root of a number.static <T extends CalculusFieldElement<T>>
Tcbrt
(T x) Compute the cubic root of a number.static double
ceil
(double x) Get the smallest whole number larger than x.static <T extends CalculusFieldElement<T>>
Tceil
(T x) Get the smallest whole number larger than x.static int
ceilDiv
(int a, int b) Finds q such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.static long
ceilDiv
(long a, int b) Finds q such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.static long
ceilDiv
(long a, long b) Finds q such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.static int
ceilDivExact
(int a, int b) Finds q such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.static long
ceilDivExact
(long a, long b) Finds q such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.static int
ceilMod
(int a, int b) Finds r such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.static int
ceilMod
(long a, int b) Finds r such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.static long
ceilMod
(long a, long b) Finds r such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.static double
clamp
(double value, double inf, double sup) Clamp a value within an interval.static float
clamp
(float value, float inf, float sup) Clamp a value within an interval.static int
clamp
(int value, int inf, int sup) Clamp a value within an interval.static int
clamp
(long value, int inf, int sup) Clamp a value within an interval.static long
clamp
(long value, long inf, long sup) Clamp a value within an interval.static double
copySign
(double magnitude, double sign) Returns the first argument with the sign of the second argument.static float
copySign
(float magnitude, float sign) Returns the first argument with the sign of the second argument.static <T extends CalculusFieldElement<T>>
TcopySign
(T magnitude, double sign) Returns the first argument with the sign of the second argument.static <T extends CalculusFieldElement<T>>
TcopySign
(T magnitude, T sign) Returns the first argument with the sign of the second argument.static double
cos
(double x) Cosine function.static <T extends CalculusFieldElement<T>>
Tcos
(T x) Cosine function.static double
cosh
(double x) Compute the hyperbolic cosine of a number.static <T extends CalculusFieldElement<T>>
Tcosh
(T x) Compute the hyperbolic cosine of a number.static int
decrementExact
(int n) Decrement a number, detecting overflows.static long
decrementExact
(long n) Decrement a number, detecting overflows.static int
divideExact
(int x, int y) Divide two integers, checking for overflow.static long
divideExact
(long x, long y) Divide two long integers, checking for overflow.static double
exp
(double x) Exponential function.static <T extends CalculusFieldElement<T>>
Texp
(T x) Exponential function.static double
expm1
(double x) Compute exp(x) - 1static <T extends CalculusFieldElement<T>>
Texpm1
(T x) Compute exp(x) - 1static double
floor
(double x) Get the largest whole number smaller than x.static <T extends CalculusFieldElement<T>>
Tfloor
(T x) Get the largest whole number smaller than x.static int
floorDiv
(int a, int b) Finds q such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.static long
floorDiv
(long a, int b) Finds q such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.static long
floorDiv
(long a, long b) Finds q such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.static int
floorDivExact
(int a, int b) Finds q such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.static long
floorDivExact
(long a, long b) Finds q such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.static int
floorMod
(int a, int b) Finds r such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.static int
floorMod
(long a, int b) Finds r such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.static long
floorMod
(long a, long b) Finds r such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.static double
fma
(double a, double b, double c) Compute Fused-multiply-add operation a * b + c.static float
fma
(float a, float b, float c) Compute Fused-multiply-add operation a * b + c.static int
getExponent
(double d) Return the exponent of a double number, removing the bias.static int
getExponent
(float f) Return the exponent of a float number, removing the bias.static double
hypot
(double x, double y) Returns the hypotenuse of a triangle with sidesx
andy
- sqrt(x2 +y2)
avoiding intermediate overflow or underflow.static <T extends CalculusFieldElement<T>>
Thypot
(T x, T y) Returns the hypotenuse of a triangle with sidesx
andy
- sqrt(x2 +y2)
avoiding intermediate overflow or underflow.static double
IEEEremainder
(double dividend, double divisor) Computes the remainder as prescribed by the IEEE 754 standard.static <T extends CalculusFieldElement<T>>
TIEEEremainder
(T dividend, double divisor) Computes the remainder as prescribed by the IEEE 754 standard.static <T extends CalculusFieldElement<T>>
TIEEEremainder
(T dividend, T divisor) Computes the remainder as prescribed by the IEEE 754 standard.static int
incrementExact
(int n) Increment a number, detecting overflows.static long
incrementExact
(long n) Increment a number, detecting overflows.static double
log
(double x) Natural logarithm.static double
log
(double base, double x) Computes the logarithm in a given base.static <T extends CalculusFieldElement<T>>
Tlog
(T x) Natural logarithm.static double
log10
(double x) Compute the base 10 logarithm.static <T extends CalculusFieldElement<T>>
Tlog10
(T x) Compute the base 10 logarithm.static double
log1p
(double x) Computes log(1 + x).static <T extends CalculusFieldElement<T>>
Tlog1p
(T x) Computes log(1 + x).static double
max
(double a, double b) Compute the maximum of two valuesstatic float
max
(float a, float b) Compute the maximum of two valuesstatic int
max
(int a, int b) Compute the maximum of two valuesstatic long
max
(long a, long b) Compute the maximum of two valuesstatic <T extends CalculusFieldElement<T>>
Tmax
(T a, double b) Compute the maximum of two valuesstatic <T extends CalculusFieldElement<T>>
Tmax
(T a, T b) Compute the maximum of two valuesstatic double
min
(double a, double b) Compute the minimum of two valuesstatic float
min
(float a, float b) Compute the minimum of two valuesstatic int
min
(int a, int b) Compute the minimum of two valuesstatic long
min
(long a, long b) Compute the minimum of two valuesstatic <T extends CalculusFieldElement<T>>
Tmin
(T a, double b) Compute the minimum of two valuesstatic <T extends CalculusFieldElement<T>>
Tmin
(T a, T b) Compute the minimum of two valuesstatic int
multiplyExact
(int a, int b) Multiply two numbers, detecting overflows.static long
multiplyExact
(long a, int b) Multiply two numbers, detecting overflows.static long
multiplyExact
(long a, long b) Multiply two numbers, detecting overflows.static long
multiplyFull
(int a, int b) Multiply two integers and give an exact result without overflow.static long
multiplyHigh
(long a, long b) Multiply two long integers and give the 64 most significant bits of the result.static int
negateExact
(int x) Negates the argument.static long
negateExact
(long x) Negates the argument.static double
nextAfter
(double d, double direction) Get the next machine representable number after a number, moving in the direction of another number.static float
nextAfter
(float f, double direction) Get the next machine representable number after a number, moving in the direction of another number.static double
nextDown
(double a) Compute next number towards negative infinity.static float
nextDown
(float a) Compute next number towards negative infinity.static double
nextUp
(double a) Compute next number towards positive infinity.static float
nextUp
(float a) Compute next number towards positive infinity.static <T extends CalculusFieldElement<T>>
doublenorm
(T x) Norm.static double
pow
(double x, double y) Power function.static double
pow
(double d, int e) Raise a double to an int power.static double
pow
(double d, long e) Raise a double to a long power.static <T extends CalculusFieldElement<T>>
Tpow
(T x, double y) Power function.static <T extends CalculusFieldElement<T>>
Tpow
(T d, int e) Raise a double to an int power.static <T extends CalculusFieldElement<T>>
Tpow
(T x, T y) Power function.static double
random()
Returns a pseudo-random number between 0.0 and 1.0.static double
rint
(double x) Get the whole number that is the nearest to x, or the even one if x is exactly half way between two integers.static <T extends CalculusFieldElement<T>>
Trint
(T x) Get the whole number that is the nearest to x, or the even one if x is exactly half way between two integers.static long
round
(double x) Get the closest long to x.static int
round
(float x) Get the closest int to x.static <T extends CalculusFieldElement<T>>
longround
(T x) Get the closest long to x.static double
scalb
(double d, int n) Multiply a double number by a power of 2.static float
scalb
(float f, int n) Multiply a float number by a power of 2.static <T extends CalculusFieldElement<T>>
Tscalb
(T d, int n) Multiply a double number by a power of 2.static <T extends CalculusFieldElement<T>>
Tsign
(T a) Compute the sign of a number.static double
signum
(double a) Compute the signum of a number.static float
signum
(float a) Compute the signum of a number.static double
sin
(double x) Sine function.static <T extends CalculusFieldElement<T>>
Tsin
(T x) Sine function.static SinCos
sinCos
(double x) Combined Sine and Cosine function.static <T extends CalculusFieldElement<T>>
FieldSinCos<T>sinCos
(T x) Combined Sine and Cosine function.static double
sinh
(double x) Compute the hyperbolic sine of a number.static <T extends CalculusFieldElement<T>>
Tsinh
(T x) Compute the hyperbolic sine of a number.static SinhCosh
sinhCosh
(double x) Combined hyperbolic sine and hyperbolic cosine function.static <T extends CalculusFieldElement<T>>
FieldSinhCosh<T>sinhCosh
(T x) Combined hyperbolic sine and hyperbolic cosine function.static double
sqrt
(double a) Compute the square root of a number.static <T extends CalculusFieldElement<T>>
Tsqrt
(T a) Compute the square root of a number.static int
subtractExact
(int a, int b) Subtract two numbers, detecting overflows.static long
subtractExact
(long a, long b) Subtract two numbers, detecting overflows.static double
tan
(double x) Tangent function.static <T extends CalculusFieldElement<T>>
Ttan
(T x) Tangent function.static double
tanh
(double x) Compute the hyperbolic tangent of a number.static <T extends CalculusFieldElement<T>>
Ttanh
(T x) Compute the hyperbolic tangent of a number.static double
toDegrees
(double x) Convert radians to degrees, with error of less than 0.5 ULPstatic <T extends CalculusFieldElement<T>>
TtoDegrees
(T x) Convert radians to degrees, with error of less than 0.5 ULPstatic int
toIntExact
(long n) Convert a long to interger, detecting overflowsstatic double
toRadians
(double x) Convert degrees to radians, with error of less than 0.5 ULPstatic <T extends CalculusFieldElement<T>>
TtoRadians
(T x) Convert degrees to radians, with error of less than 0.5 ULPstatic double
ulp
(double x) Compute least significant bit (Unit in Last Position) for a number.static float
ulp
(float x) Compute least significant bit (Unit in Last Position) for a number.static <T extends CalculusFieldElement<T>>
Tulp
(T x) Compute least significant bit (Unit in Last Position) for a number.static long
unsignedMultiplyHigh
(long a, long b) Multiply two long unsigned integers and give the 64 most significant bits of the unsigned result.
-
Field Details
-
PI
public static final double PIArchimede's constant PI, ratio of circle circumference to diameter.- See Also:
-
E
public static final double ENapier's constant e, base of the natural logarithm.- See Also:
-
-
Method Details
-
sqrt
public static double sqrt(double a) Compute the square root of a number.Note: this implementation currently delegates to
Math.sqrt(double)
- Parameters:
a
- number on which evaluation is done- Returns:
- square root of a
-
cosh
public static double cosh(double x) Compute the hyperbolic cosine of a number.- Parameters:
x
- number on which evaluation is done- Returns:
- hyperbolic cosine of x
-
sinh
public static double sinh(double x) Compute the hyperbolic sine of a number.- Parameters:
x
- number on which evaluation is done- Returns:
- hyperbolic sine of x
-
sinhCosh
Combined hyperbolic sine and hyperbolic cosine function.- Parameters:
x
- Argument.- Returns:
- [sinh(x), cosh(x)]
-
sinhCosh
Combined hyperbolic sine and hyperbolic cosine function.- Type Parameters:
T
- the type of the field element- Parameters:
x
- Argument.- Returns:
- [sinh(x), cosh(x)]
-
tanh
public static double tanh(double x) Compute the hyperbolic tangent of a number.- Parameters:
x
- number on which evaluation is done- Returns:
- hyperbolic tangent of x
-
acosh
public static double acosh(double a) Compute the inverse hyperbolic cosine of a number.- Parameters:
a
- number on which evaluation is done- Returns:
- inverse hyperbolic cosine of a
-
asinh
public static double asinh(double a) Compute the inverse hyperbolic sine of a number.- Parameters:
a
- number on which evaluation is done- Returns:
- inverse hyperbolic sine of a
-
atanh
public static double atanh(double a) Compute the inverse hyperbolic tangent of a number.- Parameters:
a
- number on which evaluation is done- Returns:
- inverse hyperbolic tangent of a
-
signum
public static double signum(double a) Compute the signum of a number. The signum is -1 for negative numbers, +1 for positive numbers and 0 otherwise- Parameters:
a
- number on which evaluation is done- Returns:
- -1.0, -0.0, +0.0, +1.0 or NaN depending on sign of a
-
signum
public static float signum(float a) Compute the signum of a number. The signum is -1 for negative numbers, +1 for positive numbers and 0 otherwise- Parameters:
a
- number on which evaluation is done- Returns:
- -1.0, -0.0, +0.0, +1.0 or NaN depending on sign of a
-
nextUp
public static double nextUp(double a) Compute next number towards positive infinity.- Parameters:
a
- number to which neighbor should be computed- Returns:
- neighbor of a towards positive infinity
-
nextUp
public static float nextUp(float a) Compute next number towards positive infinity.- Parameters:
a
- number to which neighbor should be computed- Returns:
- neighbor of a towards positive infinity
-
nextDown
public static double nextDown(double a) Compute next number towards negative infinity.- Parameters:
a
- number to which neighbor should be computed- Returns:
- neighbor of a towards negative infinity
-
nextDown
public static float nextDown(float a) Compute next number towards negative infinity.- Parameters:
a
- number to which neighbor should be computed- Returns:
- neighbor of a towards negative infinity
-
clamp
public static int clamp(int value, int inf, int sup) Clamp a value within an interval.- Parameters:
value
- value to clampinf
- lower bound of the clamping intervalsup
- upper bound of the clamping interval- Returns:
- value clamped within [inf; sup], or value if already within bounds.
- Since:
- 3.0
-
clamp
public static long clamp(long value, long inf, long sup) Clamp a value within an interval.- Parameters:
value
- value to clampinf
- lower bound of the clamping intervalsup
- upper bound of the clamping interval- Returns:
- value clamped within [inf; sup], or value if already within bounds.
- Since:
- 3.0
-
clamp
public static int clamp(long value, int inf, int sup) Clamp a value within an interval.- Parameters:
value
- value to clampinf
- lower bound of the clamping intervalsup
- upper bound of the clamping interval- Returns:
- value clamped within [inf; sup], or value if already within bounds.
- Since:
- 3.0
-
clamp
public static float clamp(float value, float inf, float sup) Clamp a value within an interval.This method assumes -0.0 is below +0.0
- Parameters:
value
- value to clampinf
- lower bound of the clamping intervalsup
- upper bound of the clamping interval- Returns:
- value clamped within [inf; sup], or value if already within bounds.
- Since:
- 3.0
-
clamp
public static double clamp(double value, double inf, double sup) Clamp a value within an interval.This method assumes -0.0 is below +0.0
- Parameters:
value
- value to clampinf
- lower bound of the clamping intervalsup
- upper bound of the clamping interval- Returns:
- value clamped within [inf; sup], or value if already within bounds.
- Since:
- 3.0
-
random
public static double random()Returns a pseudo-random number between 0.0 and 1.0.Note: this implementation currently delegates to
Math.random()
- Returns:
- a random number between 0.0 and 1.0
-
exp
public static double exp(double x) Exponential function. Computes exp(x), function result is nearly rounded. It will be correctly rounded to the theoretical value for 99.9% of input values, otherwise it will have a 1 ULP error. Method: Lookup intVal = exp(int(x)) Lookup fracVal = exp(int(x-int(x) / 1024.0) * 1024.0 ); Compute z as the exponential of the remaining bits by a polynomial minus one exp(x) = intVal * fracVal * (1 + z) Accuracy: Calculation is done with 63 bits of precision, so result should be correctly rounded for 99.9% of input values, with less than 1 ULP error otherwise.- Parameters:
x
- a double- Returns:
- double ex
-
expm1
public static double expm1(double x) Compute exp(x) - 1- Parameters:
x
- number to compute shifted exponential- Returns:
- exp(x) - 1
-
log
public static double log(double x) Natural logarithm.- Parameters:
x
- a double- Returns:
- log(x)
-
log1p
public static double log1p(double x) Computes log(1 + x).- Parameters:
x
- Number.- Returns:
log(1 + x)
.
-
log10
public static double log10(double x) Compute the base 10 logarithm.- Parameters:
x
- a number- Returns:
- log10(x)
-
log
public static double log(double base, double x) Computes the logarithm in a given base. ReturnsNaN
if either argument is negative. Ifbase
is 0 andx
is positive, 0 is returned. Ifbase
is positive andx
is 0,Double.NEGATIVE_INFINITY
is returned. If both arguments are 0, the result isNaN
.- Parameters:
base
- Base of the logarithm, must be greater than 0.x
- Argument, must be greater than 0.- Returns:
- the value of the logarithm, i.e. the number
y
such thatbasey = x
.
-
pow
public static double pow(double x, double y) Power function. Compute x^y.- Parameters:
x
- a doubley
- a double- Returns:
- double
-
pow
public static double pow(double d, int e) Raise a double to an int power.- Parameters:
d
- Number to raise.e
- Exponent.- Returns:
- de
-
pow
public static double pow(double d, long e) Raise a double to a long power.- Parameters:
d
- Number to raise.e
- Exponent.- Returns:
- de
-
sin
public static double sin(double x) Sine function.- Parameters:
x
- Argument.- Returns:
- sin(x)
-
cos
public static double cos(double x) Cosine function.- Parameters:
x
- Argument.- Returns:
- cos(x)
-
sinCos
Combined Sine and Cosine function.- Parameters:
x
- Argument.- Returns:
- [sin(x), cos(x)]
-
sinCos
Combined Sine and Cosine function.- Type Parameters:
T
- the type of the field element- Parameters:
x
- Argument.- Returns:
- [sin(x), cos(x)]
- Since:
- 1.4
-
tan
public static double tan(double x) Tangent function.- Parameters:
x
- Argument.- Returns:
- tan(x)
-
atan
public static double atan(double x) Arctangent function- Parameters:
x
- a number- Returns:
- atan(x)
-
atan2
public static double atan2(double y, double x) Two arguments arctangent function- Parameters:
y
- ordinatex
- abscissa- Returns:
- phase angle of point (x,y) between
-PI
andPI
-
asin
public static double asin(double x) Compute the arc sine of a number.- Parameters:
x
- number on which evaluation is done- Returns:
- arc sine of x
-
acos
public static double acos(double x) Compute the arc cosine of a number.- Parameters:
x
- number on which evaluation is done- Returns:
- arc cosine of x
-
cbrt
public static double cbrt(double x) Compute the cubic root of a number.- Parameters:
x
- number on which evaluation is done- Returns:
- cubic root of x
-
toRadians
public static double toRadians(double x) Convert degrees to radians, with error of less than 0.5 ULP- Parameters:
x
- angle in degrees- Returns:
- x converted into radians
-
toDegrees
public static double toDegrees(double x) Convert radians to degrees, with error of less than 0.5 ULP- Parameters:
x
- angle in radians- Returns:
- x converted into degrees
-
abs
public static int abs(int x) Absolute value.- Parameters:
x
- number from which absolute value is requested- Returns:
- abs(x)
-
abs
public static long abs(long x) Absolute value.- Parameters:
x
- number from which absolute value is requested- Returns:
- abs(x)
-
absExact
public static int absExact(int x) Absolute value.- Parameters:
x
- number from which absolute value is requested- Returns:
- abs(x), or throws an exception for
Integer.MIN_VALUE
- Since:
- 2.0
-
absExact
public static long absExact(long x) Absolute value.- Parameters:
x
- number from which absolute value is requested- Returns:
- abs(x), or throws an exception for
Long.MIN_VALUE
- Since:
- 2.0
-
abs
public static float abs(float x) Absolute value.- Parameters:
x
- number from which absolute value is requested- Returns:
- abs(x)
- Since:
- 2.0
-
abs
public static double abs(double x) Absolute value.- Parameters:
x
- number from which absolute value is requested- Returns:
- abs(x)
-
negateExact
public static int negateExact(int x) Negates the argument.- Parameters:
x
- number from which opposite value is requested- Returns:
- -x, or throws an exception for
Integer.MIN_VALUE
- Since:
- 2.0
-
negateExact
public static long negateExact(long x) Negates the argument.- Parameters:
x
- number from which opposite value is requested- Returns:
- -x, or throws an exception for
Long.MIN_VALUE
- Since:
- 2.0
-
ulp
public static double ulp(double x) Compute least significant bit (Unit in Last Position) for a number.- Parameters:
x
- number from which ulp is requested- Returns:
- ulp(x)
-
ulp
public static float ulp(float x) Compute least significant bit (Unit in Last Position) for a number.- Parameters:
x
- number from which ulp is requested- Returns:
- ulp(x)
-
scalb
public static double scalb(double d, int n) Multiply a double number by a power of 2.- Parameters:
d
- number to multiplyn
- power of 2- Returns:
- d × 2n
-
scalb
public static float scalb(float f, int n) Multiply a float number by a power of 2.- Parameters:
f
- number to multiplyn
- power of 2- Returns:
- f × 2n
-
nextAfter
public static double nextAfter(double d, double direction) Get the next machine representable number after a number, moving in the direction of another number.The ordering is as follows (increasing):
- -INFINITY
- -MAX_VALUE
- -MIN_VALUE
- -0.0
- +0.0
- +MIN_VALUE
- +MAX_VALUE
- +INFINITY
If arguments compare equal, then the second argument is returned.
If
direction
is greater thand
, the smallest machine representable number strictly greater thand
is returned; if less, then the largest representable number strictly less thand
is returned.If
d
is infinite and direction does not bring it back to finite numbers, it is returned unchanged.- Parameters:
d
- base numberdirection
- (the only important thing is whetherdirection
is greater or smaller thand
)- Returns:
- the next machine representable number in the specified direction
-
nextAfter
public static float nextAfter(float f, double direction) Get the next machine representable number after a number, moving in the direction of another number.* The ordering is as follows (increasing):
- -INFINITY
- -MAX_VALUE
- -MIN_VALUE
- -0.0
- +0.0
- +MIN_VALUE
- +MAX_VALUE
- +INFINITY
If arguments compare equal, then the second argument is returned.
If
direction
is greater thanf
, the smallest machine representable number strictly greater thanf
is returned; if less, then the largest representable number strictly less thanf
is returned.If
f
is infinite and direction does not bring it back to finite numbers, it is returned unchanged.- Parameters:
f
- base numberdirection
- (the only important thing is whetherdirection
is greater or smaller thanf
)- Returns:
- the next machine representable number in the specified direction
-
floor
public static double floor(double x) Get the largest whole number smaller than x.- Parameters:
x
- number from which floor is requested- Returns:
- a double number f such that f is an integer f <= x < f + 1.0
-
ceil
public static double ceil(double x) Get the smallest whole number larger than x.- Parameters:
x
- number from which ceil is requested- Returns:
- a double number c such that c is an integer c - 1.0 < x <= c
-
rint
public static double rint(double x) Get the whole number that is the nearest to x, or the even one if x is exactly half way between two integers.- Parameters:
x
- number from which nearest whole number is requested- Returns:
- a double number r such that r is an integer r - 0.5 <= x <= r + 0.5
-
round
public static long round(double x) Get the closest long to x.- Parameters:
x
- number from which closest long is requested- Returns:
- closest long to x
-
round
public static int round(float x) Get the closest int to x.- Parameters:
x
- number from which closest int is requested- Returns:
- closest int to x
-
min
public static int min(int a, int b) Compute the minimum of two values- Parameters:
a
- first valueb
- second value- Returns:
- a if a is lesser or equal to b, b otherwise
-
min
public static long min(long a, long b) Compute the minimum of two values- Parameters:
a
- first valueb
- second value- Returns:
- a if a is lesser or equal to b, b otherwise
-
min
public static float min(float a, float b) Compute the minimum of two values- Parameters:
a
- first valueb
- second value- Returns:
- a if a is lesser or equal to b, b otherwise
-
min
public static double min(double a, double b) Compute the minimum of two values- Parameters:
a
- first valueb
- second value- Returns:
- a if a is lesser or equal to b, b otherwise
-
max
public static int max(int a, int b) Compute the maximum of two values- Parameters:
a
- first valueb
- second value- Returns:
- b if a is lesser or equal to b, a otherwise
-
max
public static long max(long a, long b) Compute the maximum of two values- Parameters:
a
- first valueb
- second value- Returns:
- b if a is lesser or equal to b, a otherwise
-
max
public static float max(float a, float b) Compute the maximum of two values- Parameters:
a
- first valueb
- second value- Returns:
- b if a is lesser or equal to b, a otherwise
-
max
public static double max(double a, double b) Compute the maximum of two values- Parameters:
a
- first valueb
- second value- Returns:
- b if a is lesser or equal to b, a otherwise
-
hypot
public static double hypot(double x, double y) Returns the hypotenuse of a triangle with sidesx
andy
- sqrt(x2 +y2)
avoiding intermediate overflow or underflow.- If either argument is infinite, then the result is positive infinity.
- else, if either argument is NaN then the result is NaN.
- Parameters:
x
- a valuey
- a value- Returns:
- sqrt(x2 +y2)
-
IEEEremainder
public static double IEEEremainder(double dividend, double divisor) Computes the remainder as prescribed by the IEEE 754 standard.The remainder value is mathematically equal to
x - y*n
wheren
is the mathematical integer closest to the exact mathematical value of the quotientx/y
. If two mathematical integers are equally close tox/y
thenn
is the integer that is even.- If either operand is NaN, the result is NaN.
- If the result is not NaN, the sign of the result equals the sign of the dividend.
- If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
- If the dividend is finite and the divisor is an infinity, the result equals the dividend.
- If the dividend is a zero and the divisor is finite, the result equals the dividend.
- Parameters:
dividend
- the number to be divideddivisor
- the number by which to divide- Returns:
- the remainder, rounded
-
toIntExact
Convert a long to interger, detecting overflows- Parameters:
n
- number to convert to int- Returns:
- integer with same valie as n if no overflows occur
- Throws:
MathRuntimeException
- if n cannot fit into an int
-
incrementExact
Increment a number, detecting overflows.- Parameters:
n
- number to increment- Returns:
- n+1 if no overflows occur
- Throws:
MathRuntimeException
- if an overflow occurs
-
incrementExact
Increment a number, detecting overflows.- Parameters:
n
- number to increment- Returns:
- n+1 if no overflows occur
- Throws:
MathRuntimeException
- if an overflow occurs
-
decrementExact
Decrement a number, detecting overflows.- Parameters:
n
- number to decrement- Returns:
- n-1 if no overflows occur
- Throws:
MathRuntimeException
- if an overflow occurs
-
decrementExact
Decrement a number, detecting overflows.- Parameters:
n
- number to decrement- Returns:
- n-1 if no overflows occur
- Throws:
MathRuntimeException
- if an overflow occurs
-
addExact
Add two numbers, detecting overflows.- Parameters:
a
- first number to addb
- second number to add- Returns:
- a+b if no overflows occur
- Throws:
MathRuntimeException
- if an overflow occurs
-
addExact
Add two numbers, detecting overflows.- Parameters:
a
- first number to addb
- second number to add- Returns:
- a+b if no overflows occur
- Throws:
MathRuntimeException
- if an overflow occurs
-
subtractExact
public static int subtractExact(int a, int b) Subtract two numbers, detecting overflows.- Parameters:
a
- first numberb
- second number to subtract from a- Returns:
- a-b if no overflows occur
- Throws:
MathRuntimeException
- if an overflow occurs
-
subtractExact
public static long subtractExact(long a, long b) Subtract two numbers, detecting overflows.- Parameters:
a
- first numberb
- second number to subtract from a- Returns:
- a-b if no overflows occur
- Throws:
MathRuntimeException
- if an overflow occurs
-
multiplyExact
public static int multiplyExact(int a, int b) Multiply two numbers, detecting overflows.- Parameters:
a
- first number to multiplyb
- second number to multiply- Returns:
- a*b if no overflows occur
- Throws:
MathRuntimeException
- if an overflow occurs
-
multiplyExact
public static long multiplyExact(long a, int b) Multiply two numbers, detecting overflows.- Parameters:
a
- first number to multiplyb
- second number to multiply- Returns:
- a*b if no overflows occur
- Throws:
MathRuntimeException
- if an overflow occurs- Since:
- 1.3
-
multiplyExact
public static long multiplyExact(long a, long b) Multiply two numbers, detecting overflows.- Parameters:
a
- first number to multiplyb
- second number to multiply- Returns:
- a*b if no overflows occur
- Throws:
MathRuntimeException
- if an overflow occurs
-
multiplyFull
public static long multiplyFull(int a, int b) Multiply two integers and give an exact result without overflow.- Parameters:
a
- first factorb
- second factor- Returns:
- a * b exactly
- Since:
- 1.3
-
multiplyHigh
public static long multiplyHigh(long a, long b) Multiply two long integers and give the 64 most significant bits of the result.Beware that as Java primitive long are always considered to be signed, there are some intermediate values
a
andb
for whicha * b
exceedsLong.MAX_VALUE
but this method will still return 0l. This happens for example fora = 2³¹
andb = 2³²
asa * b = 2⁶³ = Long.MAX_VALUE + 1
, so it exceeds the max value for a long, but still fits in 64 bits, so this method correctly returns 0l in this case, but multiplication result would be considered negative (and in fact equal toLong.MIN_VALUE
- Parameters:
a
- first factorb
- second factor- Returns:
- a * b / 264
- Since:
- 1.3
-
unsignedMultiplyHigh
public static long unsignedMultiplyHigh(long a, long b) Multiply two long unsigned integers and give the 64 most significant bits of the unsigned result.Beware that as Java primitive long are always considered to be signed, there are some intermediate values
a
andb
for whicha * b
exceedsLong.MAX_VALUE
but this method will still return 0l. This happens for example fora = 2³¹
andb = 2³²
asa * b = 2⁶³ = Long.MAX_VALUE + 1
, so it exceeds the max value for a long, but still fits in 64 bits, so this method correctly returns 0l in this case, but multiplication result would be considered negative (and in fact equal toLong.MIN_VALUE
- Parameters:
a
- first factorb
- second factor- Returns:
- a * b / 264
- Since:
- 3.0
-
divideExact
public static int divideExact(int x, int y) Divide two integers, checking for overflow.- Parameters:
x
- dividendy
- divisor- Returns:
- x / y
- Throws:
MathRuntimeException
- if an overflow occurs- Since:
- 3.0
-
divideExact
public static long divideExact(long x, long y) Divide two long integers, checking for overflow.- Parameters:
x
- dividendy
- divisor- Returns:
- x / y
- Throws:
MathRuntimeException
- if an overflow occurs- Since:
- 3.0
-
ceilDiv
Finds q such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.This methods returns the same value as integer division when a and b are opposite signs, but returns a different value when they are same (i.e. q is positive).
- Parameters:
a
- dividendb
- divisor- Returns:
- q such that
a = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
- Throws:
MathRuntimeException
- if b == 0- Since:
- 3.0
-
ceilDivExact
Finds q such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.This methods returns the same value as integer division when a and b are opposite signs, but returns a different value when they are same (i.e. q is positive).
- Parameters:
a
- dividendb
- divisor- Returns:
- q such that
a = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
- Throws:
MathRuntimeException
- if b == 0 or if a ==Integer.MIN_VALUE
and b = -1- Since:
- 3.0
-
ceilDiv
Finds q such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.This methods returns the same value as integer division when a and b are opposite signs, but returns a different value when they are same (i.e. q is positive).
- Parameters:
a
- dividendb
- divisor- Returns:
- q such that
a = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
- Throws:
MathRuntimeException
- if b == 0- Since:
- 3.0
-
ceilDivExact
Finds q such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.This methods returns the same value as integer division when a and b are opposite signs, but returns a different value when they are same (i.e. q is positive).
- Parameters:
a
- dividendb
- divisor- Returns:
- q such that
a = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
- Throws:
MathRuntimeException
- if b == 0 or if a ==Long.MIN_VALUE
and b = -1- Since:
- 3.0
-
ceilDiv
Finds q such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.This methods returns the same value as integer division when a and b are opposite signs, but returns a different value when they are same (i.e. q is positive).
- Parameters:
a
- dividendb
- divisor- Returns:
- q such that
a = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
- Throws:
MathRuntimeException
- if b == 0- Since:
- 3.0
-
ceilMod
Finds r such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.This methods returns the same value as integer modulo when a and b are opposite signs, but returns a different value when they are same (i.e. q is positive).
- Parameters:
a
- dividendb
- divisor- Returns:
- r such that
a = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
- Throws:
MathRuntimeException
- if b == 0- Since:
- 3.0
-
ceilMod
Finds r such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.This methods returns the same value as integer modulo when a and b are opposite signs, but returns a different value when they are same (i.e. q is positive).
- Parameters:
a
- dividendb
- divisor- Returns:
- r such that
a = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
- Throws:
MathRuntimeException
- if b == 0- Since:
- 3.0
-
ceilMod
Finds r such thata = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
.This methods returns the same value as integer modulo when a and b are opposite signs, but returns a different value when they are same (i.e. q is positive).
- Parameters:
a
- dividendb
- divisor- Returns:
- r such that
a = q b + r
withb < r <= 0
ifb > 0
and0 <= r < b
ifb < 0
- Throws:
MathRuntimeException
- if b == 0- Since:
- 3.0
-
floorDiv
Finds q such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.This methods returns the same value as integer division when a and b are same signs, but returns a different value when they are opposite (i.e. q is negative).
- Parameters:
a
- dividendb
- divisor- Returns:
- q such that
a = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
- Throws:
MathRuntimeException
- if b == 0- See Also:
-
floorDivExact
Finds q such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.This methods returns the same value as integer division when a and b are same signs, but returns a different value when they are opposite (i.e. q is negative).
- Parameters:
a
- dividendb
- divisor- Returns:
- q such that
a = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
- Throws:
MathRuntimeException
- if b == 0 or if a ==Integer.MIN_VALUE
and b = -1- Since:
- 3.0
- See Also:
-
floorDiv
Finds q such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.This methods returns the same value as integer division when a and b are same signs, but returns a different value when they are opposite (i.e. q is negative).
- Parameters:
a
- dividendb
- divisor- Returns:
- q such that
a = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
- Throws:
MathRuntimeException
- if b == 0- Since:
- 1.3
- See Also:
-
floorDiv
Finds q such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.This methods returns the same value as integer division when a and b are same signs, but returns a different value when they are opposite (i.e. q is negative).
- Parameters:
a
- dividendb
- divisor- Returns:
- q such that
a = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
- Throws:
MathRuntimeException
- if b == 0- See Also:
-
floorDivExact
Finds q such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.This methods returns the same value as integer division when a and b are same signs, but returns a different value when they are opposite (i.e. q is negative).
- Parameters:
a
- dividendb
- divisor- Returns:
- q such that
a = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
- Throws:
MathRuntimeException
- if b == 0 or if a ==Long.MIN_VALUE
and b = -1- Since:
- 3.0
- See Also:
-
floorMod
Finds r such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.This methods returns the same value as integer modulo when a and b are same signs, but returns a different value when they are opposite (i.e. q is negative).
- Parameters:
a
- dividendb
- divisor- Returns:
- r such that
a = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
- Throws:
MathRuntimeException
- if b == 0- See Also:
-
floorMod
public static int floorMod(long a, int b) Finds r such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.This methods returns the same value as integer modulo when a and b are same signs, but returns a different value when they are opposite (i.e. q is negative).
- Parameters:
a
- dividendb
- divisor- Returns:
- r such that
a = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
- Throws:
MathRuntimeException
- if b == 0- Since:
- 1.3
- See Also:
-
floorMod
public static long floorMod(long a, long b) Finds r such thata = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
.This methods returns the same value as integer modulo when a and b are same signs, but returns a different value when they are opposite (i.e. q is negative).
- Parameters:
a
- dividendb
- divisor- Returns:
- r such that
a = q b + r
with0 <= r < b
ifb > 0
andb < r <= 0
ifb < 0
- Throws:
MathRuntimeException
- if b == 0- See Also:
-
copySign
public static double copySign(double magnitude, double sign) Returns the first argument with the sign of the second argument. A NaNsign
argument is treated as positive.- Parameters:
magnitude
- the value to returnsign
- the sign for the returned value- Returns:
- the magnitude with the same sign as the
sign
argument
-
copySign
public static float copySign(float magnitude, float sign) Returns the first argument with the sign of the second argument. A NaNsign
argument is treated as positive.- Parameters:
magnitude
- the value to returnsign
- the sign for the returned value- Returns:
- the magnitude with the same sign as the
sign
argument
-
getExponent
public static int getExponent(double d) Return the exponent of a double number, removing the bias.For double numbers of the form 2x, the unbiased exponent is exactly x.
- Parameters:
d
- number from which exponent is requested- Returns:
- exponent for d in IEEE754 representation, without bias
-
getExponent
public static int getExponent(float f) Return the exponent of a float number, removing the bias.For float numbers of the form 2x, the unbiased exponent is exactly x.
- Parameters:
f
- number from which exponent is requested- Returns:
- exponent for d in IEEE754 representation, without bias
-
fma
public static double fma(double a, double b, double c) Compute Fused-multiply-add operation a * b + c.This method was introduced in the regular
Math
andStrictMath
methods with Java 9, and then added to Hipparchus for consistency. However, a more general method was available in Hipparchus that also allow to repeat this computation across several terms:MathArrays.linearCombination(double[], double[])
. The linear combination method should probably be preferred in most cases.- Parameters:
a
- first factorb
- second factorc
- additive term- Returns:
- a * b + c, using extended precision in the multiplication
- Since:
- 1.3
- See Also:
-
fma
public static float fma(float a, float b, float c) Compute Fused-multiply-add operation a * b + c.This method was introduced in the regular
Math
andStrictMath
methods with Java 9, and then added to Hipparchus for consistency. However, a more general method was available in Hipparchus that also allow to repeat this computation across several terms:MathArrays.linearCombination(double[], double[])
. The linear combination method should probably be preferred in most cases.- Parameters:
a
- first factorb
- second factorc
- additive term- Returns:
- a * b + c, using extended precision in the multiplication
- See Also:
-
sqrt
Compute the square root of a number.- Type Parameters:
T
- the type of the field element- Parameters:
a
- number on which evaluation is done- Returns:
- square root of a
- Since:
- 1.3
-
cosh
Compute the hyperbolic cosine of a number.- Type Parameters:
T
- the type of the field element- Parameters:
x
- number on which evaluation is done- Returns:
- hyperbolic cosine of x
- Since:
- 1.3
-
sinh
Compute the hyperbolic sine of a number.- Type Parameters:
T
- the type of the field element- Parameters:
x
- number on which evaluation is done- Returns:
- hyperbolic sine of x
- Since:
- 1.3
-
tanh
Compute the hyperbolic tangent of a number.- Type Parameters:
T
- the type of the field element- Parameters:
x
- number on which evaluation is done- Returns:
- hyperbolic tangent of x
- Since:
- 1.3
-
acosh
Compute the inverse hyperbolic cosine of a number.- Type Parameters:
T
- the type of the field element- Parameters:
a
- number on which evaluation is done- Returns:
- inverse hyperbolic cosine of a
- Since:
- 1.3
-
asinh
Compute the inverse hyperbolic sine of a number.- Type Parameters:
T
- the type of the field element- Parameters:
a
- number on which evaluation is done- Returns:
- inverse hyperbolic sine of a
- Since:
- 1.3
-
atanh
Compute the inverse hyperbolic tangent of a number.- Type Parameters:
T
- the type of the field element- Parameters:
a
- number on which evaluation is done- Returns:
- inverse hyperbolic tangent of a
- Since:
- 1.3
-
sign
Compute the sign of a number. The sign is -1 for negative numbers, +1 for positive numbers and 0 otherwise, for Complex number, it is extended on the unit circle (equivalent to z/|z|, with special handling for 0 and NaN)- Type Parameters:
T
- the type of the field element- Parameters:
a
- number on which evaluation is done- Returns:
- -1.0, -0.0, +0.0, +1.0 or NaN depending on sign of a
- Since:
- 2.0
-
exp
Exponential function. Computes exp(x), function result is nearly rounded. It will be correctly rounded to the theoretical value for 99.9% of input values, otherwise it will have a 1 ULP error. Method: Lookup intVal = exp(int(x)) Lookup fracVal = exp(int(x-int(x) / 1024.0) * 1024.0 ); Compute z as the exponential of the remaining bits by a polynomial minus one exp(x) = intVal * fracVal * (1 + z) Accuracy: Calculation is done with 63 bits of precision, so result should be correctly rounded for 99.9% of input values, with less than 1 ULP error otherwise.- Type Parameters:
T
- the type of the field element- Parameters:
x
- a double- Returns:
- double ex
- Since:
- 1.3
-
expm1
Compute exp(x) - 1- Type Parameters:
T
- the type of the field element- Parameters:
x
- number to compute shifted exponential- Returns:
- exp(x) - 1
- Since:
- 1.3
-
log
Natural logarithm.- Type Parameters:
T
- the type of the field element- Parameters:
x
- a double- Returns:
- log(x)
- Since:
- 1.3
-
log1p
Computes log(1 + x).- Type Parameters:
T
- the type of the field element- Parameters:
x
- Number.- Returns:
log(1 + x)
.- Since:
- 1.3
-
log10
Compute the base 10 logarithm.- Type Parameters:
T
- the type of the field element- Parameters:
x
- a number- Returns:
- log10(x)
- Since:
- 1.3
-
pow
Power function. Compute xy.- Type Parameters:
T
- the type of the field element- Parameters:
x
- a doubley
- a double- Returns:
- xy
- Since:
- 1.3
-
pow
Power function. Compute xy.- Type Parameters:
T
- the type of the field element- Parameters:
x
- a doubley
- a double- Returns:
- xy
- Since:
- 1.7
-
pow
Raise a double to an int power.- Type Parameters:
T
- the type of the field element- Parameters:
d
- Number to raise.e
- Exponent.- Returns:
- de
- Since:
- 1.3
-
sin
Sine function.- Type Parameters:
T
- the type of the field element- Parameters:
x
- Argument.- Returns:
- sin(x)
- Since:
- 1.3
-
cos
Cosine function.- Type Parameters:
T
- the type of the field element- Parameters:
x
- Argument.- Returns:
- cos(x)
- Since:
- 1.3
-
tan
Tangent function.- Type Parameters:
T
- the type of the field element- Parameters:
x
- Argument.- Returns:
- tan(x)
- Since:
- 1.3
-
atan
Arctangent function- Type Parameters:
T
- the type of the field element- Parameters:
x
- a number- Returns:
- atan(x)
- Since:
- 1.3
-
atan2
Two arguments arctangent function- Type Parameters:
T
- the type of the field element- Parameters:
y
- ordinatex
- abscissa- Returns:
- phase angle of point (x,y) between
-PI
andPI
- Since:
- 1.3
-
asin
Compute the arc sine of a number.- Type Parameters:
T
- the type of the field element- Parameters:
x
- number on which evaluation is done- Returns:
- arc sine of x
- Since:
- 1.3
-
acos
Compute the arc cosine of a number.- Type Parameters:
T
- the type of the field element- Parameters:
x
- number on which evaluation is done- Returns:
- arc cosine of x
- Since:
- 1.3
-
cbrt
Compute the cubic root of a number.- Type Parameters:
T
- the type of the field element- Parameters:
x
- number on which evaluation is done- Returns:
- cubic root of x
- Since:
- 1.3
-
norm
Norm.- Type Parameters:
T
- the type of the field element- Parameters:
x
- number from which norm is requested- Returns:
- norm(x)
- Since:
- 2.0
-
abs
Absolute value.- Type Parameters:
T
- the type of the field element- Parameters:
x
- number from which absolute value is requested- Returns:
- abs(x)
- Since:
- 2.0
-
toRadians
Convert degrees to radians, with error of less than 0.5 ULP- Type Parameters:
T
- the type of the field element- Parameters:
x
- angle in degrees- Returns:
- x converted into radians
-
toDegrees
Convert radians to degrees, with error of less than 0.5 ULP- Type Parameters:
T
- the type of the field element- Parameters:
x
- angle in radians- Returns:
- x converted into degrees
-
scalb
Multiply a double number by a power of 2.- Type Parameters:
T
- the type of the field element- Parameters:
d
- number to multiplyn
- power of 2- Returns:
- d × 2n
- Since:
- 1.3
-
ulp
Compute least significant bit (Unit in Last Position) for a number.- Type Parameters:
T
- the type of the field element- Parameters:
x
- number from which ulp is requested- Returns:
- ulp(x)
- Since:
- 2.0
-
floor
Get the largest whole number smaller than x.- Type Parameters:
T
- the type of the field element- Parameters:
x
- number from which floor is requested- Returns:
- a double number f such that f is an integer f <= x < f + 1.0
- Since:
- 1.3
-
ceil
Get the smallest whole number larger than x.- Type Parameters:
T
- the type of the field element- Parameters:
x
- number from which ceil is requested- Returns:
- a double number c such that c is an integer c - 1.0 < x <= c
- Since:
- 1.3
-
rint
Get the whole number that is the nearest to x, or the even one if x is exactly half way between two integers.- Type Parameters:
T
- the type of the field element- Parameters:
x
- number from which nearest whole number is requested- Returns:
- a double number r such that r is an integer r - 0.5 <= x <= r + 0.5
- Since:
- 1.3
-
round
Get the closest long to x.- Type Parameters:
T
- the type of the field element- Parameters:
x
- number from which closest long is requested- Returns:
- closest long to x
- Since:
- 1.3
-
min
Compute the minimum of two values- Type Parameters:
T
- the type of the field element- Parameters:
a
- first valueb
- second value- Returns:
- a if a is lesser or equal to b, b otherwise
- Since:
- 1.3
-
min
Compute the minimum of two values- Type Parameters:
T
- the type of the field element- Parameters:
a
- first valueb
- second value- Returns:
- a if a is lesser or equal to b, b otherwise
- Since:
- 1.3
-
max
Compute the maximum of two values- Type Parameters:
T
- the type of the field element- Parameters:
a
- first valueb
- second value- Returns:
- b if a is lesser or equal to b, a otherwise
- Since:
- 1.3
-
max
Compute the maximum of two values- Type Parameters:
T
- the type of the field element- Parameters:
a
- first valueb
- second value- Returns:
- b if a is lesser or equal to b, a otherwise
- Since:
- 1.3
-
hypot
Returns the hypotenuse of a triangle with sidesx
andy
- sqrt(x2 +y2)
avoiding intermediate overflow or underflow.- If either argument is infinite, then the result is positive infinity.
- else, if either argument is NaN then the result is NaN.
- Type Parameters:
T
- the type of the field element- Parameters:
x
- a valuey
- a value- Returns:
- sqrt(x2 +y2)
- Since:
- 1.3
-
IEEEremainder
Computes the remainder as prescribed by the IEEE 754 standard.The remainder value is mathematically equal to
x - y*n
wheren
is the mathematical integer closest to the exact mathematical value of the quotientx/y
. If two mathematical integers are equally close tox/y
thenn
is the integer that is even.- If either operand is NaN, the result is NaN.
- If the result is not NaN, the sign of the result equals the sign of the dividend.
- If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
- If the dividend is finite and the divisor is an infinity, the result equals the dividend.
- If the dividend is a zero and the divisor is finite, the result equals the dividend.
- Type Parameters:
T
- the type of the field element- Parameters:
dividend
- the number to be divideddivisor
- the number by which to divide- Returns:
- the remainder, rounded
- Since:
- 1.3
-
IEEEremainder
Computes the remainder as prescribed by the IEEE 754 standard.The remainder value is mathematically equal to
x - y*n
wheren
is the mathematical integer closest to the exact mathematical value of the quotientx/y
. If two mathematical integers are equally close tox/y
thenn
is the integer that is even.- If either operand is NaN, the result is NaN.
- If the result is not NaN, the sign of the result equals the sign of the dividend.
- If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
- If the dividend is finite and the divisor is an infinity, the result equals the dividend.
- If the dividend is a zero and the divisor is finite, the result equals the dividend.
- Type Parameters:
T
- the type of the field element- Parameters:
dividend
- the number to be divideddivisor
- the number by which to divide- Returns:
- the remainder, rounded
- Since:
- 1.3
-
copySign
Returns the first argument with the sign of the second argument. A NaNsign
argument is treated as positive.- Type Parameters:
T
- the type of the field element- Parameters:
magnitude
- the value to returnsign
- the sign for the returned value- Returns:
- the magnitude with the same sign as the
sign
argument - Since:
- 1.3
-
copySign
Returns the first argument with the sign of the second argument. A NaNsign
argument is treated as positive.- Type Parameters:
T
- the type of the field element- Parameters:
magnitude
- the value to returnsign
- the sign for the returned value- Returns:
- the magnitude with the same sign as the
sign
argument - Since:
- 1.3
-