|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.math.util.MathUtils
public final class MathUtils
Some useful additions to the built-in functions in Math.
| Field Summary | |
|---|---|
static double |
EPSILON
Smallest positive number such that 1 - EPSILON is not numerically equal to 1. |
static double |
SAFE_MIN
Safe minimum, such that 1 / SAFE_MIN does not overflow. |
static double |
TWO_PI
2 π. |
| Method Summary | |
|---|---|
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 number. |
static void |
checkNotNull(java.lang.Object o)
Checks that an object is not null. |
static void |
checkNotNull(java.lang.Object o,
Localizable pattern,
java.lang.Object... args)
Checks that an object is not null. |
static byte |
copySign(byte magnitude,
byte sign)
Returns the first argument with the sign of the second argument. |
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 byte |
indicator(byte x)
For a byte value x, this method returns (byte)(+1) if x >= 0 and (byte)(-1) if x < 0. |
static double |
indicator(double x)
For a double precision value x, this method returns +1.0 if x >= 0 and -1.0 if x < 0. |
static float |
indicator(float x)
For a float value x, this method returns +1.0F if x >= 0 and -1.0F if x < 0. |
static int |
indicator(int x)
For an int value x, this method returns +1 if x >= 0 and -1 if x < 0. |
static long |
indicator(long x)
For a long value x, this method returns +1L if x >= 0 and -1L if x < 0. |
static short |
indicator(short x)
For a short value x, this method returns (short)(+1) if x >= 0 and (short)(-1) if x < 0. |
static double |
log(double base,
double x)
Returns the logarithm for base b of x. |
static double |
normalizeAngle(double a,
double center)
Normalize an angle in a 2&pi wide interval around a center value. |
static java.math.BigInteger |
pow(java.math.BigInteger k,
java.math.BigInteger e)
Raise a BigInteger to a BigInteger power. |
static java.math.BigInteger |
pow(java.math.BigInteger k,
int e)
Raise a BigInteger to an int power. |
static java.math.BigInteger |
pow(java.math.BigInteger k,
long e)
Raise a BigInteger to a long power. |
static int |
pow(int k,
int e)
Raise an int to an int power. |
static int |
pow(int k,
long e)
Raise an int to a long power. |
static long |
pow(long k,
int e)
Raise a long to an int power. |
static long |
pow(long k,
long e)
Raise a long to a long power. |
static double |
reduce(double a,
double period,
double offset)
Reduce |a - offset| to the primary interval
[0, |period|). |
static double |
round(double x,
int scale)
Round the given value to the specified number of decimal places. |
static double |
round(double x,
int scale,
int roundingMethod)
Round the given value to the specified number of decimal places. |
static float |
round(float x,
int scale)
Round the given value to the specified number of decimal places. |
static float |
round(float x,
int scale,
int roundingMethod)
Round the given value to the specified number of decimal places. |
static byte |
sign(byte x)
Returns the sign for byte value x. |
static int |
sign(int x)
Returns the sign for int value x. |
static long |
sign(long x)
Returns the sign for long value x. |
static short |
sign(short x)
Compute the sign of the argument. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final double EPSILON
public static final double SAFE_MIN
In IEEE 754 arithmetic, this is also the smallest normalized number 2-1022.
public static final double TWO_PI
| Method Detail |
|---|
public static int hash(double value)
value - the value to be hashed
public static int hash(double[] value)
value - the value to be hashed (may be null)
public static byte indicator(byte x)
x - the value, a byte
public static double indicator(double x)
NaN if x is
NaN.
x - the value, a double
public static float indicator(float x)
NaN if x is NaN.
x - the value, a float
public static int indicator(int x)
x - the value, an int
public static long indicator(long x)
x - the value, a long
public static short indicator(short x)
x - the value, a short
public static double log(double base,
double x)
Returns the
logarithm
for base b of x.
Returns 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 - the base of the logarithm, must be greater than 0x - argument, must be greater than 0
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 result
public 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 double round(double x,
int scale)
BigDecimal.ROUND_HALF_UP method.
x - the value to round.scale - the number of digits to the right of the decimal point.
public static double round(double x,
int scale,
int roundingMethod)
Round the given value to the specified number of decimal places. The
value is rounded using the given method which is any method defined in
BigDecimal.
If x is infinite or NaN, then the value of x is
returned unchanged, regardless of the other parameters.
x - the value to round.scale - the number of digits to the right of the decimal point.roundingMethod - the rounding method as defined in
BigDecimal.
java.lang.ArithmeticException - if roundingMethod==ROUND_UNNECESSARY and the
specified scaling operation would require rounding.
java.lang.IllegalArgumentException - if roundingMethod does not represent a
valid rounding mode.
public static float round(float x,
int scale)
BigDecimal.ROUND_HALF_UP method.
x - the value to round.scale - the number of digits to the right of the decimal point.
public static float round(float x,
int scale,
int roundingMethod)
BigDecimal.
x - the value to round.scale - the number of digits to the right of the decimal point.roundingMethod - the rounding method as defined in
BigDecimal.
public static byte sign(byte x)
x.
For a byte value x, this method returns (byte)(+1) if x > 0, (byte)(0) if x = 0, and (byte)(-1) if x < 0.
x - the value, a byte
public static byte copySign(byte magnitude,
byte sign)
magnitude - Magnitude of the returned value.sign - Sign of the returned value.
magnitude and with the
same sign as the sign argument.
MathArithmeticException - if magnitude == Byte.MIN_VALUE
and sign >= 0.public static int sign(int x)
x.
For an int value x, this method returns +1 if x > 0, 0 if x = 0, and -1 if x < 0.
x - the value, an int
public static long sign(long x)
x.
For a long value x, this method returns +1L if x > 0, 0L if x = 0, and -1L if x < 0.
x - the value, a long
public static short sign(short x)
x - the value, a short
x > 0, 0 if x == 0, and -1 if x < 0.
public static int pow(int k,
int e)
k - Number to raise.e - Exponent (must be positive or zero).
NotPositiveException - if e < 0.
public static int pow(int k,
long e)
k - Number to raise.e - Exponent (must be positive or zero).
NotPositiveException - if e < 0.
public static long pow(long k,
int e)
k - Number to raise.e - Exponent (must be positive or zero).
NotPositiveException - if e < 0.
public static long pow(long k,
long e)
k - Number to raise.e - Exponent (must be positive or zero).
NotPositiveException - if e < 0.
public static java.math.BigInteger pow(java.math.BigInteger k,
int e)
k - Number to raise.e - Exponent (must be positive or zero).
NotPositiveException - if e < 0.
public static java.math.BigInteger pow(java.math.BigInteger k,
long e)
k - Number to raise.e - Exponent (must be positive or zero).
NotPositiveException - if e < 0.
public static java.math.BigInteger pow(java.math.BigInteger k,
java.math.BigInteger e)
k - Number to raise.e - Exponent (must be positive or zero).
NotPositiveException - if e < 0.public static void checkFinite(double x)
x - Argument.
NotFiniteNumberException - if x is not a
finite real number.public static void checkFinite(double[] val)
val - Arguments.
NotFiniteNumberException - if any values of the array is not a
finite real number.
public static void checkNotNull(java.lang.Object o,
Localizable pattern,
java.lang.Object... args)
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(java.lang.Object o)
throws NullArgumentException
o - Object to be checked.
NullArgumentException - if o is null.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||