|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectariba.util.core.MathUtil
public final class MathUtil
Math Utilities. These are helper functions for dealing with math.
| Method Summary | |
|---|---|
static int |
bound(int value,
int lower,
int upper)
Bounds value to be within lower and
upper, inclusively. |
static int |
forceEven(int n)
Returns the specified number with its least significant bit zeroed. |
static int |
forceOdd(int n)
Returns the specified number with its least significant bit set. |
static long |
fromBase36(String s)
Convert a string representation of a base36 number into a long. |
static long |
fromBase36(String s,
int offset)
Convert a string representation of a base36 number into a long. |
static long |
fromBase64(String s)
Convert a string representation of a base64 number into a long. |
static long |
fromBase64(String s,
int offset)
Convert a string representation of a base64 number into a long. |
static long |
fromBase64(String s,
int beginIndex,
int endIndex)
Convert a string representation of a base64 number into a long. |
static long |
getGCD(long a,
long b)
Calculate the greatest common denominator for two longs. |
static long |
getLCM(long a,
long b)
Calculate the least common multiple for two longs. |
static int |
log2(long x)
Calculate the log (base 2) of a specified long. |
static int |
modulo10(double d,
boolean round)
Returns the integer result of (d mod 10). |
static int |
normalHashCode(char[] val)
Private method that calculates the hash code for the char[] val according to the java spec. |
static List |
permutations(int n,
int r)
Returns a List of Lists, where each sub-List is a list of Integers representing one permutation of r numbers between 0 and n. |
static long |
power2(int x)
Calculate 2 raised to a specified power. |
static double |
powerOfTen(int power)
Calculate 10 raised to a specified power. |
static BigDecimal |
setScale(BigDecimal value,
int scale)
Adjust the scale of the given BigDecimal to the specified scale. |
static Double |
setScale(Double value,
int scale)
|
static int |
sgn(int a,
int b)
Returns the value of the sgn mathematical function (the
signum function) on the operands a and b. |
static int |
sgn(long a,
long b)
Returns the value of the sgn mathematical function (the
signum function) on the operands a and b. |
static int |
sunHashCode(char[] val)
Private method that calculates the hash code for the char[] val according to the sun's unique implementation which they say will be standard in 1.2 (love those standards) |
static String |
toBase36(long num)
Converts the given long into a base 36 string. |
static int |
toBase36(long num,
char[] chr,
int off)
Converts the given long into a base 36 string. |
static String |
toBase64(long num)
Converts the given long into a base 64 string. |
static int |
toBase64(long num,
char[] chr,
int off)
Converts the given long into a base 64 string. |
static long |
unsignedUniqueId(String s)
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static int log2(long x)
x - a long to calculate the log of
public static long power2(int x)
x - the power to raise 2 to, must be greater or equal to 0
public static int forceEven(int n)
n - an integer to make even
public static double powerOfTen(int power)
power - the power to raise 10 to
public static int modulo10(double d,
boolean round)
d - a double to mod against 10round - if true the double will be rounded to the
nearest long, if false floor() will be called.
public static int forceOdd(int n)
n - an integer to make odd
public static long getGCD(long a,
long b)
a - the first number in longb - the sencond number in long
public static long getLCM(long a,
long b)
a - the first number in longb - the sencond number in long
public static BigDecimal setScale(BigDecimal value,
int scale)
value - the BigDecimalscale - the scale, which can't be negative.
public static Double setScale(Double value,
int scale)
public static String toBase64(long num)
num - the number to convert into base 64
public static int toBase64(long num,
char[] chr,
int off)
num - the number to convert into base 64chr - the character array to insert the base 64
representation of the number intooff - the offset into the character array to start writing
public static long fromBase64(String s)
s - a String representation of a base 64 number
public static long fromBase64(String s,
int offset)
s - a String containing a representation of a base 64
numberoffset - the offset of the first character in the string
to start begin parsing at.
public static long fromBase64(String s,
int beginIndex,
int endIndex)
s - a String containing a representation of a base 64
numberbeginIndex - the offset of the first character in the string
to parse (inclusive).endIndex - the offset of the last character in the string
to parse (inclusive).
public static String toBase36(long num)
num - the number to convert into base 36
public static int toBase36(long num,
char[] chr,
int off)
num - the number to convert into base 36chr - the character array to insert the base 36
representation of the number intooff - the offset into the character array to start writing
public static long fromBase36(String s)
throws ParseException
s - a String representation of a base 36 number
ParseException - if the String s could not be
parsed
public static long fromBase36(String s,
int offset)
s - a String containing a representation of a base 36
numberoffset - the offset of the first character in the string
to start begin parsing at.
public static List permutations(int n,
int r)
n - upper limit of the range within which the members of the
permutation fallr - count of integers in the permutation
public static int sgn(int a,
int b)
sgn mathematical function (the
signum function) on the operands a and b.
The signum function returns -1 if a < b,
0 if a == b and +1 if a > b.
It serves as a safe way to determine how two integers compare.
Simply subtracting the integers and comparing the result with
zero can fail for numbers close to Integer.MAX_VALUE
and Integer.MIN_VALUE.
sgn function on the supplied
operands
public static int sgn(long a,
long b)
sgn mathematical function (the
signum function) on the operands a and b.
The signum function returns -1 if a < b,
0 if a == b and +1 if a > b.
It serves as a safe way to determine how two longs compare.
Simply subtracting the numbers and comparing the result with
zero can fail for numbers close to Long.MAX_VALUE
and Long.MIN_VALUE.
sgn function on the supplied
operands
public static int bound(int value,
int lower,
int upper)
value to be within lower and
upper, inclusively.
That is if value < lower then
lower is returned and if value > upper
then upper is returned, else value itself
is returned.
Note that if upper is less than lower, this
function returns as if upper is positive infinity.
value - the value to be boundedlower - the lower boundupper - the upper bound
public static final int sunHashCode(char[] val)
public static final int normalHashCode(char[] val)
public static final long unsignedUniqueId(String s)
s -
2 ^ 32
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||