- 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 BigInteger
BYTE_MAX
static BigInteger
BYTE_MIN
static BigDecimal
DOUBLE_MAX
static BigDecimal
DOUBLE_MIN
static BigDecimal
FLOAT_MAX
static BigDecimal
FLOAT_MIN
static BigInteger
INTEGER_MAX
static BigInteger
INTEGER_MIN
static BigInteger
LONG_MAX
static BigInteger
LONG_MIN
static BigInteger
SHORT_MAX
static BigInteger
SHORT_MIN
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BigDecimal
divide(BigDecimal bigNumerator, long denominator)
Divides a BigDecimal by a long while preserving scale.static BigDecimal
divide(BigDecimal bigNumerator, BigDecimal bigDenominator)
Divides a BigDecimal by a BigDecimal.static BigDecimal
divide(BigDecimal bigNumerator, BigDecimal bigDenominator, MathContext context)
Divides a BigDecimal by a BigDecimal.static boolean
isInByteRange(Number number)
Checks to see if a number is in the valid range for a Byte type.static boolean
isInDoubleRange(Number number)
Checks to see if a number is in the valid range for a Double type.static boolean
isInFloatRange(Number number)
Checks to see if a number is in the valid range for a Float type.static boolean
isInIntegerRange(Number number)
Checks to see if a number is in the valid range for a Integer type.static boolean
isInLongRange(Number number)
Checks to see if a number is in the valid range for a Long type.static boolean
isInRange(Number number, BigDecimal min, BigDecimal max)
Checks to see if a number is within the specified range.static boolean
isInRange(Number number, BigInteger min, BigInteger max)
Checks to see if a number is within the specified range.static boolean
isInShortRange(Number number)
Checks to see if a number is in the valid range for a Short type.static BigDecimal
remainder(BigDecimal bigNumerator, BigDecimal bigDenominator)
Divides a BigDecimal by a BigDecimal and returns the remainder.static BigDecimal
remainder(BigDecimal bigNumerator, BigDecimal bigDenominator, MathContext context)
Divides a BigDecimal by a BigDecimal and returns the remainder.static BigDecimal
root(BigDecimal num, int n, MathContext baseMC)
Calculates the nth root of a BigDecimal.static BigDecimal
sqrt(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
-
-