The mathIT Library
A Java™ API for mathematics
org.mathIT.numbers

## Class BigNumbers

• ```public class BigNumbers
extends Object```
This class provides basic analytical and number theoretic functions for big numbers.
Version:
1.1
Author:
Andreas de Vries
• ### Field Summary

Fields
Modifier and Type Field and Description
`static BigDecimal` `E`
The constant e, the base of the natural logarithms.
`static BigDecimal` `GAMMA`
Euler-Mascheroni constant γ.
`static MathContext` `MATH_CONTEXT`
This math context is used throughout this class.
`static BigDecimal` `ONE_DOT`
The number 1 as a BigDecimal.
`static BigDecimal` `ONE_HALF`
The number 1/2 as a BigDecimal.
`static BigDecimal` `ONE_SIXTH`
The number 1/6 as a BigDecimal.
`static BigDecimal` `ONE_THIRD`
The number 1/3 as a BigDecimal.
`static BigDecimal` `PI`
The constant π, the ratio of the circumference of a circle to its diameter.
`static BigDecimal` `PI_2`
The constant π/2.
`static BigDecimal` `PI_4`
The constant π/4.
`static BigDecimal` `PI3_2`
The constant 3π/2.
`static BigDecimal` `PI3_4`
The constant 3π/4.
`static BigDecimal` `PI5_4`
The constant 5π/4.
`static BigDecimal` `PI7_4`
The constant 7π/4.
`static int` `PRECISION`
Maximum precision of BigDecimals, having the value 50.
`static BigDecimal` `RADIANS`
The constant 2π/360, the ratio of 1 radians per degree.
`static BigDecimal` `RAMANUJAN`
Ramanujan's constant eπ √163, up to an accuracy of 10-102.
`static BigDecimal` `ROOT_10_TWO`
10th root of 2.
`static BigDecimal` `SQRT_ONE_HALF`
Square root of 1/2.
`static BigDecimal` `SQRT_TWO`
Square root of 2.
`static BigDecimal` `TEN_DOT`
The number 10 as a BigDecimal.
`static BigInteger` `THREE`
The BigInteger constant three.
`static BigInteger` `TWO`
The BigInteger constant two.
`static BigDecimal` `TWO_DOT`
The number 2 as a BigDecimal.
`static BigDecimal` `ZERO_DOT`
The number 0 as a BigDecimal.
`static BigDecimal` `ZETA_10`
The value of the Riemann Zeta function ζ(10).
`static BigDecimal` `ZETA_11`
The value of the Riemann Zeta function ζ(11).
`static BigDecimal` `ZETA_12`
The value of the Riemann Zeta function ζ(12).
`static BigDecimal` `ZETA_13`
The value of the Riemann Zeta function ζ(13).
`static BigDecimal` `ZETA_14`
The value of the Riemann Zeta function ζ(14).
`static BigDecimal` `ZETA_15`
The value of the Riemann Zeta function ζ(15).
`static BigDecimal` `ZETA_16`
The value of the Riemann Zeta function ζ(16).
`static BigDecimal` `ZETA_17`
The value of the Riemann Zeta function ζ(17).
`static BigDecimal` `ZETA_18`
The value of the Riemann Zeta function ζ(18).
`static BigDecimal` `ZETA_19`
The value of the Riemann Zeta function ζ(19).
`static BigDecimal` `ZETA_2`
The value of the Riemann Zeta function ζ(2) = π2/6.
`static BigDecimal` `ZETA_20`
The value of the Riemann Zeta function ζ(20).
`static BigDecimal` `ZETA_21`
The value of the Riemann Zeta function ζ(21).
`static BigDecimal` `ZETA_23`
The value of the Riemann Zeta function ζ(23).
`static BigDecimal` `ZETA_25`
The value of the Riemann Zeta function ζ(25).
`static BigDecimal` `ZETA_3`
The value of the Riemann Zeta function ζ(3), also called Apéry's constant.
`static BigDecimal` `ZETA_4`
The value of the Riemann Zeta function ζ(4) = π6/945.
`static BigDecimal` `ZETA_5`
The value of the Riemann Zeta function ζ(5).
`static BigDecimal` `ZETA_6`
The value of the Riemann Zeta function ζ(6) = π6/945.
`static BigDecimal` `ZETA_7`
The value of the Riemann Zeta function ζ(7).
`static BigDecimal` `ZETA_8`
The value of the Riemann Zeta function ζ(8) = π8/9450.
`static BigDecimal` `ZETA_9`
The value of the Riemann Zeta function ζ(9).
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static BigDecimal` `arctan(BigDecimal x)`
Returns the arc tangent of a value; the returned angle is in the range -π/2 through π/2.
`static BigDecimal` ```arctan(BigDecimal x, int n)```
Returns the arc tangent of a value up to an approximation order n; the returned angle is in the range -π/2 through π/2.
`static BigInteger[]` ```bestRationalApproximation(BigDecimal x, int limit)```
Returns the best rational approximation of a real number x, that is, the integers p, q such that xp/q.
`static BigDecimal` `binToBigDecimal(String bin)`
Returns a binary string as a decimal floating-point number.
`static BigDecimal` ```binToBigDecimal(String bin, int length)```
Returns a binary string as a decimal floating-point number.
`static BigDecimal` ```binToBigDecimal(String bin, MathContext mc)```
Returns a binary string as a decimal floating-point number.
`static BigInteger` `binToDec(String bin)`
Returns a binary string as an integer.
`static BigDecimal` ```brown(int n, int precision)```
Returns the n-th Brownian number with respect to the specified radix.
`static BigInteger[]` ```continuedFraction(BigDecimal x, int limit)```
Returns an array containing coefficients of the continued fraction of the number x, with at most `limit` coefficients.
`static BigDecimal` `cos(BigDecimal x)`
Returns the trigonometric cosine of an angle x.
`static BigDecimal` ```cos(BigDecimal x, int n)```
Returns the trigonometric sine of an angle x with |x| ≤ π/4, up to the approximation order n.
`static String` ```decToBin(BigDecimal z, int limit)```
Returns z as a hexadecimal string with at most `limit` positions right of the binary point.
`static String` `decToBin(BigInteger n)`
Returns n as a binary string.
`static String` ```decToBin(BigInteger n, int minimumLength)```
Returns n as a binary string of the specified minimum length.
`static String` `decToHex(BigDecimal z)`
Returns z as a hexadecimal string with at most 100 positions right of the hexadecimal point.
`static String` ```decToHex(BigDecimal z, int limit)```
Returns z as a hexadecimal string with at most `limit` positions right of the hexadecimal point.
`static String` `decToHex(BigInteger n)`
Returns n as a hexadecimal string.
`static String` `decToTern(BigDecimal z)`
Returns z as a ternary string with at most 50 digits right of the ternary point.
`static String` ```decToTern(BigDecimal z, int limit)```
Returns z as a ternary string with at most `limit` positions right of the ternary point.
`static String` `decToTern(BigInteger n)`
Returns n as a ternary string.
`static String` ```decToTern(BigInteger n, int minimumLength)```
Returns n as a ternary string of the specified minimum length.
`static String` `decToTernB(BigDecimal z)`
Returns z as a balanced ternary string with at most 50 digits right of the ternary point.
`static String` ```decToTernB(BigDecimal z, int limit)```
Returns z as a balanced ternary string with at most `limit` positions right of the ternary point.
`static String` `decToTernB(BigInteger n)`
Returns n as a balanced ternary string.
`static String` ```decToTernB(BigInteger n, int minimumLength)```
Returns n as a balanced ternary string of the specified minimum length.
`static BigInteger` `div3b(BigInteger n)`
Returns the integer division n/3 in the balanced ternary system.
`static BigInteger[]` ```euclid(BigInteger m, BigInteger n)```
Returns an array of three integers x[0], x[1], x[2] as given by the extended Euclidian algorithm for integers m and n.
`static BigDecimal` `exp(BigDecimal x)`
Returns Euler's number e raised to the power of x.
`static BigDecimal` ```exp(BigDecimal x, int n)```
Returns the exponential value ex of a number x, up to an approximation order of n.
`static String` `grayCode(BigInteger x)`
Returns the Gray code of an integer.
`static String` ```grayCode(BigInteger x, int minimumLength)```
Returns the Gray code of an integer x, with a given minimum length.
`static String` `grayCodeToBinary(String grayCode)`
Returns binary representation of the integer in which is represented by a Gray code string.
`static String` ```grayCodeToBinary(String grayCode, int minimumLength)```
Returns binary representation of the integer represented by a Gray code string; the string is padded with zeros if it is shorter than the specified minimum length.
`static BigInteger` `grayCodeToDecimal(String grayCode)`
Returns the integer represented by a Gray code string.
`static BigDecimal` `hexToBigDecimal(String hex)`
Returns a hexadecimal string as a decimal fraction number.
`static BigDecimal` ```hexToBigDecimal(String hex, int length)```
Returns a hexadecimal string as a decimal fraction number.
`static BigDecimal` ```hexToBigDecimal(String hex, MathContext mc)```
Returns a hexadecimal string as a decimal fraction number.
`static BigInteger` `hexToDec(String hex)`
Returns a hexadecimal string as an integer.
`static boolean` `isPower(BigInteger n)`
Tests whether there exist integers m and k such that n = mk.
`static boolean` `isPrime(BigInteger n)`
Tests deterministically whether the given integer n is prime.
`static boolean` ```isStrongProbablePrime(BigInteger n, BigInteger a)```
Returns true if n is a strong probable prime to base a, and false if n is not prime.
`static BigInteger` ```lcm(BigInteger m, BigInteger n)```
Returns the least common multiple of m and n.
`static BigDecimal` `ln(BigDecimal x)`
Returns the natural logarithm of a number x.
`static BigDecimal` ```ln(BigDecimal x, int n)```
Returns the natural logarithm of a number x, up to an approximation order of n.
`static BigDecimal` `ln(BigInteger x)`
Returns the natural logarithm of a number x.
`static BigDecimal` ```ln2(BigDecimal x, int n)```
Returns the dual logarithm of a number x, up to an approximation order of n.
`static BigDecimal` ```mod(BigDecimal n, BigDecimal m)```
Returns the value of n mod m, even for negative values.
`static BigInteger` ```mod(BigInteger n, BigInteger m)```
Returns the value of n mod m, even for negative values.
`static char` `mod3b(BigInteger n)`
Returns the symbol in the balanced ternary system representing the value n mod 3.
`static BigDecimal` ```modPow(BigDecimal x, int e, BigDecimal n)```
Returns the value of (xe) mod n.
`static BigInteger` ```modPow(BigInteger x, BigInteger e, BigInteger n)```
Returns the value of me mod n for a nonnegative integer exponent e and a positive modulus n.
`static long` ```modPow(BigInteger m, long e, long n)```
Returns the value of me mod n for a nonnegative integer exponent e and a positive modulus n.
`static boolean` ```nakedAKS(BigInteger n, int r)```
Test for reduced AKS algorithm (probably wrong!)
`static BigInteger` ```ord(BigInteger m, BigInteger n)```
Returns the order ord(m,n) of m modulo n.
`static BigDecimal` `pi(int precision)`
Returns the exact value of π up th the specified precision.
`static String` ```pi(int precision, int radix)```
Returns the exact value of π up th the specified precision and the number system.
`static BigDecimal` ```pow(BigDecimal x, int n)```
Returns a BigDecimal whose value is xn, using the core algorithm defined in ANSI standard X3.274-1996 with rounding according to the context `MATH_CONTEXT`.
`static boolean` `primalityTestAKS(BigInteger n)`
The AKS primality test, returns true if the integer n > 1 is prime.
`static BigDecimal` ```root(int n, BigDecimal z)```
Returns the nth root of z, with an accuracy of 10-50/2 z.
`static BigDecimal` ```root(int n, BigDecimal z, int precision)```
Returns the nth root of z, with an accuracy given by 10-precision/2 z.
`static BigDecimal` ```root(int n, BigInteger z)```
Returns the nth root of z, with an accuracy of 10-50/2 z.
`static BigDecimal` `sin(BigDecimal x)`
Returns the trigonometric sine of an angle x.
`static BigDecimal` ```sin(BigDecimal x, int n)```
Returns the trigonometric sine of an angle x with |x| ≤ π/4, up to the approximation order n.
`static BigInteger` `sqr(BigInteger x)`
Returns the value of x2.
`static BigDecimal` `sqrt(BigDecimal z)`
Returns the square root of z, with an accuracy of 10-50/2 z.
`static BigDecimal` ```sqrt(BigDecimal z, int precision)```
Returns the square root of z, with an accuracy of 10-50/2 z.
`static BigDecimal` `sqrt(BigInteger z)`
Returns the square root of z, with an accuracy of 10-50/2 z.
`static BigDecimal` `ternBToBigDecimal(String tern)`
Returns a balanced ternary string as a decimal floating-point number.
`static BigDecimal` ```ternBToBigDecimal(String tern, int length)```
Returns a balanced ternary string as a decimal floating-point number.
`static BigDecimal` ```ternBToBigDecimal(String tern, MathContext mc)```
Returns a balanced ternary string as a decimal floating-point number.
`static BigInteger` `ternBToDec(String tern)`
Returns a balanced ternary string as an integer.
`static BigDecimal` `ternToBigDecimal(String tern)`
Returns a ternary string as a decimal floating-point number.
`static BigDecimal` ```ternToBigDecimal(String tern, int length)```
Returns a ternary string as a decimal floating-point number.
`static BigDecimal` ```ternToBigDecimal(String tern, MathContext mc)```
Returns a ternary string as a decimal floating-point number.
`static BigInteger` `ternToDec(String tern)`
Returns a ternary string as an integer.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Field Detail

• #### TWO

`public static final BigInteger TWO`
The BigInteger constant two.
`BigInteger`
• #### THREE

`public static final BigInteger THREE`
The BigInteger constant three.
`BigInteger`
• #### PRECISION

`public static final int PRECISION`
Maximum precision of BigDecimals, having the value 50.
Constant Field Values
• #### MATH_CONTEXT

`public static final MathContext MATH_CONTEXT`
This math context is used throughout this class. It determines the maximum precision ("scale") of the BigDecimal numbers and the rounding mode and is initialized with the values PRECISION = 50 and rounding mode = `RoundingMode.HALF_EVEN`.
• #### ZERO_DOT

`public static final BigDecimal ZERO_DOT`
The number 0 as a BigDecimal. It equals `BigInteger.ZERO`.
• #### ONE_DOT

`public static final BigDecimal ONE_DOT`
The number 1 as a BigDecimal. It equals `BigInteger.ONE`.
• #### TWO_DOT

`public static final BigDecimal TWO_DOT`
The number 2 as a BigDecimal.
• #### TEN_DOT

`public static final BigDecimal TEN_DOT`
The number 10 as a BigDecimal. It equals `BigInteger.TEN`.
• #### ONE_SIXTH

`public static final BigDecimal ONE_SIXTH`
The number 1/6 as a BigDecimal. It is computed with the initial value of `MATH_CONTEXT`.
• #### ONE_THIRD

`public static final BigDecimal ONE_THIRD`
The number 1/3 as a BigDecimal. It is computed with the initial value of `MATH_CONTEXT`.
• #### ONE_HALF

`public static final BigDecimal ONE_HALF`
The number 1/2 as a BigDecimal.
• #### SQRT_TWO

`public static final BigDecimal SQRT_TWO`
Square root of 2.
`Numbers.SQRT2`
• #### SQRT_ONE_HALF

`public static final BigDecimal SQRT_ONE_HALF`
Square root of 1/2.
`Numbers.SQRT_1_2`
• #### ROOT_10_TWO

`public static final BigDecimal ROOT_10_TWO`
10th root of 2.
• #### E

`public static final BigDecimal E`
The constant e, the base of the natural logarithms. The constant is implemented to a precision of 10-100.
`Math.E`
• #### PI

`public static final BigDecimal PI`
The constant π, the ratio of the circumference of a circle to its diameter. The constant is implemented to a precision of 10-100.
`Math.PI`
• #### GAMMA

`public static final BigDecimal GAMMA`
Euler-Mascheroni constant γ. The constant is implemented to a precision of 10-101.
`Numbers.GAMMA`

`public static final BigDecimal RADIANS`
The constant 2π/360, the ratio of 1 radians per degree. The constant is implemented to a precision of 10-102.
`PI`, `Numbers.RADIANS`
• #### PI3_4

`public static final BigDecimal PI3_4`
The constant 3π/4.
`PI`
• #### PI5_4

`public static final BigDecimal PI5_4`
The constant 5π/4.
`PI`
• #### PI3_2

`public static final BigDecimal PI3_2`
The constant 3π/2.
`PI`
• #### PI7_4

`public static final BigDecimal PI7_4`
The constant 7π/4.
`PI`
• #### RAMANUJAN

`public static final BigDecimal RAMANUJAN`
Ramanujan's constant eπ √163, up to an accuracy of 10-102. It is "almost" an integer number. It is listed up to 5000 digits at Simon Plouffe's web site at pi.lacim.uqam.ca/piDATA/ramanujan.txt.
• #### ZETA_2

`public static final BigDecimal ZETA_2`
The value of the Riemann Zeta function ζ(2) = π2/6. See http://oeis.org/A013661, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
• #### ZETA_3

`public static final BigDecimal ZETA_3`
The value of the Riemann Zeta function ζ(3), also called Apéry's constant. See http://oeis.org/A002117, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
`Numbers.ZETA_3`
• #### ZETA_4

`public static final BigDecimal ZETA_4`
The value of the Riemann Zeta function ζ(4) = π6/945. See http://oeis.org/A013664, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
• #### ZETA_5

`public static final BigDecimal ZETA_5`
The value of the Riemann Zeta function ζ(5). See http://oeis.org/A013663, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
`Numbers.ZETA_5`
• #### ZETA_6

`public static final BigDecimal ZETA_6`
The value of the Riemann Zeta function ζ(6) = π6/945. See http://oeis.org/A013664, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
• #### ZETA_7

`public static final BigDecimal ZETA_7`
The value of the Riemann Zeta function ζ(7). See http://oeis.org/A013665, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
`Numbers.ZETA_7`
• #### ZETA_8

`public static final BigDecimal ZETA_8`
The value of the Riemann Zeta function ζ(8) = π8/9450. See http://oeis.org/A013666, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
• #### ZETA_9

`public static final BigDecimal ZETA_9`
The value of the Riemann Zeta function ζ(9). See http://oeis.org/A013667, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
`Numbers.ZETA_9`
• #### ZETA_10

`public static final BigDecimal ZETA_10`
The value of the Riemann Zeta function ζ(10). See http://oeis.org/A013668, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
• #### ZETA_11

`public static final BigDecimal ZETA_11`
The value of the Riemann Zeta function ζ(11). See http://oeis.org/A013669, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
`Numbers.ZETA_11`
• #### ZETA_12

`public static final BigDecimal ZETA_12`
The value of the Riemann Zeta function ζ(12). See http://oeis.org/A013670, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
• #### ZETA_13

`public static final BigDecimal ZETA_13`
The value of the Riemann Zeta function ζ(13). See http://oeis.org/A013671, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
`Numbers.ZETA_13`
• #### ZETA_14

`public static final BigDecimal ZETA_14`
The value of the Riemann Zeta function ζ(14). See http://oeis.org/A013672, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
• #### ZETA_15

`public static final BigDecimal ZETA_15`
The value of the Riemann Zeta function ζ(15). See http://oeis.org/A013673, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
`Numbers.ZETA_15`
• #### ZETA_16

`public static final BigDecimal ZETA_16`
The value of the Riemann Zeta function ζ(16). See http://oeis.org/A013674, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
• #### ZETA_17

`public static final BigDecimal ZETA_17`
The value of the Riemann Zeta function ζ(17). See http://oeis.org/A013675, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
`Numbers.ZETA_17`
• #### ZETA_18

`public static final BigDecimal ZETA_18`
The value of the Riemann Zeta function ζ(18). See http://oeis.org/A013676, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
• #### ZETA_19

`public static final BigDecimal ZETA_19`
The value of the Riemann Zeta function ζ(19). See http://oeis.org/A013677, or M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
`Numbers.ZETA_19`
• #### ZETA_20

`public static final BigDecimal ZETA_20`
The value of the Riemann Zeta function ζ(20). See http://oeis.org/A013678.
• #### ZETA_21

`public static final BigDecimal ZETA_21`
The value of the Riemann Zeta function ζ(21). See M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
`Numbers.ZETA_21`
• #### ZETA_23

`public static final BigDecimal ZETA_23`
The value of the Riemann Zeta function ζ(23). See M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
`Numbers.ZETA_23`
• #### ZETA_25

`public static final BigDecimal ZETA_25`
The value of the Riemann Zeta function ζ(25). See M. Abramowitz and I. A. Stegun: Handbook of Mathematical Functions, p. 811.
`Numbers.ZETA_25`
• ### Method Detail

• #### bestRationalApproximation

```public static BigInteger[] bestRationalApproximation(BigDecimal x,
int limit)```
Returns the best rational approximation of a real number x, that is, the integers p, q such that xp/q. The algorithm computes the continued fraction coefficients corresponding to x, where the number of coefficients is bounded by `limit`. Usually, the value of `limit` should be about 40.
Parameters:
`x` - the number to be approximated
`limit` - the maximum number of continued fraction coefficients being considered
Returns:
a two-element array `y` where `y[0]` = p and `y[1]` = q such that xp/q
`continuedFraction(BigDecimal,int)`
• #### pow

```public static BigDecimal pow(BigDecimal x,
int n)```
Returns a BigDecimal whose value is xn, using the core algorithm defined in ANSI standard X3.274-1996 with rounding according to the context `MATH_CONTEXT`. The absolute value of the parameter n must be in the range 0 through 999999999, inclusive. The allowable exponent range of this method depends on the version of `BigDecimal.pow(int,MathContext)`. Especially, pow(`ZERO_DOT`, 0) returns `ONE_DOT`.
Parameters:
`x` - number to be raised to the power
`n` - power to raise x to
Returns:
xn
• #### root

```public static BigDecimal root(int n,
BigInteger z)```
Returns the nth root of z, with an accuracy of 10-50/2 z. The root is understood as the principal root r with the unique real number with the same sign as z such that rn = z. If n = 0, the value of z is returned, if n < 0, the value `0.0` is returned.
Parameters:
`n` - the radical
`z` - the radicand
Returns:
the principal nth root r of z such that rn = z
• #### root

```public static BigDecimal root(int n,
BigDecimal z)```
Returns the nth root of z, with an accuracy of 10-50/2 z. The root is understood as the principal root r with the unique real number with the same sign as z such that rn = z.
Parameters:
`n` - the radical
`z` - the radicand
Returns:
the principal nth root r of z such that rn = z
Throws:
`IllegalArgumentException` - if n = 0, or if n is even and z < 0
• #### root

```public static BigDecimal root(int n,
BigDecimal z,
int precision)```
Returns the nth root of z, with an accuracy given by 10-precision/2 z. The root is understood as the principal root r with the unique real number with the same sign as z such that rn = z.
Parameters:
`n` - the radical
`z` - the radicand
`precision` - the accuracy
Returns:
the principal nth root r of z such that rn = z
Throws:
`IllegalArgumentException` - if n = 0, or if n is even and z < 0
• #### sqrt

`public static BigDecimal sqrt(BigInteger z)`
Returns the square root of z, with an accuracy of 10-50/2 z. The root is understood as the principal root r with the unique real number with the same sign as z such that r2 = z.
Parameters:
`z` - the radicand
Returns:
the principal square root r of z such that r2 = z
• #### sqrt

```public static BigDecimal sqrt(BigDecimal z,
int precision)```
Returns the square root of z, with an accuracy of 10-50/2 z. The root is understood as the principal root r with the unique real number with the same sign as z such that r2 = z.
Parameters:
`z` - the radicand
`precision` - the desired precision
Returns:
the principal square root r of z such that r2 = z
• #### sqrt

`public static BigDecimal sqrt(BigDecimal z)`
Returns the square root of z, with an accuracy of 10-50/2 z. The root is understood as the principal root r with the unique real number with the same sign as z such that r2 = z.
Parameters:
`z` - the radicand
Returns:
the principal square root r of z such that r2 = z
• #### mod

```public static BigInteger mod(BigInteger n,
BigInteger m)```
Returns the value of n mod m, even for negative values. Here the usual periodic definition is used, i.e.,

n mod m = n - ⎣n/m⎦   for m ≠ 0,   and n mod 0 = n.

For instance, 5 mod 3 = 2, but -5 mod 3 = 1, 5 mod (-3) = -1, and -5 mod (-3) = -2. See R.L. Graham, D.E. Knuth, O. Patashnik: Concrete Mathematics. 2nd Edition. Addison-Wesley, Upper Saddle River, NJ 1994, §3.4 (p.82)
Parameters:
`n` - the value to be computed
`m` - the modulus
Returns:
the value n mod m
• #### mod

```public static BigDecimal mod(BigDecimal n,
BigDecimal m)```
Returns the value of n mod m, even for negative values. Here the usual periodic definition is used, i.e., 5 mod 3 = 2, but -5 mod 3 = 1, 5 mod (-3) = -1, and -5 mod (-3) = -2. See R.L. Graham, D.E. Knuth, O. Patashnik: Concrete Mathematics. 2nd Edition. Addison-Wesley, Upper Saddle River, NJ 1994, §3.4 (p.82)
Parameters:
`n` - the value to be computed
`m` - the modulus
Returns:
the value n mod m
• #### modPow

```public static long modPow(BigInteger m,
long e,
long n)```
Returns the value of me mod n for a nonnegative integer exponent e and a positive modulus n.
Parameters:
`m` - the value to be raised to the power
`e` - the exponent
`n` - the modulus
Returns:
the value me mod n
Throws:
`ArithmeticException` - if e < 0 and gcd(x, n) > 1
• #### modPow

```public static BigInteger modPow(BigInteger x,
BigInteger e,
BigInteger n)```
Returns the value of me mod n for a nonnegative integer exponent e and a positive modulus n.
Parameters:
`x` - the value to be raised to the power
`e` - the exponent
`n` - the modulus
Returns:
the value me mod n
Throws:
`ArithmeticException` - if e < 0 and gcd(x, n) > 1
• #### modPow

```public static BigDecimal modPow(BigDecimal x,
int e,
BigDecimal n)```
Returns the value of (xe) mod n.
Parameters:
`x` - the value to be raised to the power
`e` - the exponent
`n` - the modulus
Returns:
the value of xe mod n
• #### sqr

`public static BigInteger sqr(BigInteger x)`
Returns the value of x2.
Parameters:
`x` - the value to be squared
Returns:
the square of the input x, i.e., x2
• #### euclid

```public static BigInteger[] euclid(BigInteger m,
BigInteger n)```
Returns an array of three integers x[0], x[1], x[2] as given by the extended Euclidian algorithm for integers m and n. The three integers satisfy the equations

x[0] = gcd(m, n) = x[1] m + x[2] n.

This methods implements an iterative version of the extended Euclidian algorithm.
Parameters:
`m` - the first integer
`n` - the second integer
Returns:
an array of three integers x[0], x[1], x[2] such that x[0] = gcd(m, n) = x[1] m + x[2] n
`Numbers.euclid(long,long)`
• #### lcm

```public static BigInteger lcm(BigInteger m,
BigInteger n)```
Returns the least common multiple of m and n.
Parameters:
`m` - the first integer
`n` - the second integer
Returns:
the least common multiple of m and n
• #### isPrime

`public static boolean isPrime(BigInteger n)`
Tests deterministically whether the given integer n is prime. This algorithm first uses the method `isProbablePrime` of the class `BigInteger` which yields false if the given number is not prime with certainty.
Parameters:
`n` - the integer to test
Returns:
true if and only if n is prime.
• #### isStrongProbablePrime

```public static boolean isStrongProbablePrime(BigInteger n,
BigInteger a)```
Returns true if n is a strong probable prime to base a, and false if n is not prime. This algorithm is the core of the Miller-Rabin primality test, cf. R. Crandall & C. Pomerance: Prime Numbers. A Computational Perspective. 2nd edition. Springer, New York 2005, &sec;3.5. The number n must be an odd number > 3, and 1 < a < n-1.
Parameters:
`n` - the number to be tested on strong probable primality
`a` - the base of the strong probable primality test
Returns:
true if n is a strong probable prime to base a, and false if n is not prime
Throws:
`IllegalArgumentException` - if n ≤ 3, or a ≤ 1, or an - 1
`Numbers.isStrongProbablePrime(int,int)`
• #### primalityTestAKS

`public static boolean primalityTestAKS(BigInteger n)`
The AKS primality test, returns true if the integer n > 1 is prime. This test has a polynomial time complexity with respect to log n, proving that the decision problem whether a given integer is prime, is in the complexity class P.
Parameters:
`n` - an integer > 1
Returns:
true if and only if n is prime
• #### nakedAKS

```public static boolean nakedAKS(BigInteger n,
int r)```
Test for reduced AKS algorithm (probably wrong!)
Parameters:
`n` - the integer to be analyzed
`r` - the polynomial degree
Returns:
true iff n is prime (?)
• #### ord

```public static BigInteger ord(BigInteger m,
BigInteger n)```
Returns the order ord(m,n) of m modulo n. More precisely, we have

ord(m, n) = mini { i > 0 : mi = 1 mod n },

The order is computed by Floyd's cycle finding algorithm.
Parameters:
`m` - the number of which the order is computed
`n` - the modulus
Returns:
the order of m mod n
• #### isPower

`public static boolean isPower(BigInteger n)`
Tests whether there exist integers m and k such that n = mk.
Parameters:
`n` - the number to be checked
Returns:
true if and only if there exist integers m and k such that n = mk
• #### continuedFraction

```public static BigInteger[] continuedFraction(BigDecimal x,
int limit)```
Returns an array containing coefficients of the continued fraction of the number x, with at most `limit` coefficients. Note that by the finite precision of x the higher continuous fraction coefficients get more and more imprecise. For instance, for the Euler number the coefficients are correct up to the limit 87, for Apéry's constant up to the limit 100, http://oeis.org/A013631, for π up to the limit 43, cf. http://oeis.org/A001203.
Parameters:
`x` - the number to be expanded as a continuous fraction
`limit` - the maximum number of continuous fraction coefficients to be computed
Returns:
an array of length `limit` containing the continuous fraction coefficients
• #### exp

`public static BigDecimal exp(BigDecimal x)`
Returns Euler's number e raised to the power of x. The value is computed up to an accuracy of 10-100.
Parameters:
`x` - the exponent
Returns:
the number ex
`E`
• #### exp

```public static BigDecimal exp(BigDecimal x,
int n)```
Returns the exponential value ex of a number x, up to an approximation order of n. For n = 70, the value is computed up to an accuracy of 10-100. The range of the integral part of x is limited according to the method `BigDecimal.pow(int,MathContext)`.
Parameters:
`x` - the number
`n` - the order of approximation
Returns:
the number ex, up to the approximation order n
• #### ln

`public static BigDecimal ln(BigInteger x)`
Returns the natural logarithm of a number x. The value is computed up to an accuracy of 10-`PRECISION`.
Parameters:
`x` - the number
Returns:
the natural logarithm of the argument
• #### ln

`public static BigDecimal ln(BigDecimal x)`
Returns the natural logarithm of a number x. The value is computed up to an accuracy of 10-`PRECISION`.
Parameters:
`x` - the number
Returns:
the natural logarithm of the argument
• #### ln

```public static BigDecimal ln(BigDecimal x,
int n)```
Returns the natural logarithm of a number x, up to an approximation order of n. With n, the value is computed up to an accuracy of 10-n.
Parameters:
`x` - the number
`n` - the order up to which the approximation is computed
Returns:
the natural logarithm of the the argument
• #### ln2

```public static BigDecimal ln2(BigDecimal x,
int n)```
Returns the dual logarithm of a number x, up to an approximation order of n. With n, the value is computed up to an accuracy of 10-n.
Parameters:
`x` - the number
`n` - the order up to which the approximation is computed
Returns:
the dual logarithm of the the argument
• #### pi

`public static BigDecimal pi(int precision)`
Returns the exact value of π up th the specified precision.
Parameters:
`precision` - the length of the representation of π
Returns:
the value of π in hexadecimal expansion up to the specified precision
• #### pi

```public static String pi(int precision,
Returns the exact value of π up th the specified precision and the number system.
Parameters:
`precision` - the length of the representation of π
`radix` - the radix of the number system
Returns:
the natural logarithm of the the argument
Throws:
`IllegalArgumentException` - if the radix is not known
• #### arctan

`public static BigDecimal arctan(BigDecimal x)`
Returns the arc tangent of a value; the returned angle is in the range -π/2 through π/2. The precision of the returned value is at least 10-100.
Parameters:
`x` - a number
Returns:
the arc tangent of the argument
`arctan(BigDecimal,int)`
• #### cos

`public static BigDecimal cos(BigDecimal x)`
Returns the trigonometric cosine of an angle x. The value is computed up to an accuracy of 10-100.
Parameters:
`x` - the angle in radians
Returns:
the cosine of the the argument
`cos(BigDecimal,int)`
• #### sin

`public static BigDecimal sin(BigDecimal x)`
Returns the trigonometric sine of an angle x. The value is computed up to an accuracy of 10-100.
Parameters:
`x` - the angle in radians
Returns:
the sine of the the argument
`sin(BigDecimal,int)`
• #### arctan

```public static BigDecimal arctan(BigDecimal x,
int n)```
Returns the arc tangent of a value up to an approximation order n; the returned angle is in the range -π/2 through π/2. For even n ≤ 130, the precision of the returned value is about 10-0.8n in the worst case. The most imprecise values to be computed are x1 = √2 - 1 and x2 = √2 + 1 (= 1/x1). For n = 126, the precision of the returned value is about 10-100 for these argument values.
Parameters:
`x` - a number
`n` - the number of iterations
Returns:
the arc tangent of the argument
• #### cos

```public static BigDecimal cos(BigDecimal x,
int n)```
Returns the trigonometric sine of an angle x with |x| ≤ π/4, up to the approximation order n. For n = 32, the precision of the returned value is about 10-100. Note, however, that the precision depends on the scale of the argument x, i.e., a low scale may result in a low precision.
Parameters:
`x` - the angle in radians
`n` - the number of iterations
Returns:
the sine of the argument
• #### sin

```public static BigDecimal sin(BigDecimal x,
int n)```
Returns the trigonometric sine of an angle x with |x| ≤ π/4, up to the approximation order n. For n = 32, the precision of the returned value is about 10-100.
Parameters:
`x` - the angle in radians
`n` - the number of iterations
Returns:
the sine of the argument
• #### brown

```public static BigDecimal brown(int n,
int precision)```
Returns the n-th Brownian number with respect to the specified radix. The n-th Brownian number bn is defined as

bn = sqrt(f(n))

where f is defined by the recursion f(n) = radix * f(n - 1). The Brownian numbers were introduced by Kevin Brown. For details, see J.-P. Delahaye: MathÃ©matiques pour le plaisir. Un inventaire de curiositÃ©s. Belin, Paris 2010, p. 140.
Parameters:
`n` - an integer
`precision` - the number of digits which are calculated
Returns:
the n-th Brownian number bn
• #### binToDec

`public static BigInteger binToDec(String bin)`
Returns a binary string as an integer.
Parameters:
`bin` - the binary string to be represented in decimal form
Returns:
the BigInteger representing the binary string
Throws:
`NumberFormatException` - if the string is not binary
• #### decToBin

`public static String decToBin(BigInteger n)`
Returns n as a binary string.
Parameters:
`n` - the decimal value to be represented in binary form.
Returns:
the binary representation of n
`decToBin(BigDecimal, int)`
• #### decToBin

```public static String decToBin(BigInteger n,
int minimumLength)```
Returns n as a binary string of the specified minimum length.
Parameters:
`n` - the decimal value to be represented in binary form
`minimumLength` - the minimum length of the returned binary string
Returns:
string representing the binary representation of n
• #### decToBin

```public static String decToBin(BigDecimal z,
int limit)```
Returns z as a hexadecimal string with at most `limit` positions right of the binary point.
Parameters:
`z` - the decimal value to be represented in hexadecimal form.
`limit` - the maximum position after the binary point.
Returns:
the binary representation of z
• #### binToBigDecimal

`public static BigDecimal binToBigDecimal(String bin)`
Returns a binary string as a decimal floating-point number.
Parameters:
`bin` - the binary string to be represented in decimal form.
Returns:
the double number representing the binary string
Throws:
`NumberFormatException` - if the string is not binary
• #### binToBigDecimal

```public static BigDecimal binToBigDecimal(String bin,
int length)```
Returns a binary string as a decimal floating-point number.
Parameters:
`bin` - the binary string to be represented in decimal form.
`length` - precision (number of digits)
Returns:
the double number representing the binary string
Throws:
`NumberFormatException` - if the string is not binary
• #### binToBigDecimal

```public static BigDecimal binToBigDecimal(String bin,
MathContext mc)```
Returns a binary string as a decimal floating-point number.
Parameters:
`bin` - the binary string to be represented in decimal form.
`mc` - MATH_CONTEXT (precision and rounding mode)
Returns:
the double number representing the binary string
Throws:
`NumberFormatException` - if the string is not binary
• #### decToTern

`public static String decToTern(BigInteger n)`
Returns n as a ternary string.
Parameters:
`n` - the decimal value to be represented in ternary form
Returns:
string representing the ternary representation of n
• #### decToTern

```public static String decToTern(BigInteger n,
int minimumLength)```
Returns n as a ternary string of the specified minimum length.
Parameters:
`n` - the decimal value to be represented in ternary form
`minimumLength` - the minimum length of the returned ternary string
Returns:
string representing the ternary representation of n
• #### decToTern

`public static String decToTern(BigDecimal z)`
Returns z as a ternary string with at most 50 digits right of the ternary point.
Parameters:
`z` - the decimal value to be represented in ternary form.
Returns:
the ternary representation of z
• #### decToTern

```public static String decToTern(BigDecimal z,
int limit)```
Returns z as a ternary string with at most `limit` positions right of the ternary point.
Parameters:
`z` - the decimal value to be represented in ternary form.
`limit` - the maximum position after the ternary point.
Returns:
the ternary representation of z
• #### ternToDec

`public static BigInteger ternToDec(String tern)`
Returns a ternary string as an integer.
Parameters:
`tern` - the ternary string to be represented in decimal form
Returns:
the long integer representing the ternary string
Throws:
`NumberFormatException` - if the string is not ternary
• #### ternToBigDecimal

`public static BigDecimal ternToBigDecimal(String tern)`
Returns a ternary string as a decimal floating-point number.
Parameters:
`tern` - the ternary string to be represented in decimal form.
Returns:
the BigDecimal number representing the ternary string
Throws:
`NumberFormatException` - if the string is not ternary
• #### ternToBigDecimal

```public static BigDecimal ternToBigDecimal(String tern,
int length)```
Returns a ternary string as a decimal floating-point number.
Parameters:
`tern` - the ternary string to be represented in decimal form.
`length` - the precision (number of digits)
Returns:
the BigDecimal number representing the ternary string
Throws:
`NumberFormatException` - if the string is not ternary
• #### ternToBigDecimal

```public static BigDecimal ternToBigDecimal(String tern,
MathContext mc)```
Returns a ternary string as a decimal floating-point number.
Parameters:
`tern` - the ternary string to be represented in decimal form.
`mc` - the MATH_CONTEXT (precision and rounding mode)
Returns:
the BigDecimal number representing the ternary string
Throws:
`NumberFormatException` - if the string is not ternary
• #### div3b

`public static BigInteger div3b(BigInteger n)`
Returns the integer division n/3 in the balanced ternary system. It is defined by [n/3] except for the case n % 2 where it gives [n/3] + 1.
Parameters:
`n` - the decimal value to be divised
Returns:
the integer division n/3 in the balanced ternary system
• #### mod3b

`public static char mod3b(BigInteger n)`
Returns the symbol in the balanced ternary system representing the value n mod 3.
Parameters:
`n` - the decimal value to be divised
Returns:
the symbol in the balanced ternary system representing the value n mod 3.
• #### decToTernB

`public static String decToTernB(BigInteger n)`
Returns n as a balanced ternary string.
Parameters:
`n` - the decimal value to be represented in ternary form
Returns:
string representing the balanced ternary representation of n
• #### decToTernB

```public static String decToTernB(BigInteger n,
int minimumLength)```
Returns n as a balanced ternary string of the specified minimum length.
Parameters:
`n` - the decimal value to be represented in balanced ternary form
`minimumLength` - the minimum length of the returned ternary string
Returns:
string representing the balanced ternary representation of n
• #### ternBToDec

`public static BigInteger ternBToDec(String tern)`
Returns a balanced ternary string as an integer.
Parameters:
`tern` - the ternary string to be represented in decimal form
Returns:
the long integer representing the ternary string
Throws:
`NumberFormatException` - if the string is not ternary
• #### decToTernB

`public static String decToTernB(BigDecimal z)`
Returns z as a balanced ternary string with at most 50 digits right of the ternary point.
Parameters:
`z` - the decimal value to be represented in balanced ternary form.
Returns:
the balanced ternary representation of z
• #### decToTernB

```public static String decToTernB(BigDecimal z,
int limit)```
Returns z as a balanced ternary string with at most `limit` positions right of the ternary point.
Parameters:
`z` - the decimal value to be represented in balanced ternary form.
`limit` - the maximum position after the ternary point.
Returns:
the balanced ternary representation of z
• #### ternBToBigDecimal

`public static BigDecimal ternBToBigDecimal(String tern)`
Returns a balanced ternary string as a decimal floating-point number.
Parameters:
`tern` - the ternary string to be represented in decimal form.
Returns:
the BigDecimal number representing the balanced ternary string
Throws:
`NumberFormatException` - if the string is not balanced ternary
• #### ternBToBigDecimal

```public static BigDecimal ternBToBigDecimal(String tern,
int length)```
Returns a balanced ternary string as a decimal floating-point number.
Parameters:
`tern` - the balanced ternary string to be represented in decimal form.
`length` - the precision of the decimal number
Returns:
the BigDecimal number representing the balanced ternary string
Throws:
`NumberFormatException` - if the string is not balanced ternary
• #### ternBToBigDecimal

```public static BigDecimal ternBToBigDecimal(String tern,
MathContext mc)```
Returns a balanced ternary string as a decimal floating-point number.
Parameters:
`tern` - the balanced ternary string to be represented in decimal form.
`mc` - the MATH_CONTEXT (digit number and rounding mode)
Returns:
the BigDecimal number representing the balanced ternary string
Throws:
`NumberFormatException` - if the string is not balanced ternary
• #### decToHex

`public static String decToHex(BigInteger n)`
Returns n as a hexadecimal string.
Parameters:
`n` - the decimal value to be represented in hexadecimal form.
Returns:
• #### decToHex

`public static String decToHex(BigDecimal z)`
Returns z as a hexadecimal string with at most 100 positions right of the hexadecimal point.
Parameters:
`z` - the decimal value to be represented in hexadecimal form.
Returns:
• #### decToHex

```public static String decToHex(BigDecimal z,
int limit)```
Returns z as a hexadecimal string with at most `limit` positions right of the hexadecimal point.
Parameters:
`z` - the decimal value to be represented in hexadecimal form.
`limit` - the maximum position after the hexadecimal point.
Returns:
• #### hexToDec

`public static BigInteger hexToDec(String hex)`
Returns a hexadecimal string as an integer.
Parameters:
`hex` - the hexadecimal string to be represented in decimal form
Returns:
the integer representing the hexadecimal string
Throws:
`NumberFormatException` - if the string is not hexadecimal
• #### hexToBigDecimal

`public static BigDecimal hexToBigDecimal(String hex)`
Returns a hexadecimal string as a decimal fraction number.
Parameters:
`hex` - the hexadecimal string to be represented in decimal form.
Returns:
the BigDecimal number representing the hexadecimal string
Throws:
`NumberFormatException` - if the string is not hexadecimal
• #### hexToBigDecimal

```public static BigDecimal hexToBigDecimal(String hex,
int length)```
Returns a hexadecimal string as a decimal fraction number.
Parameters:
`hex` - the hexadecimal string to be represented in decimal form.
`length` - the precision (number of digits)
Returns:
the BigDecimal number representing the hexadecimal string
Throws:
`NumberFormatException` - if the string is not hexadecimal
• #### hexToBigDecimal

```public static BigDecimal hexToBigDecimal(String hex,
MathContext mc)```
Returns a hexadecimal string as a decimal fraction number.
Parameters:
`hex` - the hexadecimal string to be represented in decimal form.
`mc` - the MATH_CONTEXT (precision and rounding mode)
Returns:
the BigDecimal number representing the hexadecimal string
Throws:
`NumberFormatException` - if the string is not hexadecimal
• #### grayCode

`public static String grayCode(BigInteger x)`
Returns the Gray code of an integer.
Parameters:
`x` - an integer
Returns:
the Gray code of x as a string
`grayCode(BigInteger, int)`
• #### grayCode

```public static String grayCode(BigInteger x,
int minimumLength)```
Returns the Gray code of an integer x, with a given minimum length. If the minimum length is greater than the bit length of the integer x, the Gray code string is padded with leading zeros.
Parameters:
`x` - an integer
`minimumLength` - the minimum length of the returned Gray code string
Returns:
the Gray code of x as a string
`grayCode(BigInteger)`
• #### grayCodeToBinary

```public static String grayCodeToBinary(String grayCode,
int minimumLength)```
Returns binary representation of the integer represented by a Gray code string; the string is padded with zeros if it is shorter than the specified minimum length.
Parameters:
`grayCode` - a Gray code string
`minimumLength` - the minimum length of the binary string
Returns:
the binary representation of the integer represented by the Gray code string
Throws:
`NumberFormatException` - if the string does not represent a Gray code
`grayCodeToBinary(String)`
• #### grayCodeToBinary

`public static String grayCodeToBinary(String grayCode)`
Returns binary representation of the integer in which is represented by a Gray code string.
Parameters:
`grayCode` - a Gray code string
Returns:
the binary representation of the integer represented by the Gray code string
Throws:
`NumberFormatException` - if the string does not represent a Gray code
`grayCodeToBinary(String, int)`
• #### grayCodeToDecimal

`public static BigInteger grayCodeToDecimal(String grayCode)`
Returns the integer represented by a Gray code string.
Parameters:
`grayCode` - a Gray code string
Returns:
the integer represented by the Gray code string
Throws:
`NumberFormatException` - if the string does not represent a Gray code