Class BigNumberUtil


  • public final class BigNumberUtil
    extends Object
    Miscellaneous BigInteger and BigDecimal utilities
    • 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 check
        min - the inclusive minimum of the range
        max - 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 check
        min - the inclusive minimum of the range
        max - 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 divide
        denominator - 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 dividend
        bigDenominator - 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 dividend
        bigDenominator - the divisor
        context - 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 dividend
        bigDenominator - 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 dividend
        bigDenominator - the divisor
        context - 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 value
        baseMC - 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 value
        n - the root
        baseMC - the math context to use
        Returns:
        the nth root of num