All Packages Class Hierarchy This Package Previous Next Index
Class com.ibm.eou.toolkit.util.MathUtils
java.lang.Object
|
+----com.ibm.eou.toolkit.util.MathUtils
- public class MathUtils
- extends Object
This class provides math utility functions.
-
getHighestCommonFactor(int, int)
- Return the highest common factor of two integers.
-
getHighestCommonFactor(long, long)
- Return the highest common factor of two integers.
-
getNumberOfBits(int)
- Return the number of bits required to store the given
integer.
-
getNumberOfDigits(int, int)
- Return the number of digits required to represent the
given integer in the given base.
-
pow(int, int)
- Raises an integer to a positive integer exponent.
-
roundDownToNextMultiple(int, int)
- Round down the passed in value according to
the passed in multiple.
-
roundUpToNextMultiple(int, int)
- Round up the passed in value according to
the passed in multiple.
getHighestCommonFactor
public static int getHighestCommonFactor(int a,
int b)
- Return the highest common factor of two integers.
If either integer is zero, zero is returned.
Otherwise, Euclid's algorithm is employed.
getHighestCommonFactor
public static long getHighestCommonFactor(long a,
long b)
- Return the highest common factor of two integers.
If either integer is zero, zero is returned.
Otherwise, Euclid's algorithm is employed.
getNumberOfBits
public static int getNumberOfBits(int x)
- Return the number of bits required to store the given
integer. That is, the smallest N such that ANDing the
given integer with (1<
getNumberOfDigits
public static int getNumberOfDigits(int x,
int base)
- Return the number of digits required to represent the
given integer in the given base.
roundUpToNextMultiple
public static int roundUpToNextMultiple(int value,
int multiple)
- Round up the passed in value according to
the passed in multiple. Both positive and
negative multiples are dealt with correctly.
- Parameters:
- value - the integer to be rounded
- multiple - the integer to which value is
to be rounded up to
- Returns:
- the rounded value
- Throws: IllegalArgumentException
- thrown if multiple is zero
- See Also:
- roundDownToNextMultiple
roundDownToNextMultiple
public static int roundDownToNextMultiple(int value,
int multiple)
- Round down the passed in value according to
the passed in multiple. Both positive and
negative multiples are dealt with correctly.
- Parameters:
- value - the integer to be rounded
- multiple - the integer to which value is
to be rounded down to
- Returns:
- the rounded value
- Throws: IllegalArgumentException
- thrown if multiple is zero
- See Also:
- roundUpToNextMultiple
pow
public static int pow(int number,
int exponent)
- Raises an integer to a positive integer exponent.
- Parameters:
- number - the number to be raised by the specified power
- exponent - the power to which the number will be raised
- Returns:
- the number raised to the exponent
- Throws: IllegalArgumentException
- thrown if exponent is not postive
All Packages Class Hierarchy This Package Previous Next Index