- java.lang.Object
-
- com.pervasive.datarush.commons.util.BigNumberUtil
-
public final class BigNumberUtil extends Object
Miscellaneous BigInteger and BigDecimal utilities
-
-
Field Summary
Fields Modifier and Type Field Description static BigIntegerBYTE_MAXstatic BigIntegerBYTE_MINstatic BigDecimalDOUBLE_MAXstatic BigDecimalDOUBLE_MINstatic BigDecimalFLOAT_MAXstatic BigDecimalFLOAT_MINstatic BigIntegerINTEGER_MAXstatic BigIntegerINTEGER_MINstatic BigIntegerLONG_MAXstatic BigIntegerLONG_MINstatic BigIntegerSHORT_MAXstatic BigIntegerSHORT_MIN
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BigDecimaldivide(BigDecimal bigNumerator, long denominator)Divides a BigDecimal by a long while preserving scale.static BigDecimaldivide(BigDecimal bigNumerator, BigDecimal bigDenominator)Divides a BigDecimal by a BigDecimal.static BigDecimaldivide(BigDecimal bigNumerator, BigDecimal bigDenominator, MathContext context)Divides a BigDecimal by a BigDecimal.static booleanisInByteRange(Number number)Checks to see if a number is in the valid range for a Byte type.static booleanisInDoubleRange(Number number)Checks to see if a number is in the valid range for a Double type.static booleanisInFloatRange(Number number)Checks to see if a number is in the valid range for a Float type.static booleanisInIntegerRange(Number number)Checks to see if a number is in the valid range for a Integer type.static booleanisInLongRange(Number number)Checks to see if a number is in the valid range for a Long type.static booleanisInRange(Number number, BigDecimal min, BigDecimal max)Checks to see if a number is within the specified range.static booleanisInRange(Number number, BigInteger min, BigInteger max)Checks to see if a number is within the specified range.static booleanisInShortRange(Number number)Checks to see if a number is in the valid range for a Short type.static BigDecimalremainder(BigDecimal bigNumerator, BigDecimal bigDenominator)Divides a BigDecimal by a BigDecimal and returns the remainder.static BigDecimalremainder(BigDecimal bigNumerator, BigDecimal bigDenominator, MathContext context)Divides a BigDecimal by a BigDecimal and returns the remainder.static BigDecimalroot(BigDecimal num, int n, MathContext baseMC)Calculates the nth root of a BigDecimal.static BigDecimalsqrt(BigDecimal num, MathContext baseMC)Calculates the square root of a BigDecimal.
-
-
-
Field Detail
-
BYTE_MIN
public static final BigInteger BYTE_MIN
-
BYTE_MAX
public static final BigInteger BYTE_MAX
-
SHORT_MIN
public static final BigInteger SHORT_MIN
-
SHORT_MAX
public static final BigInteger SHORT_MAX
-
INTEGER_MIN
public static final BigInteger INTEGER_MIN
-
INTEGER_MAX
public static final BigInteger INTEGER_MAX
-
LONG_MIN
public static final BigInteger LONG_MIN
-
LONG_MAX
public static final BigInteger LONG_MAX
-
FLOAT_MIN
public static final BigDecimal FLOAT_MIN
-
FLOAT_MAX
public static final BigDecimal FLOAT_MAX
-
DOUBLE_MIN
public static final BigDecimal DOUBLE_MIN
-
DOUBLE_MAX
public static final BigDecimal DOUBLE_MAX
-
-
Method Detail
-
isInByteRange
public static boolean isInByteRange(Number number)
Checks to see if a number is in the valid range for a Byte type.- Parameters:
number- the number to check- Returns:
- true if in range
-
isInShortRange
public static boolean isInShortRange(Number number)
Checks to see if a number is in the valid range for a Short type.- Parameters:
number- the number to check- Returns:
- true if in range
-
isInIntegerRange
public static boolean isInIntegerRange(Number number)
Checks to see if a number is in the valid range for a Integer type.- Parameters:
number- the number to check- Returns:
- true if in range
-
isInLongRange
public static boolean isInLongRange(Number number)
Checks to see if a number is in the valid range for a Long type.- Parameters:
number- the number to check- Returns:
- true if in range
-
isInFloatRange
public static boolean isInFloatRange(Number number)
Checks to see if a number is in the valid range for a Float type.- Parameters:
number- the number to check- Returns:
- true if in range
-
isInDoubleRange
public static boolean isInDoubleRange(Number number)
Checks to see if a number is in the valid range for a Double type.- Parameters:
number- the number to check- Returns:
- true if in range
-
isInRange
public static boolean isInRange(Number number, BigInteger min, BigInteger max)
Checks to see if a number is within the specified range.- Parameters:
number- the number to checkmin- the inclusive minimum of the rangemax- the inclusive maximum of the range- Returns:
- true if in range
-
isInRange
public static boolean isInRange(Number number, BigDecimal min, BigDecimal max)
Checks to see if a number is within the specified range.- Parameters:
number- the number to checkmin- the inclusive minimum of the rangemax- the inclusive maximum of the range- Returns:
- true if in range
-
divide
public static BigDecimal divide(BigDecimal bigNumerator, long denominator)
Divides a BigDecimal by a long while preserving scale.- Parameters:
bigNumerator- the BigDecimal to dividedenominator- value to divide by- Returns:
- the quotient of the division
-
divide
public static BigDecimal divide(BigDecimal bigNumerator, BigDecimal bigDenominator)
Divides a BigDecimal by a BigDecimal. This method will return null if the divisor is zero.- Parameters:
bigNumerator- the dividendbigDenominator- the divisor- Returns:
- the quotient of the division
-
divide
public static BigDecimal divide(BigDecimal bigNumerator, BigDecimal bigDenominator, MathContext context)
Divides a BigDecimal by a BigDecimal. This method will return null if the divisor is zero.- Parameters:
bigNumerator- the dividendbigDenominator- the divisorcontext- the context to use- Returns:
- the quotient of the division
-
remainder
public static BigDecimal remainder(BigDecimal bigNumerator, BigDecimal bigDenominator)
Divides a BigDecimal by a BigDecimal and returns the remainder. This method will return null if the divisor is zero.- Parameters:
bigNumerator- the dividendbigDenominator- the divisor- Returns:
- the remainder of the division
-
remainder
public static BigDecimal remainder(BigDecimal bigNumerator, BigDecimal bigDenominator, MathContext context)
Divides a BigDecimal by a BigDecimal and returns the remainder. This method will return null if the divisor is zero.- Parameters:
bigNumerator- the dividendbigDenominator- the divisorcontext- the context to use- Returns:
- the remainder of the division
-
sqrt
public static BigDecimal sqrt(BigDecimal num, MathContext baseMC)
Calculates the square root of a BigDecimal.- Parameters:
num- a valuebaseMC- the math context to use- Returns:
- the square root of num
-
root
public static BigDecimal root(BigDecimal num, int n, MathContext baseMC)
Calculates the nth root of a BigDecimal.- Parameters:
num- a valuen- the rootbaseMC- the math context to use- Returns:
- the nth root of num
-
-