public final class MathLib extends Object
MathLibrary
. By default FastMathWrapper
which
encapsulate MathLib
is used.
The user can define its own Math library used in PATRIUS by implementing MathLibrary
and defining it as the
Math library to use with method setMathLibrary(MathLibrary)
Be aware that some MathLib
of JAFAMA functions may not be included in Mathlib since only all commons
functions between FastMath and JAFAMA are listed in MathLib (e.g. FastMath.log(double, double)
.
Modifier 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 double |
acos(double x)
Compute the arc cosine of a number.
|
static double |
acosh(double a)
Compute the inverse hyperbolic cosine of a number.
|
static double |
asin(double x)
Compute the arc sine of a number.
|
static double |
asinh(double a)
Compute the inverse hyperbolic sine of a number.
|
static double |
atan(double x)
Arctangent function
|
static double |
atan2(double y,
double x)
Two arguments arctangent function
|
static double |
atanh(double a)
Compute the inverse hyperbolic tangent of a number.
|
static double |
cbrt(double x)
Compute the cubic root of a number.
|
static double |
ceil(double 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 double |
cos(double x)
Cosine function.
|
static double |
cosh(double x)
Compute the hyperbolic cosine of a number.
|
static double |
divide(double x,
double y)
Computes x / y.
|
static double |
exp(double x)
Exponential function.
|
static double |
expm1(double x)
Compute exp(x) - 1
|
static double |
floor(double x)
Get the largest whole number smaller than x.
|
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 double |
IEEEremainder(double dividend,
double divisor)
Computes the remainder as prescribed by the IEEE 754 standard.
|
static double |
log(double x)
Natural logarithm.
|
static double |
log10(double x)
Compute the base 10 logarithm.
|
static double |
log1p(double 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 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 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 |
nextUp(double a)
Compute next number towards positive infinity.
|
static float |
nextUp(float a)
Compute next number towards positive infinity.
|
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 |
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 long |
round(double x)
Get the closest long to x.
|
static int |
round(float x)
Get the closest int 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 void |
setMathLibrary(MathLibrary library)
Set Math library.
|
static void |
setMathLibrary(MathLibraryType libraryType)
Set Math library using predefined values.
|
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 double[] |
sinAndCos(double x)
Computes sine and cosine of an angle together.
|
static void |
sinAndCos(double x,
double[] sincos)
Computes sine and cosine of an angle together.
|
static double |
sinh(double x)
Compute the hyperbolic sine of a number.
|
static double[] |
sinhAndCosh(double x)
Computes hyperbolic sine and hyperbolic cosine together.
|
static void |
sinhAndCosh(double x,
double[] sinhcosh)
Computes hyperbolic sine and hyperbolic cosine together.
|
static double |
sqrt(double a)
Compute the square root of a number.
|
static double |
tan(double x)
Tangent function.
|
static double |
tanh(double 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 double |
toRadians(double 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.
|
public static final double PI
public static final double E
public static void setMathLibrary(MathLibrary library)
This methods allows user to define its own Math library.
library
- librarypublic static void setMathLibrary(MathLibraryType libraryType)
libraryType
- library typepublic static double sqrt(double a)
a
- number on which evaluation is doneArithmeticException
- thrown if a < 0 or a is NaNpublic static double cosh(double x)
x
- number on which evaluation is doneArithmeticException
- thrown if x is NaNpublic static double sinh(double x)
x
- number on which evaluation is doneArithmeticException
- thrown if x is NaNpublic static double tanh(double x)
x
- number on which evaluation is doneArithmeticException
- thrown if a is NaNpublic static double acosh(double a)
a
- number on which evaluation is doneArithmeticException
- thrown if a < 1 or a is NaNpublic static double asinh(double a)
a
- number on which evaluation is doneArithmeticException
- thrown if a is NaNpublic static double atanh(double a)
a
- number on which evaluation is doneArithmeticException
- thrown if a > 1 or a < -1 or a is NaNpublic static double signum(double a)
a
- number on which evaluation is doneArithmeticException
- thrown if a is NaNpublic static float signum(float a)
a
- number on which evaluation is doneArithmeticException
- thrown if a is NaNpublic static double nextUp(double a)
a
- number to which neighbor should be computedArithmeticException
- thrown if a is NaNpublic static float nextUp(float a)
a
- number to which neighbor should be computedArithmeticException
- thrown if a is NaNpublic static double random()
public static double exp(double x)
x
- a doubleArithmeticException
- thrown if x is NaNpublic static double expm1(double x)
x
- number to compute shifted exponentialArithmeticException
- thrown if x is NaNpublic static double log(double x)
x
- a doubleArithmeticException
- thrown if x < 0 or x is NaNpublic static double log1p(double x)
x
- Number.log(1 + x)
.ArithmeticException
- thrown if x < 0 or x is NaNpublic static double log10(double x)
x
- a numberArithmeticException
- thrown if x < 0 or x is NaNpublic static double pow(double x, double y)
x
- a doubley
- a doubleArithmeticException
- thrown if y < 0 and y not an integer or x or y is NaN or x = -1public static double pow(double d, int e)
d
- Number to raise.e
- Exponent.ArithmeticException
- thrown if d is NaNpublic static double sin(double x)
x
- Argument.ArithmeticException
- thrown if x is NaN or Infinitypublic static double cos(double x)
x
- Argument.ArithmeticException
- thrown if x is NaN or Infinitypublic static double tan(double x)
x
- Argument.ArithmeticException
- thrown if x is NaN or Infinitypublic static double atan(double x)
x
- a numberArithmeticException
- thrown if x is NaNpublic static double atan2(double y, double x)
y
- ordinatex
- abscissa-PI
and PI
ArithmeticException
- thrown if x or y is NaNpublic static double asin(double x)
x
- number on which evaluation is doneArithmeticException
- thrown if x < -1 or x > 1 or x is NaNpublic static double acos(double x)
x
- number on which evaluation is doneArithmeticException
- thrown if x < -1 or x > 1 or x is NaNpublic static double cbrt(double x)
x
- number on which evaluation is doneArithmeticException
- thrown if x is NaNpublic static double toRadians(double x)
x
- angle in degreesArithmeticException
- thrown if x is NaNpublic static double toDegrees(double x)
x
- angle in radiansArithmeticException
- thrown if x is NaNpublic 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 float abs(float x)
x
- number from which absolute value is requestedArithmeticException
- thrown if x is NaNpublic static double abs(double x)
x
- number from which absolute value is requestedArithmeticException
- thrown if x is NaNpublic static double ulp(double x)
x
- number from which ulp is requestedArithmeticException
- thrown if x is NaNpublic static float ulp(float x)
x
- number from which ulp is requestedArithmeticException
- thrown if x is NaNpublic static double scalb(double d, int n)
d
- number to multiplyn
- power of 2ArithmeticException
- thrown if d is NaNpublic static float scalb(float f, int n)
f
- number to multiplyn
- power of 2ArithmeticException
- thrown if f is NaNpublic 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
)ArithmeticException
- thrown if d or direction is NaNpublic 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
)ArithmeticException
- thrown if f or direction is NaNpublic static double floor(double x)
x
- number from which floor is requestedArithmeticException
- thrown if x is NaNpublic static double ceil(double x)
x
- number from which ceil is requestedArithmeticException
- thrown if x is NaNpublic static double rint(double x)
x
- number from which nearest whole number is requestedArithmeticException
- thrown if x is NaNpublic static long round(double x)
x
- number from which closest long is requestedArithmeticException
- thrown if x is NaNpublic static int round(float x)
x
- number from which closest int is requestedArithmeticException
- thrown if x is NaNpublic 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 valueArithmeticException
- thrown if a or b is NaNpublic static double min(double a, double b)
a
- first valueb
- second valueArithmeticException
- thrown if a or b is NaNpublic 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 valueArithmeticException
- thrown if a or b is NaNpublic static double max(double a, double b)
a
- first valueb
- second valueArithmeticException
- thrown if a or b is NaNpublic static double hypot(double x, double y)
x
and y
-
sqrt(x2 +y2)x
- a valuey
- a valueArithmeticException
- thrown if x or y is NaNpublic 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 divideArithmeticException
- thrown if input cannot allow to compute remainderpublic static double copySign(double magnitude, double sign)
sign
argument
is treated as positive.magnitude
- the value to returnsign
- the sign for the returned valuesign
argumentArithmeticException
- thrown if magnitude is NaNpublic static float copySign(float magnitude, float sign)
sign
argument
is treated as positive.magnitude
- the value to returnsign
- the sign for the returned valuesign
argumentArithmeticException
- thrown if magnitude is NaNpublic 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 divide(double x, double y)
x
- numeratory
- denominatorArithmeticException
- thrown if x / y = NaN or y = 0public static double[] sinAndCos(double x)
x
- angle in radianspublic static void sinAndCos(double x, double[] sincos)
x
- angle in radianssincos
- array of size 2. Array is filled is values: [angle sine, angle cosine]public static double[] sinhAndCosh(double x)
x
- valuepublic static void sinhAndCosh(double x, double[] sinhcosh)
x
- valuesinhcosh
- array of size 2. Array is filled is values: [hyperbolic sine, hyperbolic cosine]Copyright © 2021 CNES. All rights reserved.