|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectrebuild.util.MathUtilities
public final class MathUtilities
Provides some basic numeric operations.
Constructor Summary | |
---|---|
MathUtilities()
|
Method Summary | |
---|---|
static double |
acos(double x)
Returns the arc cosine of the value x. |
static double |
asin(double x)
Returns the arc sine of the value x. |
static double |
atan(double x)
Returns the arc tangent of the value x. |
static double |
atan2(double y,
double x)
Converts rectangular coordinates (x,y) to polar coordinates (r,theta). |
static long |
bigMul(int a,
int b)
Produces the full product of two 32-bit numbers. |
static double |
clamp(double low,
double value,
double high)
Clamps provided double value between a lower and upper bound. |
static float |
clamp(float low,
float value,
float high)
Clamps provided float value between a lower and upper bound. |
static int |
clamp(int low,
int value,
int high)
Clamps provided integer value between a lower and upper bound. |
static long |
clamp(long low,
long value,
long high)
Clamps provided long integer value between a lower and upper bound. |
static double |
cosh(double value)
Returns the hyperbolic cosine of the specified angle. |
static int |
divRem(int a,
int b,
RefLong result)
Calculates the quotient of two 64-bit signed integers and also returns the remainder in an output parameter. |
static int |
doubleToFP(double value)
Convert a Double to a 16.16 fixed-point number. |
static int |
doubleToFP(float value)
Convert a Float to a 16.16 fixed-point number. |
static double |
exp(double x)
Return the exponential (base e) of x. |
static double |
fpToDouble(int fp)
Convert a 16.16 fixed-point number to a Double . |
static float |
fpToFloat(int fp)
Convert a 16.16 fixed-point number to a Float . |
static boolean |
isNegativeInfinity(double d)
Returns a value indicating whether the specified number evaluates to negative infinity. |
static boolean |
isNegativeInfinity(float d)
Returns a value indicating whether the specified number evaluates to negative infinity. |
static boolean |
isPositiveInfinity(double d)
Returns a value indicating whether the specified number evaluates to positive infinity. |
static boolean |
isPositiveInfinity(float d)
Returns a value indicating whether the specified number evaluates to positive infinity. |
static double |
ldexp(double x,
int exp)
Returns the result of multiplying x (the significand) by 2 raised to the power of exp (the exponent). |
static double |
log(double x)
Return the natural logarithm (base e) of x. |
static double |
log(double a,
double newBase)
Returns the logarithm of a specified number in a specified base. |
static int |
log2(int value)
Returns the log base 2 of the unsigned value rounded down. |
static int |
log2(long value)
Returns the log base 2 of the unsigned value rounded down. |
static double |
nextDouble(double d)
Finds the least double greater than d. |
static double |
nextDouble(double d,
boolean positive)
Finds the least double greater than d (if positive == true), or the greatest double less than d (if positive == false). |
static double |
pow(double x,
double y)
Return x raised to the power of y. |
static double |
previousDouble(double d)
Finds the greatest double less than d. |
static long |
round(double a)
Returns the closest long to the argument. |
static int |
round(float a)
Returns the closest int to the argument. |
static int |
sign(byte value)
Returns a value indicating the sign of a 8-bit signed integer. |
static int |
sign(double value)
Returns a value indicating the sign of a double-precision floating-point number. |
static int |
sign(float value)
Returns a value indicating the sign of a single-precision floating-point number. |
static int |
sign(int value)
Returns a value indicating the sign of a 32-bit signed integer. |
static int |
sign(long value)
Returns a value indicating the sign of a 64-bit signed integer. |
static int |
sign(short value)
Returns a value indicating the sign of a 16-bit signed integer. |
static double |
sinh(double value)
Returns the hyperbolic sine of the specified angle. |
static double |
tanh(double value)
Returns the hyperbolic tangent of the specified angle. |
static double |
wrap(double low,
double value,
double high)
Wraps provided double value around a lower and upper bound. |
static float |
wrap(float low,
float value,
float high)
Wraps provided float value around a lower and upper bound. |
static int |
wrap(int low,
int value,
int high)
Wraps provided integer value around a lower and upper bound. |
static long |
wrap(long low,
long value,
long high)
Wraps provided long integer value around a lower and upper bound. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MathUtilities()
Method Detail |
---|
public static double acos(double x)
x
- the value.
public static double asin(double x)
x
- the value.
public static double atan(double x)
x
- the value.
public static double atan2(double y, double x)
y
- the abscissa coordinate.x
- the ordinate coordinate.
public static int clamp(int low, int value, int high)
low
- Lower bound value; must be less than your upper bound parameter.value
- Value to clamp.high
- Upper bound value.
java.lang.IllegalArgumentException
- If you provide a low parameter value that is greater than your high parameter value.public static long clamp(long low, long value, long high)
low
- Lower bound value; must be less than your upper bound parameter.value
- Value to clamp.high
- Upper bound value.
java.lang.IllegalArgumentException
- If you provide a low parameter value that is greater than your high parameter value.public static float clamp(float low, float value, float high)
low
- Lower bound value; must be less than your upper bound parameter.value
- Value to clamp.high
- Upper bound value.
java.lang.IllegalArgumentException
- If you provide a low parameter value that is greater than your high parameter value.public static double clamp(double low, double value, double high)
low
- Lower bound value; must be less than your upper bound parameter.value
- Value to clamp.high
- Upper bound value.
java.lang.IllegalArgumentException
- If you provide a low parameter value that is greater than your high parameter value.public static double exp(double x)
x
- the power to raise e to.
public static double ldexp(double x, int exp)
x
- the significand.exp
- the exponent.
public static double log(double x)
x
- a number greater than zero.
public static int log2(int value)
The value zero and one both return zero.
value
- The unsigned value to calculate log2 on.
public static int log2(long value)
The value zero and one both return a log2 result of zero.
value
- The unsigned value to calculate log2 on.
public static double pow(double x, double y)
x
- the base value.y
- the exponent.
public static long round(double a)
Special cases:
a
- a floating-point value to be rounded to a long.
Long.MAX_VALUE
,
Long.MIN_VALUE
public static int round(float a)
Special cases:
a
- a floating-point value to be rounded to an integer.
Integer.MAX_VALUE
,
Integer.MIN_VALUE
public static int wrap(int low, int value, int high)
This method does the opposite of clamp(int, int, int)
.
low
- Lower bound value; must be less than your upper bound parameter.value
- Value to wrap.high
- Upper bound value.
java.lang.IllegalArgumentException
- If you provide a low parameter value that is greater than your high parameter value.public static long wrap(long low, long value, long high)
This method does the opposite of clamp(long, long, long)
.
low
- Lower bound value; must be less than your upper bound parameter.value
- Value to wrap.high
- Upper bound value.
java.lang.IllegalArgumentException
- If you provide a low parameter value that is greater than your high parameter value.public static float wrap(float low, float value, float high)
This method does the opposite of clamp(float, float, float)
.
low
- Lower bound value; must be less than your upper bound parameter.value
- Value to wrap.high
- Upper bound value.
java.lang.IllegalArgumentException
- If you provide a low parameter value that is greater than your high parameter value.public static double wrap(double low, double value, double high)
This method does the opposite of clamp(double, double, double)
.
low
- Lower bound value; must be less than your upper bound parameter.value
- Value to wrap.high
- Upper bound value.
java.lang.IllegalArgumentException
- If you provide a low parameter value that is greater than your high parameter value.public static boolean isNegativeInfinity(float d)
d
- A single-precision floating point number.
Float.NEGATIVE_INFINITY
; otherwise, false.public static boolean isPositiveInfinity(float d)
d
- A single-precision floating point number.
Float.POSITIVE_INFINITY
; otherwise, false.public static boolean isNegativeInfinity(double d)
d
- A double-precision floating point number.
Double.NEGATIVE_INFINITY
; otherwise, false.public static boolean isPositiveInfinity(double d)
d
- A double-precision floating point number.
Double.POSITIVE_INFINITY
; otherwise, false.public static long bigMul(int a, int b)
a
- The first int to multiply.b
- The second int to multiply.
public static int divRem(int a, int b, RefLong result)
a
- The long that contains the dividend.b
- The long that contains the divisor.result
- The RefLong
that receives the remainder.
java.lang.ArithmeticException
- b is zero.public static double log(double a, double newBase)
a
- A number whose logarithm is to be found.newBase
- The base of the logarithm.
Double.POSITIVE_INFINITY
, -Infinity denotes Double.NEGATIVE_INFINITY
, and Double.NaN
denotes Double.NaN
.
a | newBase | Return Value |
---|---|---|
a> 0 | (0 <newBase < 1) -or-(newBase> 1) | lognewBase(a) \ |
a< 0 | (any value) | NaN |
(any value) | newBase< 0 | NaN |
a != 1 | newBase = 0 | NaN |
a != 1 | newBase = +Infinity | NaN |
a = NaN | (any value) | NaN |
(any value) |
newBase = NaN | NaN |
(any value) | newBase = 1 | NaN |
a = 0 |
0 <newBase< 1 | +Infinity |
a = 0 | newBase> 1 | -Infinity |
a = +Infinity |
0 <newBase< 1 | -Infinity |
a = +Infinity | newBase> 1 | +Infinity |
a = 1 | newBase = 0 | 0 |
a = 1 | newBase = +Infinity | 0 |
public static int sign(double value)
value
- A signed number.
java.lang.ArithmeticException
- value is equal to Double.NaN
.public static int sign(byte value)
value
- A signed number.
public static int sign(short value)
value
- A signed number.
public static int sign(int value)
value
- A signed number.
public static int sign(long value)
value
- A signed number.
public static int sign(float value)
value
- A signed number.
java.lang.ArithmeticException
- value is equal to Float.NaN
.public static double sinh(double value)
value
- An angle, measured in radians.
Double.NEGATIVE_INFINITY
, Double.POSITIVE_INFINITY
, or Double.NaN
, this method returns a Double
equal to value.public static double cosh(double value)
value
- An angle, measured in radians.
public static double tanh(double value)
value
- An angle, measured in radians.
Double.NEGATIVE_INFINITY
, this method returns -1. If value is equal to Double.POSITIVE_INFINITY
, this method returns 1. If value is equal to Double.NaN
, this method returns Double.NaN
.public static double nextDouble(double d)
d
- The double to get the next positive value of.
public static double previousDouble(double d)
d
- The double to get the next negative value of.
public static double nextDouble(double d, boolean positive)
d
- The number to get the next double of.positive
- Should the next value be the next positive value (adding) or negative value (subtraction).
public static float fpToFloat(int fp)
Float
. Certain predefined values are returned with calculation.
fp
- A 16.16 fixed-point number.
Float
that represents a fixed-point number.public static double fpToDouble(int fp)
Double
. Certain predefined values are returned with calculation.
fp
- A 16.16 fixed-point number.
Double
that represents a fixed-point number.public static int doubleToFP(float value)
Float
to a 16.16 fixed-point number. Certain predefined values are returned with calculation.
value
- A Float
number.
Float
.public static int doubleToFP(double value)
Double
to a 16.16 fixed-point number. Certain predefined values are returned with calculation.
value
- A Double
number.
Double
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |