|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--lava.math.MathToolbox
Miscellaneous mathematical operations.
Details: MathToolbox
is a collection of static methods for performing mathematical operations.
Field Summary | |
static double |
TWO_PI
Two times pi. |
Method Summary | |
static int |
compare(int i,
int j)
Compares two int s. |
static int |
compareUnsigned(int i,
int j)
Compares two int s as if they were 32-bit unsigned values. |
static java.math.BigInteger |
flipSignBits(java.math.BigInteger bi)
Flips the sign bits in a BigInteger. |
static int |
log2Ceiling(int n)
Computes the base-2 log ceiling of n. |
static double |
magnitude(double x,
double y)
Computes the magnitude of a 2D coordinate. |
static java.math.BigDecimal |
minimizeScale(java.math.BigDecimal bd)
Minimizes the scale of a BigDecimal to the greatest extent possible without rounding. |
static int |
mod(int value,
int lowerbound,
int upperbound)
Arbitrary modulus operation. |
static long |
overlap(long n0,
long l0,
long n1,
long l1)
Determines the number of overlapping integers in two ranges of integers. |
static java.math.BigDecimal |
setPrecision(java.math.BigDecimal bd,
int n)
Adjusts the fractional precision of a BigDecimal . |
static java.math.BigDecimal |
setSignificantDigits(java.math.BigDecimal bd,
int n)
Adjusts the number of significant digits in a BigDecimal . |
static int |
signum(int n)
Returns the sign of n. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final double TWO_PI
Details: TWO_PI is the value obtained when Math.PI is multiplied by 2. It is stored here for convenience.
Method Detail |
public static final long overlap(long n0, long l0, long n1, long l1)
n0
- the first integer in the first rangel0
- the extent (length) of the first rangen1
- the second integer in the second rangel1
- the extent (length) of the second rangepublic static final java.math.BigDecimal setSignificantDigits(java.math.BigDecimal bd, int n)
BigDecimal
.bd
- the value to adjustn
- the number of significant digitspublic static final java.math.BigDecimal setPrecision(java.math.BigDecimal bd, int n)
BigDecimal
.bd
- the value to adjustn
- the number of digits after the decimal pointpublic static final java.math.BigDecimal minimizeScale(java.math.BigDecimal bd)
BigDecimal
to the greatest extent possible without rounding.bd
- the BigDecimal
public static final int compare(int i, int j)
int
s. Returns -1 if i
< j
, 0 if i
= j
, or +1 if i
> j
.i
- the "left" value in the comparisonj
- the "right" value in the comparisonpublic static final int compareUnsigned(int i, int j)
int
s as if they were 32-bit unsigned values. Returns -1 if i
< j
, 0 if i
= j
, or +1 if i
> j
.i
- the "left" value in the comparisonj
- the "right" value in the comparisonpublic static final java.math.BigInteger flipSignBits(java.math.BigInteger bi)
Example: The bit representation of 3 is
000...00011.This method will change the value to
111...11111,or -1. (Elipses ("...") represent infinite repetition.)
The bit representation of -72 is
111...1110111000.This method will change the value to
000...0000111000,or 56.
bi
- the BigIntegerpublic static final double magnitude(double x, double y)
Details: magnitude computes the magnitude of a 2D coordinate, i.e., the distance from the origin.
To determine the phase of the coordinate, use java.lang.Math.atan2.
x
- x coordinatey
- y coordinatepublic static final int mod(int value, int lowerbound, int upperbound)
Details: The remainder operator %
is useful for performing modulus operations, but only if the range begins at 0 and the domain is non-negative. This method provides a more generic modulus operation because it allows negative domains and arbitrarily positioned ranges.
lowerbound
is the beginning of the range, and upperbound
is one more than the last value allowed in the range. (Obviously, upperbound - lowerbound
is the period of modulation.) value
is the value to modulate.
The returned value, retval, is such that:
lowerbound
<= retval
upperbound
(value -
retval)
is a multiple of (upperbound - lowerbound)
The % operator has these properties, too, but only for lowerbound == 0 and value >= 0.
value
- value to modulatelowerbound
- bottom of rangeupperbound
- top of rangepublic static final int log2Ceiling(int n)
Details: log2Ceiling returns the base-2 log of n, rounded up to the nearest whole integer. n is treated as a an unsigned int
. If n==0, -1 is returned.
n
- npublic static final int signum(int n)
Details: signum returns -1 if n<0, 0 if n==0, or +1 if n>0.
n
- n
|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |