Class BigUtil

java.lang.Object
com.zieglersoftware.num.BigUtil

public final class BigUtil
extends Object
Provides many static methods for more conveniently working with BigDecimal and BigInteger. Also provides some functionality that is not available at all with these classes; for example, raising a BigDecimal to the power of another BigDecimal.

Acquiring instances of BigDecimal and BigInteger is particularly easy with BigUtil. Simply call bd(arg) with any reasonable argument type to get a BigDecimal, and similarly bi(arg) to get a BigInteger. No need to think about whether to use a constructor or valueOf(), no risk of accidentally building a BigDecimal from a double the wrong way, and because then names bd and bi are fairly specific, unlike valueOf, it is practial to statically import them and get instances extremely succintly. Additionally, you can use the static fields BD0, BD1, BDM1, BI0, BI1, BIM1, BDPI, and BDE to acquire instances representing 0, 1, negative 1, pi, and e, and these can also be conveniently statically imported.

Comparison methods are provided for comparing two BigDecimals, two BigIntegers, or one of each. equal, notEqual, greater, less, greaterOrEqual, and lessOrEqual are all provided, so you can avoid the clutter of the (compareTo() <op> 0) idiom. Additionally, equal(BigDecimal, BigDecimal) works as you would hope it would work -- two numbers that differ only in trailing zeros after the decimal point are equal to one another. Convenience methods are provided for other comparisons as well, namely isPos, isNeg, isZero, and isOne.

isInt(BigDecimal) can be used to determine whether the value has a nonzero decimal component. wholePart(BigDecimal) and decimalPart(BigDecimal) return the value's desired component, and wholeAndDecimalParts(BigDecimal) is similar but represents the decimal part as an integer. fraction(BigDecimal) and mixedNumber(BigDecimal) return a fractional view of the value. digits(BigInteger) returns an array of the value's digits, and digits(BigDecimal) returns two arrays, one for the whole part and one for the decimal part. digitCount(BigInteger) returns the length of the value.

round(BigDecimal) methods are provided, one for rounding to a BigInteger value and another for rounding to a different BigDecimal value. Unlike BigDecimal.round(MathContext), BigUtil's round method rounds to the given number of decimal places as you would expect, rather than reducing the total number of significant figures to the given amount. It also removes any trailing decimal zeros and does not cause the string representation to change to exponential notation.

add, subtract, multiply, and divide methods are provided, taking BigDecimal, BigInteger, or a combination of the two as arguments. add and multiply can take a variable number of arguments so that a chain of additions and multiplications can be performed with one call. divide does not require the code clutter of specifying a number of digits to round to; if rounding is required, a very high precision result will be returned. If rounding is not required, the result will not include trailing decimal zeros.

pow can raise any BigInteger or BigDecimal to the power of any other BigInteger, BigDecimal, or long. sqrt and nthRoot are also provided, as are exp, ln, and log, all of which can take BigDecimal or BigInteger arguments.

