public class FastMath extends Object
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 machinesModifier and Type | Field and Description |
---|---|
static double |
E
Napier's constant e, base of the natural logarithm.
|
static double |
PI
Archimede's constant PI, ratio of circle circumference to diameter.
|
Modifier and Type | Method and Description |
---|---|
static 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>> |
abs(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>> |
acos(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>> |
acosh(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>> |
asin(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>> |
asinh(T a)
Compute the inverse hyperbolic sine of a number.
|
static double |
atan(double x)
Arctangent function
|
static <T extends CalculusFieldElement<T>> |
atan(T x)
Arctangent function
|
static double |
atan2(double y,
double x)
Two arguments arctangent function
|
static <T extends CalculusFieldElement<T>> |
atan2(T y,
T x)
Two arguments arctangent function
|
static double |
atanh(double a)
Compute the inverse hyperbolic tangent of a number.
|
static <T extends CalculusFieldElement<T>> |
atanh(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>> |
cbrt(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>> |
ceil(T x)
Get the smallest whole number larger than x.
|
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>> |
copySign(T magnitude,
double sign)
Returns the first argument with the sign of the second argument.
|
static <T extends CalculusFieldElement<T>> |
copySign(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>> |
cos(T x)
Cosine function.
|
static double |
cosh(double x)
Compute the hyperbolic cosine of a number.
|
static <T extends CalculusFieldElement<T>> |
cosh(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 double |
exp(double x)
Exponential function.
|
static <T extends CalculusFieldElement<T>> |
exp(T x)
Exponential function.
|
static double |
expm1(double x)
Compute exp(x) - 1
|
static <T extends CalculusFieldElement<T>> |
expm1(T x)
Compute exp(x) - 1
|
static double |
floor(double x)
Get the largest whole number smaller than x.
|
static <T extends CalculusFieldElement<T>> |
floor(T x)
Get the largest whole number smaller than x.
|
static int |
floorDiv(int a,
int b)
Finds q such that
a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0 . |
static long |
floorDiv(long a,
int b)
Finds q such that
a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0 . |
static long |
floorDiv(long a,
long b)
Finds q such that
a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0 . |
static int |
floorMod(int a,
int b)
Finds r such that
a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0 . |
static int |
floorMod(long a,
int b)
Finds r such that
a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 0 . |
static long |
floorMod(long a,
long b)
Finds r such that
a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b < 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 sides
x and y
- sqrt(x2 +y2)avoiding intermediate overflow or underflow. |
static <T extends CalculusFieldElement<T>> |
hypot(T x,
T y)
Returns the hypotenuse of a triangle with sides
x and y
- 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>> |
IEEEremainder(T dividend,
double divisor)
Computes the remainder as prescribed by the IEEE 754 standard.
|
static <T extends CalculusFieldElement<T>> |
IEEEremainder(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>> |
log(T x)
Natural logarithm.
|
static double |
log10(double x)
Compute the base 10 logarithm.
|
static <T extends CalculusFieldElement<T>> |
log10(T x)
Compute the base 10 logarithm.
|
static double |
log1p(double x)
Computes log(1 + x).
|
static <T extends CalculusFieldElement<T>> |
log1p(T x)
Computes log(1 + x).
|
static double |
max(double a,
double b)
Compute the maximum of two values
|
static float |
max(float a,
float b)
Compute the maximum of two values
|
static int |
max(int a,
int b)
Compute the maximum of two values
|
static long |
max(long a,
long b)
Compute the maximum of two values
|
static <T extends CalculusFieldElement<T>> |
max(T a,
double b)
Compute the maximum of two values
|
static <T extends CalculusFieldElement<T>> |
max(T a,
T b)
Compute the maximum of two values
|
static double |
min(double a,
double b)
Compute the minimum of two values
|
static float |
min(float a,
float b)
Compute the minimum of two values
|
static int |
min(int a,
int b)
Compute the minimum of two values
|
static long |
min(long a,
long b)
Compute the minimum of two values
|
static <T extends CalculusFieldElement<T>> |
min(T a,
double b)
Compute the minimum of two values
|
static <T extends CalculusFieldElement<T>> |
min(T a,
T b)
Compute the minimum of two values
|
static 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>> |
norm(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>> |
pow(T x,
double y)
Power function.
|
static <T extends CalculusFieldElement<T>> |
pow(T d,
int e)
Raise a double to an int power.
|
static <T extends CalculusFieldElement<T>> |
pow(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>> |
rint(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>> |
round(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>> |
scalb(T d,
int n)
Multiply a double number by a power of 2.
|
static <T extends CalculusFieldElement<T>> |
sign(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>> |
sin(T x)
Sine function.
|
static SinCos |
sinCos(double x)
Combined Sine and Cosine function.
|
static <T extends CalculusFieldElement<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>> |
sinh(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>> |
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>> |
sqrt(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>> |
tan(T x)
Tangent function.
|
static double |
tanh(double x)
Compute the hyperbolic tangent of a number.
|
static <T extends CalculusFieldElement<T>> |
tanh(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 ULP
|
static <T extends CalculusFieldElement<T>> |
toDegrees(T x)
Convert radians to degrees, with error of less than 0.5 ULP
|
static int |
toIntExact(long n)
Convert a long to interger, detecting overflows
|
static double |
toRadians(double x)
Convert degrees to radians, with error of less than 0.5 ULP
|
static <T extends CalculusFieldElement<T>> |
toRadians(T x)
Convert degrees to radians, with error of less than 0.5 ULP
|
static 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>> |
ulp(T x)
Compute least significant bit (Unit in Last Position) for a number.
|
public static final double PI
public static final double E
public static double sqrt(double a)
Note: this implementation currently delegates to Math.sqrt(double)
a
- number on which evaluation is donepublic static double cosh(double x)
x
- number on which evaluation is donepublic static double sinh(double x)
x
- number on which evaluation is donepublic static SinhCosh sinhCosh(double x)
x
- Argument.public static <T extends CalculusFieldElement<T>> FieldSinhCosh<T> sinhCosh(T x)
T
- the type of the field elementx
- Argument.public static double tanh(double x)
x
- number on which evaluation is donepublic static double acosh(double a)
a
- number on which evaluation is donepublic static double asinh(double a)
a
- number on which evaluation is donepublic static double atanh(double a)
a
- number on which evaluation is donepublic static double signum(double a)
a
- number on which evaluation is donepublic static float signum(float a)
a
- number on which evaluation is donepublic static double nextUp(double a)
a
- number to which neighbor should be computedpublic static float nextUp(float a)
a
- number to which neighbor should be computedpublic static double nextDown(double a)
a
- number to which neighbor should be computedpublic static float nextDown(float a)
a
- number to which neighbor should be computedpublic static double random()
Note: this implementation currently delegates to Math.random()
public static double exp(double x)
x
- a doublepublic static double expm1(double x)
x
- number to compute shifted exponentialpublic static double log(double x)
x
- a doublepublic static double log1p(double x)
x
- Number.log(1 + x)
.public static double log10(double x)
x
- a numberpublic static double log(double base, double x)
NaN
if either argument is negative.
If base
is 0 and x
is positive, 0 is returned.
If base
is positive and x
is 0,
Double.NEGATIVE_INFINITY
is returned.
If both arguments are 0, the result is NaN
.base
- Base of the logarithm, must be greater than 0.x
- Argument, must be greater than 0.y
such that
basey = x
.public static double pow(double x, double y)
x
- a doubley
- a doublepublic static double pow(double d, int e)
d
- Number to raise.e
- Exponent.public static double pow(double d, long e)
d
- Number to raise.e
- Exponent.public static double sin(double x)
x
- Argument.public static double cos(double x)
x
- Argument.public static SinCos sinCos(double x)
x
- Argument.public static <T extends CalculusFieldElement<T>> FieldSinCos<T> sinCos(T x)
T
- the type of the field elementx
- Argument.public static double tan(double x)
x
- Argument.public static double atan(double x)
x
- a numberpublic static double atan2(double y, double x)
y
- ordinatex
- abscissa-PI
and PI
public static double asin(double x)
x
- number on which evaluation is donepublic static double acos(double x)
x
- number on which evaluation is donepublic static double cbrt(double x)
x
- number on which evaluation is donepublic static double toRadians(double x)
x
- angle in degreespublic static double toDegrees(double x)
x
- angle in radianspublic static int abs(int x)
x
- number from which absolute value is requestedpublic static long abs(long x)
x
- number from which absolute value is requestedpublic static int absExact(int x)
x
- number from which absolute value is requestedInteger.MIN_VALUE
public static long absExact(long x)
x
- number from which absolute value is requestedLong.MIN_VALUE
public static float abs(float x)
x
- number from which absolute value is requestedpublic static double abs(double x)
x
- number from which absolute value is requestedpublic static int negateExact(int x)
x
- number from which opposite value is requestedInteger.MIN_VALUE
public static long negateExact(long x)
x
- number from which opposite value is requestedLong.MIN_VALUE
public static double ulp(double x)
x
- number from which ulp is requestedpublic static float ulp(float x)
x
- number from which ulp is requestedpublic static double scalb(double d, int n)
d
- number to multiplyn
- power of 2public static float scalb(float f, int n)
f
- number to multiplyn
- power of 2public static double nextAfter(double d, double direction)
The ordering is as follows (increasing):
If arguments compare equal, then the second argument is returned.
If direction
is greater than d
,
the smallest machine representable number strictly greater than
d
is returned; if less, then the largest representable number
strictly less than d
is returned.
If d
is infinite and direction does not
bring it back to finite numbers, it is returned unchanged.
d
- base numberdirection
- (the only important thing is whether
direction
is greater or smaller than d
)public static float nextAfter(float f, double direction)
The ordering is as follows (increasing):
If arguments compare equal, then the second argument is returned.
If direction
is greater than f
,
the smallest machine representable number strictly greater than
f
is returned; if less, then the largest representable number
strictly less than f
is returned.
If f
is infinite and direction does not
bring it back to finite numbers, it is returned unchanged.
f
- base numberdirection
- (the only important thing is whether
direction
is greater or smaller than f
)public static double floor(double x)
x
- number from which floor is requestedpublic static double ceil(double x)
x
- number from which ceil is requestedpublic static double rint(double x)
x
- number from which nearest whole number is requestedpublic static long round(double x)
x
- number from which closest long is requestedpublic static int round(float x)
x
- number from which closest int is requestedpublic static int min(int a, int b)
a
- first valueb
- second valuepublic static long min(long a, long b)
a
- first valueb
- second valuepublic static float min(float a, float b)
a
- first valueb
- second valuepublic static double min(double a, double b)
a
- first valueb
- second valuepublic static int max(int a, int b)
a
- first valueb
- second valuepublic static long max(long a, long b)
a
- first valueb
- second valuepublic static float max(float a, float b)
a
- first valueb
- second valuepublic static double max(double a, double b)
a
- first valueb
- second valuepublic static double hypot(double x, double y)
x
and y
- sqrt(x2 +y2)x
- a valuey
- a valuepublic static double IEEEremainder(double dividend, double divisor)
x - y*n
where n
is the mathematical integer closest to the exact mathematical value
of the quotient x/y
.
If two mathematical integers are equally close to x/y
then
n
is the integer that is even.
dividend
- the number to be divideddivisor
- the number by which to dividepublic static int toIntExact(long n) throws MathRuntimeException
n
- number to convert to intMathRuntimeException
- if n cannot fit into an intpublic static int incrementExact(int n) throws MathRuntimeException
n
- number to incrementMathRuntimeException
- if an overflow occurspublic static long incrementExact(long n) throws MathRuntimeException
n
- number to incrementMathRuntimeException
- if an overflow occurspublic static int decrementExact(int n) throws MathRuntimeException
n
- number to decrementMathRuntimeException
- if an overflow occurspublic static long decrementExact(long n) throws MathRuntimeException
n
- number to decrementMathRuntimeException
- if an overflow occurspublic static int addExact(int a, int b) throws MathRuntimeException
a
- first number to addb
- second number to addMathRuntimeException
- if an overflow occurspublic static long addExact(long a, long b) throws MathRuntimeException
a
- first number to addb
- second number to addMathRuntimeException
- if an overflow occurspublic static int subtractExact(int a, int b)
a
- first numberb
- second number to subtract from aMathRuntimeException
- if an overflow occurspublic static long subtractExact(long a, long b)
a
- first numberb
- second number to subtract from aMathRuntimeException
- if an overflow occurspublic static int multiplyExact(int a, int b)
a
- first number to multiplyb
- second number to multiplyMathRuntimeException
- if an overflow occurspublic static long multiplyExact(long a, int b)
a
- first number to multiplyb
- second number to multiplyMathRuntimeException
- if an overflow occurspublic static long multiplyExact(long a, long b)
a
- first number to multiplyb
- second number to multiplyMathRuntimeException
- if an overflow occurspublic static long multiplyFull(int a, int b)
a
- first factorb
- second factorpublic static long multiplyHigh(long a, long b)
Beware that as Java primitive long are always considered to be signed, there are some
intermediate values a
and b
for which a * b
exceeds Long.MAX_VALUE
but this method will still return 0l. This happens for example for a = 2³¹
and
b = 2³²
as a * 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 to Long.MIN_VALUE
a
- first factorb
- second factorpublic static int floorDiv(int a, int b) throws MathRuntimeException
a = q b + r
with 0 <= r < b
if b > 0
and b < r <= 0
if b < 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).
a
- dividendb
- divisora = q b + r
with 0 <= r < b
if b > 0
and b < r <= 0
if b < 0
MathRuntimeException
- if b == 0floorMod(int, int)
public static long floorDiv(long a, int b) throws MathRuntimeException
a = q b + r
with 0 <= r < b
if b > 0
and b < r <= 0
if b < 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).
a
- dividendb
- divisora = q b + r
with 0 <= r < b
if b > 0
and b < r <= 0
if b < 0
MathRuntimeException
- if b == 0floorMod(long, int)
public static long floorDiv(long a, long b) throws MathRuntimeException
a = q b + r
with 0 <= r < b
if b > 0
and b < r <= 0
if b < 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).
a
- dividendb
- divisora = q b + r
with 0 <= r < b
if b > 0
and b < r <= 0
if b < 0
MathRuntimeException
- if b == 0floorMod(long, long)
public static int floorMod(int a, int b) throws MathRuntimeException
a = q b + r
with 0 <= r < b
if b > 0
and b < r <= 0
if b < 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).
a
- dividendb
- divisora = q b + r
with 0 <= r < b
if b > 0
and b < r <= 0
if b < 0
MathRuntimeException
- if b == 0floorDiv(int, int)
public static int floorMod(long a, int b)
a = q b + r
with 0 <= r < b
if b > 0
and b < r <= 0
if b < 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).
a
- dividendb
- divisora = q b + r
with 0 <= r < b
if b > 0
and b < r <= 0
if b < 0
MathRuntimeException
- if b == 0floorDiv(long, int)
public static long floorMod(long a, long b)
a = q b + r
with 0 <= r < b
if b > 0
and b < r <= 0
if b < 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).
a
- dividendb
- divisora = q b + r
with 0 <= r < b
if b > 0
and b < r <= 0
if b < 0
MathRuntimeException
- if b == 0floorDiv(long, long)
public static double copySign(double magnitude, double sign)
sign
argument is treated as positive.magnitude
- the value to returnsign
- the sign for the returned valuesign
argumentpublic static float copySign(float magnitude, float sign)
sign
argument is treated as positive.magnitude
- the value to returnsign
- the sign for the returned valuesign
argumentpublic static int getExponent(double d)
For double numbers of the form 2x, the unbiased exponent is exactly x.
d
- number from which exponent is requestedpublic static int getExponent(float f)
For float numbers of the form 2x, the unbiased exponent is exactly x.
f
- number from which exponent is requestedpublic static double fma(double a, double b, double c)
This method was introduced in the regular Math
and StrictMath
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.
a
- first factorb
- second factorc
- additive termMathArrays.linearCombination(double[], double[])
,
MathArrays.linearCombination(double, double, double, double)
,
MathArrays.linearCombination(double, double, double, double, double, double)
,
MathArrays.linearCombination(double, double, double, double, double, double, double, double)
public static float fma(float a, float b, float c)
This method was introduced in the regular Math
and StrictMath
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.
a
- first factorb
- second factorc
- additive termMathArrays.linearCombination(double[], double[])
,
MathArrays.linearCombination(double, double, double, double)
,
MathArrays.linearCombination(double, double, double, double, double, double)
,
MathArrays.linearCombination(double, double, double, double, double, double, double, double)
public static <T extends CalculusFieldElement<T>> T sqrt(T a)
T
- the type of the field elementa
- number on which evaluation is donepublic static <T extends CalculusFieldElement<T>> T cosh(T x)
T
- the type of the field elementx
- number on which evaluation is donepublic static <T extends CalculusFieldElement<T>> T sinh(T x)
T
- the type of the field elementx
- number on which evaluation is donepublic static <T extends CalculusFieldElement<T>> T tanh(T x)
T
- the type of the field elementx
- number on which evaluation is donepublic static <T extends CalculusFieldElement<T>> T acosh(T a)
T
- the type of the field elementa
- number on which evaluation is donepublic static <T extends CalculusFieldElement<T>> T asinh(T a)
T
- the type of the field elementa
- number on which evaluation is donepublic static <T extends CalculusFieldElement<T>> T atanh(T a)
T
- the type of the field elementa
- number on which evaluation is donepublic static <T extends CalculusFieldElement<T>> T sign(T a)
T
- the type of the field elementa
- number on which evaluation is donepublic static <T extends CalculusFieldElement<T>> T exp(T x)
T
- the type of the field elementx
- a doublepublic static <T extends CalculusFieldElement<T>> T expm1(T x)
T
- the type of the field elementx
- number to compute shifted exponentialpublic static <T extends CalculusFieldElement<T>> T log(T x)
T
- the type of the field elementx
- a doublepublic static <T extends CalculusFieldElement<T>> T log1p(T x)
T
- the type of the field elementx
- Number.log(1 + x)
.public static <T extends CalculusFieldElement<T>> T log10(T x)
T
- the type of the field elementx
- a numberpublic static <T extends CalculusFieldElement<T>> T pow(T x, T y)
T
- the type of the field elementx
- a doubley
- a doublepublic static <T extends CalculusFieldElement<T>> T pow(T x, double y)
T
- the type of the field elementx
- a doubley
- a doublepublic static <T extends CalculusFieldElement<T>> T pow(T d, int e)
T
- the type of the field elementd
- Number to raise.e
- Exponent.public static <T extends CalculusFieldElement<T>> T sin(T x)
T
- the type of the field elementx
- Argument.public static <T extends CalculusFieldElement<T>> T cos(T x)
T
- the type of the field elementx
- Argument.public static <T extends CalculusFieldElement<T>> T tan(T x)
T
- the type of the field elementx
- Argument.public static <T extends CalculusFieldElement<T>> T atan(T x)
T
- the type of the field elementx
- a numberpublic static <T extends CalculusFieldElement<T>> T atan2(T y, T x)
T
- the type of the field elementy
- ordinatex
- abscissa-PI
and PI
public static <T extends CalculusFieldElement<T>> T asin(T x)
T
- the type of the field elementx
- number on which evaluation is donepublic static <T extends CalculusFieldElement<T>> T acos(T x)
T
- the type of the field elementx
- number on which evaluation is donepublic static <T extends CalculusFieldElement<T>> T cbrt(T x)
T
- the type of the field elementx
- number on which evaluation is donepublic static <T extends CalculusFieldElement<T>> double norm(T x)
T
- the type of the field elementx
- number from which norm is requestedpublic static <T extends CalculusFieldElement<T>> T abs(T x)
T
- the type of the field elementx
- number from which absolute value is requestedpublic static <T extends CalculusFieldElement<T>> T toRadians(T x)
T
- the type of the field elementx
- angle in degreespublic static <T extends CalculusFieldElement<T>> T toDegrees(T x)
T
- the type of the field elementx
- angle in radianspublic static <T extends CalculusFieldElement<T>> T scalb(T d, int n)
T
- the type of the field elementd
- number to multiplyn
- power of 2public static <T extends CalculusFieldElement<T>> T ulp(T x)
T
- the type of the field elementx
- number from which ulp is requestedpublic static <T extends CalculusFieldElement<T>> T floor(T x)
T
- the type of the field elementx
- number from which floor is requestedpublic static <T extends CalculusFieldElement<T>> T ceil(T x)
T
- the type of the field elementx
- number from which ceil is requestedpublic static <T extends CalculusFieldElement<T>> T rint(T x)
T
- the type of the field elementx
- number from which nearest whole number is requestedpublic static <T extends CalculusFieldElement<T>> long round(T x)
T
- the type of the field elementx
- number from which closest long is requestedpublic static <T extends CalculusFieldElement<T>> T min(T a, T b)
T
- the type of the field elementa
- first valueb
- second valuepublic static <T extends CalculusFieldElement<T>> T min(T a, double b)
T
- the type of the field elementa
- first valueb
- second valuepublic static <T extends CalculusFieldElement<T>> T max(T a, T b)
T
- the type of the field elementa
- first valueb
- second valuepublic static <T extends CalculusFieldElement<T>> T max(T a, double b)
T
- the type of the field elementa
- first valueb
- second valuepublic static <T extends CalculusFieldElement<T>> T hypot(T x, T y)
x
and y
- sqrt(x2 +y2)T
- the type of the field elementx
- a valuey
- a valuepublic static <T extends CalculusFieldElement<T>> T IEEEremainder(T dividend, double divisor)
x - y*n
where n
is the mathematical integer closest to the exact mathematical value
of the quotient x/y
.
If two mathematical integers are equally close to x/y
then
n
is the integer that is even.
T
- the type of the field elementdividend
- the number to be divideddivisor
- the number by which to dividepublic static <T extends CalculusFieldElement<T>> T IEEEremainder(T dividend, T divisor)
x - y*n
where n
is the mathematical integer closest to the exact mathematical value
of the quotient x/y
.
If two mathematical integers are equally close to x/y
then
n
is the integer that is even.
T
- the type of the field elementdividend
- the number to be divideddivisor
- the number by which to dividepublic static <T extends CalculusFieldElement<T>> T copySign(T magnitude, T sign)
sign
argument is treated as positive.T
- the type of the field elementmagnitude
- the value to returnsign
- the sign for the returned valuesign
argumentpublic static <T extends CalculusFieldElement<T>> T copySign(T magnitude, double sign)
sign
argument is treated as positive.T
- the type of the field elementmagnitude
- the value to returnsign
- the sign for the returned valuesign
argumentCopyright © 2016-2022 CS GROUP. All rights reserved.