public final class MathUtils extends Object
ArithmeticUtils
,
Precision
,
MathArrays
Modifier and Type | Class and Description |
---|---|
static class |
MathUtils.FieldSumAndResidual<T extends FieldElement<T>>
Result class for
twoSum(FieldElement, FieldElement) containing
the sum and the residual error in the sum. |
static class |
MathUtils.SumAndResidual
Result class for
twoSum(double, double) containing the
sum and the residual error in the sum. |
Modifier and Type | Field and Description |
---|---|
static double |
PI_SQUARED
\(\pi^2\)
|
static double |
SEMI_PI
\(\pi/2\).
|
static double |
TWO_PI
\(2\pi\)
|
Modifier and Type | Method and Description |
---|---|
static void |
checkDimension(int dimension,
int otherDimension)
Checks that the given dimensions match.
|
static void |
checkFinite(double x)
Check that the argument is a real number.
|
static void |
checkFinite(double[] val)
Check that all the elements are real numbers.
|
static void |
checkNotNull(Object o)
Checks that an object is not null.
|
static void |
checkNotNull(Object o,
Localizable pattern,
Object... args)
Checks that an object is not null.
|
static void |
checkRangeInclusive(double value,
double lo,
double hi)
Checks that the given value is strictly within the range [lo, hi].
|
static void |
checkRangeInclusive(long value,
long lo,
long hi)
Checks that the given value is strictly within the range [lo, hi].
|
static byte |
copySign(byte magnitude,
byte sign)
Returns the first argument with the sign of the second argument.
|
static int |
copySign(int magnitude,
int sign)
Returns the first argument with the sign of the second argument.
|
static long |
copySign(long magnitude,
long sign)
Returns the first argument with the sign of the second argument.
|
static short |
copySign(short magnitude,
short sign)
Returns the first argument with the sign of the second argument.
|
static boolean |
equals(double x,
double y)
Returns
true if the values are equal according to semantics of
Double.equals(Object) . |
static int |
hash(double value)
Returns an integer hash code representing the given double value.
|
static int |
hash(double[] value)
Returns an integer hash code representing the given double array.
|
static <T extends CalculusFieldElement<T>> |
max(T e1,
T e2)
Find the maximum of two field elements.
|
static <T extends CalculusFieldElement<T>> |
min(T e1,
T e2)
Find the minimum of two field elements.
|
static double |
normalizeAngle(double a,
double center)
Normalize an angle in a 2π wide interval around a center value.
|
static <T extends CalculusFieldElement<T>> |
normalizeAngle(T a,
T center)
Normalize an angle in a 2π wide interval around a center value.
|
static double |
reduce(double a,
double period,
double offset)
Reduce
|a - offset| to the primary interval
[0, |period|) . |
static MathUtils.SumAndResidual |
twoSum(double a,
double b)
Sums
a and b using Møller's 2Sum algorithm. |
static <T extends FieldElement<T>> |
twoSum(T a,
T b)
Sums
a and b using Møller's 2Sum algorithm. |
public static final double TWO_PI
public static final double PI_SQUARED
public static final double SEMI_PI
public static int hash(double value)
value
- the value to be hashedpublic static boolean equals(double x, double y)
true
if the values are equal according to semantics of
Double.equals(Object)
.x
- Valuey
- Valuenew Double(x).equals(new Double(y))
public static int hash(double[] value)
value
- the value to be hashed (may be null)public static double normalizeAngle(double a, double center)
This method has three main uses:
a = MathUtils.normalizeAngle(a, FastMath.PI);
a = MathUtils.normalizeAngle(a, 0.0);
angle = MathUtils.normalizeAngle(end, start) - start;
Note that due to numerical accuracy and since π cannot be represented exactly, the result interval is closed, it cannot be half-closed as would be more satisfactory in a purely mathematical view.
a
- angle to normalizecenter
- center of the desired 2π interval for the resultpublic static <T extends CalculusFieldElement<T>> T normalizeAngle(T a, T center)
This method has three main uses:
a = MathUtils.normalizeAngle(a, FastMath.PI);
a = MathUtils.normalizeAngle(a, zero);
angle = MathUtils.normalizeAngle(end, start).subtract(start);
Note that due to numerical accuracy and since π cannot be represented exactly, the result interval is closed, it cannot be half-closed as would be more satisfactory in a purely mathematical view.
T
- the type of the field elementsa
- angle to normalizecenter
- center of the desired 2π interval for the resultpublic static <T extends CalculusFieldElement<T>> T max(T e1, T e2)
T
- the type of the field elementse1
- first elemente2
- second elementpublic static <T extends CalculusFieldElement<T>> T min(T e1, T e2)
T
- the type of the field elementse1
- first elemente2
- second elementpublic static double reduce(double a, double period, double offset)
Reduce |a - offset|
to the primary interval
[0, |period|)
.
Specifically, the value returned is
a - |period| * floor((a - offset) / |period|) - offset
.
If any of the parameters are NaN
or infinite, the result is
NaN
.
a
- Value to reduce.period
- Period.offset
- Value that will be mapped to 0
.[0 |period|)
,
that corresponds to a
.public static byte copySign(byte magnitude, byte sign) throws MathRuntimeException
magnitude
- Magnitude of the returned value.sign
- Sign of the returned value.magnitude
and with the
same sign as the sign
argument.MathRuntimeException
- if magnitude == Byte.MIN_VALUE
and sign >= 0
.public static short copySign(short magnitude, short sign) throws MathRuntimeException
magnitude
- Magnitude of the returned value.sign
- Sign of the returned value.magnitude
and with the
same sign as the sign
argument.MathRuntimeException
- if magnitude == Short.MIN_VALUE
and sign >= 0
.public static int copySign(int magnitude, int sign) throws MathRuntimeException
magnitude
- Magnitude of the returned value.sign
- Sign of the returned value.magnitude
and with the
same sign as the sign
argument.MathRuntimeException
- if magnitude == Integer.MIN_VALUE
and sign >= 0
.public static long copySign(long magnitude, long sign) throws MathRuntimeException
magnitude
- Magnitude of the returned value.sign
- Sign of the returned value.magnitude
and with the
same sign as the sign
argument.MathRuntimeException
- if magnitude == Long.MIN_VALUE
and sign >= 0
.public static void checkFinite(double x) throws MathIllegalArgumentException
x
- Argument.MathIllegalArgumentException
- if x
is not a
finite real number.public static void checkFinite(double[] val) throws MathIllegalArgumentException
val
- Arguments.MathIllegalArgumentException
- if any values of the array is not a
finite real number.public static void checkNotNull(Object o, Localizable pattern, Object... args) throws NullArgumentException
o
- Object to be checked.pattern
- Message pattern.args
- Arguments to replace the placeholders in pattern
.NullArgumentException
- if o
is null
.public static void checkNotNull(Object o) throws NullArgumentException
o
- Object to be checked.NullArgumentException
- if o
is null
.public static void checkRangeInclusive(long value, long lo, long hi)
value
- value to be checked.lo
- the lower bound (inclusive).hi
- the upper bound (inclusive).MathIllegalArgumentException
- if value
is strictly outside [lo, hi].public static void checkRangeInclusive(double value, double lo, double hi)
value
- value to be checked.lo
- the lower bound (inclusive).hi
- the upper bound (inclusive).MathIllegalArgumentException
- if value
is strictly outside [lo, hi].public static void checkDimension(int dimension, int otherDimension)
dimension
- the first dimension.otherDimension
- the second dimension.MathIllegalArgumentException
- if length != otherLength.public static MathUtils.SumAndResidual twoSum(double a, double b)
a
and b
using Møller's 2Sum algorithm.
References:
a
- first summandb
- second summandpublic static <T extends FieldElement<T>> MathUtils.FieldSumAndResidual<T> twoSum(T a, T b)
a
and b
using Møller's 2Sum algorithm.
References:
T
- field element typea
- first summandb
- second summandCopyright © 2016-2021 CS GROUP. All rights reserved.