Any calculation whose result requires rounding; i.e., an irrational number or a repeating decimal, will be returned with an extremely high precision (at least 100 significant figures).

  • Field Details

    • BD0

      public static final BigDecimal BD0
      The BigDecimal 0, with no decimal digits
    • BD1

      public static final BigDecimal BD1
      The BigDecimal 1, with no decimal digits
    • BDM1

      public static final BigDecimal BDM1
      The BigDecimal -1, with no decimal digits
    • BI0

      public static final BigInteger BI0
      The BigInteger 0
    • BI1

      public static final BigInteger BI1
      The BigInteger 1
    • BIM1

      public static final BigInteger BIM1
      The BigInteger -1
    • BDPI

      public static final BigDecimal BDPI
      A BigDecimal representation of pi approximated to 110 decimal places.
    • BDE

      public static final BigDecimal BDE
      A BigDecimal representation of e approximated to 110 decimal places.
  • Method Details

    • bd

      public static BigDecimal bd​(String val)
      Returns a BigDecimal representation of val.
    • bd

      public static BigDecimal bd​(double val)
      Returns a BigDecimal representation of val.
    • bd

      public static BigDecimal bd​(BigInteger val)
      Returns a BigDecimal representation of val.
    • bd

      public static BigDecimal bd​(long val)
      Returns a BigDecimal representation of val.
    • bi

      public static BigInteger bi​(String val)
      Returns a BigInteger representation of val.
    • bi

      public static BigInteger bi​(long val)
      Returns a BigInteger representation of val.
    • isPos

      public static boolean isPos​(BigDecimal val)
      Returns true if val is greater than 0, false otherwise.
    • isPos

      public static boolean isPos​(BigInteger val)
      Returns true if val is greater than 0, false otherwise.
    • isNeg

      public static boolean isNeg​(BigDecimal val)
      Returns true if val is less than 0, false otherwise.
    • isNeg

      public static boolean isNeg​(BigInteger val)
      Returns true if val is less than 0, false otherwise.
    • isZero

      public static boolean isZero​(BigDecimal val)
      Returns true if val is equal in magnitude to 0 (ignoring scale), false otherwise.
    • isZero

      public static boolean isZero​(BigInteger val)
      Returns true if val is equal to 0, false otherwise.
    • isOne

      public static boolean isOne​(BigDecimal val)
      Returns true if val is equal in magnitude to 1 (ignoring scale), false otherwise.
    • isOne

      public static boolean isOne​(BigInteger val)
      Returns true if val is equal to 1, false otherwise.
    • equal

      public static boolean equal​(BigDecimal a, BigDecimal b)
      Returns true if a and b are the same value, ignoring scale.
    • equal

      public static boolean equal​(BigDecimal a, BigInteger b)
      Returns true if a and b are the same value, ignoring the scale of a.
    • equal

      public static boolean equal​(BigInteger a, BigDecimal b)
      Returns true if a and b are the same value, ignoring the scale of b.
    • equal

      public static boolean equal​(BigInteger a, BigInteger b)
      Returns true if a and b are equal.
    • notEqual

      public static boolean notEqual​(BigDecimal a, BigDecimal b)
      Returns true if a and b are not the same value, ignoring scale.
    • notEqual

      public static boolean notEqual​(BigDecimal a, BigInteger b)
      Returns true if a and b are not the same value, ignoring the scale of a.
    • notEqual

      public static boolean notEqual​(BigInteger a, BigDecimal b)
      Returns true if a and b are not the same value, ignoring the scale of b.
    • notEqual

      public static boolean notEqual​(BigInteger a, BigInteger b)
      Returns true if a and b are not equal.
    • greater

      public static boolean greater​(BigDecimal a, BigDecimal b)
      Returns true if a is greater than b.
    • greater

      public static boolean greater​(BigDecimal a, BigInteger b)
      Returns true if a is greater than b.
    • greater

      public static boolean greater​(BigInteger a, BigDecimal b)
      Returns true if a is greater than b.
    • greater

      public static boolean greater​(BigInteger a, BigInteger b)
      Returns true if a is greater than b.
    • less

      public static boolean less​(BigDecimal a, BigDecimal b)
      Returns true if a is less than b.
    • less

      public static boolean less​(BigDecimal a, BigInteger b)
      Returns true if a is less than b.
    • less

      public static boolean less​(BigInteger a, BigDecimal b)
      Returns true if a is less than b.
    • less

      public static boolean less​(BigInteger a, BigInteger b)
      Returns true if a is less than b.
    • greaterOrEqual

      public static boolean greaterOrEqual​(BigDecimal a, BigDecimal b)
      Returns true if a is greater than or equal to b, ignoring scale.
    • greaterOrEqual

      public static boolean greaterOrEqual​(BigDecimal a, BigInteger b)
      Returns true if a is greater than or equal to b, ignoring the scale of a.
    • greaterOrEqual

      public static boolean greaterOrEqual​(BigInteger a, BigDecimal b)
      Returns true if a is greater than or equal to b, ignoring the scale of b.
    • greaterOrEqual

      public static boolean greaterOrEqual​(BigInteger a, BigInteger b)
      Returns true if a is greater than or equal to b.
    • lessOrEqual

      public static boolean lessOrEqual​(BigDecimal a, BigDecimal b)
      Returns true if a is less than or equal to b, ignoring scale.
    • lessOrEqual

      public static boolean lessOrEqual​(BigDecimal a, BigInteger b)
      Returns true if a is less than or equal to b, ignoring the scale of a.
    • lessOrEqual

      public static boolean lessOrEqual​(BigInteger a, BigDecimal b)
      Returns true if a is less than or equal to b, ignoring the scale of b.
    • lessOrEqual

      public static boolean lessOrEqual​(BigInteger a, BigInteger b)
      Returns true if a is less than or equal to b.
    • isInt

      public static boolean isInt​(BigDecimal val)
      Returns true if val is an integer, false otherwise. val is considered an integer if it has no decimal digits or if every decimal digit is a 0. val need not be able to fit into an int to be considered an integer.

      If this method returns true, val.toBigIntegerExact() would succeed. If this method returns false, that would fail.

      Examples:

        1000000000000000000000000000        → true
        1000000000000000000000000000.000000 → true
        1000000000000000000000000000.000001 → false
        0   → true
        0.0 → true
       -1000000000000000000000000000        → true
       -1000000000000000000000000000.000000 → true
       -1000000000000000000000000000.000001 → false
       
    • round

      public static BigInteger round​(BigDecimal val)
      Returns val rounded to the nearest BigInteger. Uses RoundingMode.HALF_UP.

      Examples:

        1.8 →  2
        1.5 →  2
        1.2 →  1
        1.0 →  1
        1   →  1
        0.8 →  1
        0.5 →  1
        0.2 →  0
        0.0 →  0
        0   →  0
       -0.2 →  0
       -0.5 → -1
       -0.8 → -1
       -1   → -1
       -1.0 → -1
       -1.2 → -1
       -1.5 → -2
       -1.8 → -2
       
    • round

      public static BigInteger round​(BigDecimal val, RoundingMode roundingMode)
      Returns val rounded to a BigInteger, using the given RoundingMode.
    • round

      public static BigDecimal round​(BigDecimal val, int decimalPlaces)
      Returns val rounded to the given number of decimal places. Uses RoundingMode.HALF_UP. decimalPlaces must be at least zero. If it is zero, the result will be a whole number.

      The result will not have any trailing zeros in the decimal part.

      Examples:

       10     , 0 → 10
       10     , 1 → 10
       10.0   , 0 → 10
       10.0   , 1 → 10
       10.01  , 0 → 10
       10.01  , 1 → 10
       10.01  , 2 → 10.01
        1.9803, 0 →  2
        1.9803, 1 →  2
        1.9803, 2 →  1.98
        1.9805, 3 →  1.981
        1.9803, 5 →  1.9803
        0.00  , 4 →  0
       -1.0   , 1 → -1
       -1.55  , 0 → -2
       -1.55  , 1 → -1.6
       -1.55  , 2 → -1.55
       -1.55  , 3 → -1.55
       
    • round

      public static BigDecimal round​(BigDecimal val, int decimalPlaces, RoundingMode roundingMode)
      Returns val rounded to the given number of decimal places, using the given RoundingMode. decimalPlaces must be at least zero. If it is zero, the result will be a whole number.

      The result will not have any trailing zeros in the decimal part.

    • wholePart

      public static BigInteger wholePart​(BigDecimal val)
      Returns the whole number part of val. The returned value will have the same sign sign as val, unless val is a negative number between 0 and -1, in which case the returned value will be 0.

      Examples:

        3.80 →   3
        3.0  →   3
        3    →   3
        0.5  →   0
        0    →   0
       -0.5  →   0
       -3.80 →  -3
       -3.0  →  -3
       -3    →  -3
       
    • decimalPart

      public static BigDecimal decimalPart​(BigDecimal val)
      Returns the decimal part of val (as a decimal, not scaled to an integer value). The returned value will have the same sign sign as val, unless val is an integer, in which case 0 will be returned. Any trailing zeros will be removed.

      To have the decimal part represented as an integer, use wholeAndDecimalParts(BigDecimal).

      Examples:

        3.80 →  0.8
        3.0  →  0
        3    →  0
        0.5  →  0.5
        0    →  0
       -0.5  → -0.5
       -3.80 → -0.8
       -3.0  →  0
       -3    →  0
       
    • wholeAndDecimalParts

      public static BigInteger[] wholeAndDecimalParts​(BigDecimal val)
      Returns a 2-element array of BigIntegers that represents the whole part and the decimal part of val.

      The first element of the array is equivalent to wholePart(BigDecimal). The second element is equivalent to decimalPart(BigDecimal), but scaled as an integer.

      Examples:

        3.80 → [ 3,  8]
        3.0  → [ 3,  0]
        3    → [ 3,  0]
        0.5  → [ 0,  5]
        0    → [ 0,  0]
       -3.80 → [-3, -8]
       -3.0  → [-3,  0]
       -3    → [-3,  0]
       -0.5  → [ 0, -5]
       
    • mixedNumber

      public static BigInteger[] mixedNumber​(BigDecimal val)
      Returns a mixed number representation of val, i.e., a+b/c, where a is the whole part of val, b is the decimal part scaled as an integer, and c is 10 raised to the power of the number of decimal digits. Note that the b/c fraction will not necessarily be reduced.

      The returned value is a 3-element array of BigIntegers, consisting of:

      1. wholeAndDecimalParts(BigDecimal)[0]
      2. wholeAndDecimalParts[1]
      3. 10 raised to the power of the number of decimal digits in val, excluding trailing zeros. (1 if val is an integer.)

      Examples:

        3.80 → [ 3,  8, 10]
        3.0  → [ 3,  0,  1]
        3    → [ 3,  0,  1]
        0.5  → [ 0,  5, 10]
        0    → [ 0,  0,  1]
       -3.80 → [-3, -8, 10]
       -3.0  → [-3,  0,  1]
       -3    → [-3,  0,  1]
       -0.5  → [ 0, -5, 10]
       
    • fraction

      public static BigInteger[] fraction​(BigDecimal val)
      Returns a fraction representation of val.

      The returned value is a 2-element array of BigIntegers, consisting of:

      1. mixedNumber(BigDecimal)[0] * mixedNumber[2] + mixedNumber[1]
      2. mixedNumber[2]
      Note that the fraction will not necessarily be reduced.

      Examples:

        3.80 → [ 38, 10]
        3.0  → [  3,  1]
        3    → [  3,  1]
        0.5  → [  5, 10]
        0    → [  0,  1]
       -3.80 → [-38, 10]
       -3.0  → [- 3,  1]
       -3    → [- 3,  1]
       -0.5  → [- 5, 10]
       
    • digits

      public static int[][] digits​(BigDecimal val)
      Returns 2 arrays, the first of which contains the digits of val before the decimal point, and the second of which contains the digits after the decimal point. If val is an integer, the second array will be empty. The second array will never have trailing zeros.

      val may negative, but the returned arrays will never include any negative digits.

      Examples:

        123.45600 → [ [1,2,3], [4,5,6] ]
          3.0     → [ [3],     []      ]
          3       → [ [3],     []      ]
          0.5     → [ [0],     [5]     ]
          0       → [ [0],     []      ]
       -  3.0     → [ [3],     []      ]
       -123.45600 → [ [1,2,3], [4,5,6] ]
       
    • digits

      public static int[] digits​(BigInteger val)
      Returns the digits of val.

      val may negative, but the returned array will never include any negative digits.

      Examples:

        123 → [1,2,3]
          3 → [3]
          0 → [0]
         -3 → [3]
       -123 → [1,2,3]
       
    • digitCount

      public static int digitCount​(BigInteger val)
      Returns the number of digits of val.

      val may negative, but this method only considers abs(val). If val is 0, 1 is returned.

      Examples:

        123 → 3
          3 → 1
          0 → 1
         -3 → 1
       -123 → 3
       
    • add

      public static BigDecimal add​(BigDecimal a, BigDecimal b, BigDecimal... others)
      Returns the sum of the given values.
    • add

      public static BigDecimal add​(BigDecimal a, BigInteger b, BigInteger... others)
      Returns the sum of the given values.
    • add

      public static BigDecimal add​(BigInteger a, BigDecimal b, BigDecimal... others)
      Returns the sum of the given values.
    • add

      public static BigInteger add​(BigInteger a, BigInteger b, BigInteger... others)
      Returns the sum of the given values.
    • subtract

      public static BigDecimal subtract​(BigDecimal a, BigDecimal b)
      Returns a minus b.
    • subtract

      public static BigDecimal subtract​(BigDecimal a, BigInteger b)
      Returns a minus b.
    • subtract

      public static BigDecimal subtract​(BigInteger a, BigDecimal b)
      Returns a minus b.
    • subtract

      public static BigInteger subtract​(BigInteger a, BigInteger b)
      Returns a minus b.
    • multiply

      public static BigDecimal multiply​(BigDecimal a, BigDecimal b, BigDecimal... others)
      Returns the product of the given values.
    • multiply

      public static BigDecimal multiply​(BigDecimal a, BigInteger b, BigInteger... others)
      Returns the product of the given values.
    • multiply

      public static BigDecimal multiply​(BigInteger a, BigDecimal b, BigDecimal... others)
      Returns the product of the given values.
    • multiply

      public static BigInteger multiply​(BigInteger a, BigInteger b, BigInteger... others)
      Returns the product of the given values.
    • divide

      public static BigDecimal divide​(BigDecimal a, BigDecimal b)
      Returns a divided by b. If rounding is necessary because the result is a non-terminating decimal, the result will be rounded to a large number of significant figures (at least 100). The result will not have trailing decimal zeros.
    • divide

      public static BigDecimal divide​(BigDecimal a, BigInteger b)
      Returns a divided by b. If rounding is necessary because the result is a non-terminating decimal, the result will be rounded to a large number of significant figures (at least 100). The result will not have trailing decimal zeros.
    • divide

      public static BigDecimal divide​(BigInteger a, BigDecimal b)
      Returns a divided by b. If rounding is necessary because the result is a non-terminating decimal, the result will be rounded to a large number of significant figures (at least 100). The result will not have trailing decimal zeros.
    • divide

      public static BigDecimal divide​(BigInteger a, BigInteger b)
      Returns a divided by b. Note that even though the arguments are BigInteger, the result is a BigDecimal to allow decimal digits in the result. If rounding is necessary because the result is a non-terminating decimal, the result will be rounded to a large number of significant figures (at least 100). The result will not have trailing decimal zeros.
    • invert

      public static BigDecimal invert​(BigDecimal val)
      Returns 1/val. If rounding is necessary because the result is a non-terminating decimal, the result will be rounded to a large number of significant figures (at least 100). The result will not have trailing decimal zeros.
    • invert

      public static BigDecimal invert​(BigInteger val)
      Returns 1/val. Note that even though the argument is a BigInteger, the result is a BigDecimal to allow decimal digits in the result. If rounding is necessary because the result is a non-terminating decimal, the result will be rounded to a large number of significant figures (at least 100). The result will not have trailing decimal zeros.
    • pow

      public static BigDecimal pow​(BigDecimal base, long power)
      Returns base^power.

      If base is 0, power must be greater than 0. Will succeed without overflow if abs(base) is less than 1,000,000,000,000,000,000,000 and abs(power) is less than 100,000,000. If one value is smaller than its limit and the other value is somewhat larger than its limit, the calculation might succeed.

    • pow

      public static BigDecimal pow​(BigDecimal base, BigInteger power)
      Returns base^power.

      If base is 0, power must be greater than 0. Will succeed without overflow if abs(base) is less than 1,000,000,000,000,000,000,000 and abs(power) is less than 100,000,000. If one value is smaller than its limit and the other value is somewhat larger than its limit, the calculation might succeed.

    • pow

      public static BigDecimal pow​(BigDecimal base, BigDecimal power)
      Returns base^power.

      If base is negative, power must either be an integer or a number that can be expressed as a fraction with an odd denominator.

      If base is 0, power must be greater than 0. Will succeed without overflow if abs(base) is less than 1,000,000,000,000,000,000,000 and abs(power) is less than 100,000,000. If one value is smaller than its limit and the other value is somewhat larger than its limit, the calculation might succeed.

    • pow

      public static BigDecimal pow​(BigInteger base, long power)
      Returns base^power.

      If base is 0, power must be greater than 0. Will succeed without overflow if abs(base) is less than 1,000,000,000,000,000,000,000 and abs(power) is less than 100,000,000. If one value is smaller than its limit and the other value is somewhat larger than its limit, the calculation might succeed.

      Returns a BigDecimal since the result may not be an integer (when power is negative).

    • pow

      public static BigDecimal pow​(BigInteger base, BigInteger power)
      Returns base^power.

      If base is 0, power must be greater than 0. Will succeed without overflow if abs(base) is less than 1,000,000,000,000,000,000,000 and abs(power) is less than 100,000,000. If one value is smaller than its limit and the other value is somewhat larger than its limit, the calculation might succeed.

      Returns a BigDecimal since the result may not be an integer (when power is negative).

    • pow

      public static BigDecimal pow​(BigInteger base, BigDecimal power)
      Returns base^power.

      If base is negative, power must either be an integer or a number that can be expressed as a fraction with an odd denominator.

      If base is 0, power must be greater than 0. Will succeed without overflow if abs(base) is less than 1,000,000,000,000,000,000,000 and abs(power) is less than 100,000,000. If one value is smaller than its limit and the other value is somewhat larger than its limit, the calculation might succeed.

    • nthRoot

      public static BigDecimal nthRoot​(BigDecimal base, long n)
      Equivalent to pow(BigDecimal, BigDecimal) with invert(n) as the exponent, except that n must be greater than zero, and in the case that base is negative, n is odd, and invert(n) can't be expressed exactly as a decimal, this method will succeed whereas pow(base, invert(n)) will likely fail due to representing the denominator of the exponent as an even number rather than odd.

      Examples:

        nthRoot(-1, 3)          → -1
            pow(-1, 0.33333...)ArithmeticException
        nthRoot(-8, 3)          → -2
            pow(-8, 0.33333...)ArithmeticException
        nthRoot(pow(-8, 5)), 3) → -32
            pow(-8, 1.6666...)ArithmeticException
        nthRoot( 1, 3)          → 1
            pow( 1, 0.33333...) → 1
        nthRoot( 8, 3)          → 2
            pow( 8, 0.33333...) → 2
       
    • nthRoot

      public static BigDecimal nthRoot​(BigDecimal base, BigInteger n)
      Equivalent to pow(BigDecimal, BigDecimal) with invert(n) as the exponent, except that n must be greater than zero, and in the case that base is negative, n is odd, and invert(n) can't be expressed exactly as a decimal, this method will succeed whereas pow(base, invert(n)) will likely fail due to representing the denominator of the exponent as an even number rather than odd.

      Examples:

        nthRoot(-1, 3)          → -1
            pow(-1, 0.33333...)ArithmeticException
        nthRoot(-8, 3)          → -2
            pow(-8, 0.33333...)ArithmeticException
        nthRoot(pow(-8, 5)), 3) → -32
            pow(-8, 1.6666...)ArithmeticException
        nthRoot( 1, 3)          → 1
            pow( 1, 0.33333...) → 1
        nthRoot( 8, 3)          → 2
            pow( 8, 0.33333...) → 2
       
    • nthRoot

      public static BigDecimal nthRoot​(BigInteger base, long n)
      Equivalent to pow(BigDecimal, BigDecimal) with invert(n) as the exponent, except that n must be greater than zero, and in the case that base is negative, n is odd, and invert(n) can't be expressed exactly as a decimal, this method will succeed whereas pow(base, invert(n)) will likely fail due to representing the denominator of the exponent as an even number rather than odd.

      Examples:

        nthRoot(-1, 3)          → -1
            pow(-1, 0.33333...)ArithmeticException
        nthRoot(-8, 3)          → -2
            pow(-8, 0.33333...)ArithmeticException
        nthRoot(pow(-8, 5)), 3) → -32
            pow(-8, 1.6666...)ArithmeticException
        nthRoot( 1, 3)          → 1
            pow( 1, 0.33333...) → 1
        nthRoot( 8, 3)          → 2
            pow( 8, 0.33333...) → 2
       
    • nthRoot

      public static BigDecimal nthRoot​(BigInteger base, BigInteger n)
      Equivalent to pow(BigDecimal, BigDecimal) with invert(n) as the exponent, except that n must be greater than zero, and in the case that base is negative, n is odd, and invert(n) can't be expressed exactly as a decimal, this method will succeed whereas pow(base, invert(n)) will likely fail due to representing the denominator of the exponent as an even number rather than odd.

      Examples:

        nthRoot(-1, 3)          → -1
            pow(-1, 0.33333...)ArithmeticException
        nthRoot(-8, 3)          → -2
            pow(-8, 0.33333...)ArithmeticException
        nthRoot(pow(-8, 5)), 3) → -32
            pow(-8, 1.6666...)ArithmeticException
        nthRoot( 1, 3)          → 1
            pow( 1, 0.33333...) → 1
        nthRoot( 8, 3)          → 2
            pow( 8, 0.33333...) → 2
       
    • sqrt

      public static BigDecimal sqrt​(BigDecimal val)
      Returns the square root of the given value. val must be non-negative.
    • sqrt

      public static BigDecimal sqrt​(BigInteger val)
      Returns the square root of the given value. val must be non-negative.
    • exp

      public static BigDecimal exp​(long power)
      Returns e^power.

      abs(power) must be less or equal to 4,900,000,000.

    • exp

      public static BigDecimal exp​(BigInteger power)
      Returns e^power.

      abs(power) must be less or equal to 4,900,000,000.

    • exp

      public static BigDecimal exp​(BigDecimal power)
      Returns e^power.

      abs(power) must be less or equal to 4,900,000,000.

    • ln

      public static BigDecimal ln​(long val)
      Returns the natural logarithm of val.

      val must be greater than 0.

    • ln

      public static BigDecimal ln​(BigInteger val)
      Returns the natural logarithm of val.

      val must be greater than 0. More specifically, val must be greater than 10^-10,000,000 and less than 10^10,000,000.

    • ln

      public static BigDecimal ln​(BigDecimal val)
      Returns the natural logarithm of val.

      val must be greater than 0. More specifically, val must be greater than 10^-10,000,000 and less than 10^10,000,000.

    • log

      public static BigDecimal log​(long base, long val)
      Returns the log of the given base of val.

      base must be greater than 0 and not equal to 1. val must be greater than 0.

    • log

      public static BigDecimal log​(BigInteger base, long val)
      Returns the log of the given base of val.

      base must be greater than 0 and not equal to 1. val must be greater than 0.

    • log

      public static BigDecimal log​(BigDecimal base, long val)
      Returns the log of the given base of val.

      base must be greater than 0 and not equal to 1. val must be greater than 0.

    • log

      public static BigDecimal log​(long base, BigInteger val)
      Returns the log of the given base of val.

      base must be greater than 0 and not equal to 1. val must be greater than 0.

    • log

      public static BigDecimal log​(BigInteger base, BigInteger val)
      Returns the log of the given base of val.

      base must be greater than 0 and not equal to 1. val must be greater than 0.

    • log

      public static BigDecimal log​(BigDecimal base, BigInteger val)
      Returns the log of the given base of val.

      base must be greater than 0 and not equal to 1. val must be greater than 0.

    • log

      public static BigDecimal log​(long base, BigDecimal val)
      Returns the log of the given base of val.

      base must be greater than 0 and not equal to 1. val must be greater than 0.

    • log

      public static BigDecimal log​(BigInteger base, BigDecimal val)
      Returns the log of the given base of val.

      base must be greater than 0 and not equal to 1. val must be greater than 0.

    • log

      public static BigDecimal log​(BigDecimal base, BigDecimal val)
      Returns the log of the given base of val.

      base must be greater than 0 and not equal to 1. val must be greater than 0.