public class BigNumbers extends Object
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).
|
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 x ≈ p/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.
|
public static final BigInteger TWO
BigInteger
public static final BigInteger THREE
BigInteger
public static final int PRECISION
public static final MathContext MATH_CONTEXT
RoundingMode.HALF_EVEN
.public static final BigDecimal ZERO_DOT
BigInteger.ZERO
.public static final BigDecimal ONE_DOT
BigInteger.ONE
.public static final BigDecimal TWO_DOT
public static final BigDecimal TEN_DOT
BigInteger.TEN
.public static final BigDecimal ONE_SIXTH
MATH_CONTEXT
.public static final BigDecimal ONE_THIRD
MATH_CONTEXT
.public static final BigDecimal ONE_HALF
public static final BigDecimal SQRT_TWO
Numbers.SQRT2
public static final BigDecimal SQRT_ONE_HALF
Numbers.SQRT_1_2
public static final BigDecimal ROOT_10_TWO
public static final BigDecimal E
Math.E
public static final BigDecimal PI
Math.PI
public static final BigDecimal GAMMA
Numbers.GAMMA
public static final BigDecimal RADIANS
PI
,
Numbers.RADIANS
public static final BigDecimal PI_4
PI
public static final BigDecimal PI_2
PI
public static final BigDecimal PI3_4
PI
public static final BigDecimal PI5_4
PI
public static final BigDecimal PI3_2
PI
public static final BigDecimal PI7_4
PI
public static final BigDecimal RAMANUJAN
public static final BigDecimal ZETA_2
public static final BigDecimal ZETA_3
Numbers.ZETA_3
public static final BigDecimal ZETA_4
public static final BigDecimal ZETA_5
Numbers.ZETA_5
public static final BigDecimal ZETA_6
public static final BigDecimal ZETA_7
Numbers.ZETA_7
public static final BigDecimal ZETA_8
public static final BigDecimal ZETA_9
Numbers.ZETA_9
public static final BigDecimal ZETA_10
public static final BigDecimal ZETA_11
Numbers.ZETA_11
public static final BigDecimal ZETA_12
public static final BigDecimal ZETA_13
Numbers.ZETA_13
public static final BigDecimal ZETA_14
public static final BigDecimal ZETA_15
Numbers.ZETA_15
public static final BigDecimal ZETA_16
public static final BigDecimal ZETA_17
Numbers.ZETA_17
public static final BigDecimal ZETA_18
public static final BigDecimal ZETA_19
Numbers.ZETA_19
public static final BigDecimal ZETA_20
public static final BigDecimal ZETA_21
Numbers.ZETA_21
public static final BigDecimal ZETA_23
Numbers.ZETA_23
public static final BigDecimal ZETA_25
Numbers.ZETA_25
public static BigInteger[] bestRationalApproximation(BigDecimal x, int limit)
limit
. Usually, the value of limit
should be about 40.x
- the number to be approximatedlimit
- the maximum number of continued fraction coefficients being consideredy
where y[0]
= p and
y[1]
= q such that x ≈ p/qcontinuedFraction(BigDecimal,int)
public static BigDecimal pow(BigDecimal x, int n)
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
.x
- number to be raised to the powern
- power to raise x topublic static BigDecimal root(int n, BigInteger z)
0.0
is returned.n
- the radicalz
- the radicandpublic static BigDecimal root(int n, BigDecimal z)
n
- the radicalz
- the radicandIllegalArgumentException
- if n = 0,
or if n is even and z < 0public static BigDecimal root(int n, BigDecimal z, int precision)
n
- the radicalz
- the radicandprecision
- the accuracyIllegalArgumentException
- if n = 0,
or if n is even and z < 0public static BigDecimal sqrt(BigInteger z)
z
- the radicandpublic static BigDecimal sqrt(BigDecimal z, int precision)
z
- the radicandprecision
- the desired precisionpublic static BigDecimal sqrt(BigDecimal z)
z
- the radicandpublic static BigInteger mod(BigInteger n, BigInteger m)
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)n
- the value to be computedm
- the moduluspublic static BigDecimal mod(BigDecimal n, BigDecimal m)
n
- the value to be computedm
- the moduluspublic static long modPow(BigInteger m, long e, long n)
m
- the value to be raised to the powere
- the exponentn
- the modulusArithmeticException
- if e < 0 and gcd(x, n) > 1public static BigInteger modPow(BigInteger x, BigInteger e, BigInteger n)
x
- the value to be raised to the powere
- the exponentn
- the modulusArithmeticException
- if e < 0 and gcd(x, n) > 1public static BigDecimal modPow(BigDecimal x, int e, BigDecimal n)
x
- the value to be raised to the powere
- the exponentn
- the moduluspublic static BigInteger sqr(BigInteger x)
x
- the value to be squaredpublic static BigInteger[] euclid(BigInteger m, BigInteger n)
x[0] = gcd(m, n) = x[1] m + x[2] n.
This methods implements an iterative version of the extended Euclidian algorithm.m
- the first integern
- the second integerNumbers.euclid(long,long)
public static BigInteger lcm(BigInteger m, BigInteger n)
m
- the first integern
- the second integerpublic static boolean isPrime(BigInteger n)
isProbablePrime
of the class BigInteger
which yields false if
the given number is not prime with certainty.n
- the integer to testpublic static boolean isStrongProbablePrime(BigInteger n, BigInteger a)
n
- the number to be tested on strong probable primalitya
- the base of the strong probable primality testIllegalArgumentException
- if n ≤ 3, or a ≤ 1,
or a ≥ n - 1Numbers.isStrongProbablePrime(int,int)
public static boolean primalityTestAKS(BigInteger n)
n
- an integer > 1public static boolean nakedAKS(BigInteger n, int r)
n
- the integer to be analyzedr
- the polynomial degreepublic static BigInteger ord(BigInteger m, BigInteger n)
ord(m, n) = mini { i > 0 : mi = 1 mod n },
The order is computed by Floyd's cycle finding algorithm.m
- the number of which the order is computedn
- the moduluspublic static boolean isPower(BigInteger n)
n
- the number to be checkedpublic static BigInteger[] continuedFraction(BigDecimal x, int limit)
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.x
- the number to be expanded as a continuous fractionlimit
- the maximum number of continuous fraction coefficients to be computedlimit
containing the continuous fraction coefficientspublic static BigDecimal exp(BigDecimal x)
x
- the exponentE
public static BigDecimal exp(BigDecimal x, int n)
BigDecimal.pow(int,MathContext)
.x
- the numbern
- the order of approximationpublic static BigDecimal ln(BigInteger x)
PRECISION
.x
- the numberpublic static BigDecimal ln(BigDecimal x)
PRECISION
.x
- the numberpublic static BigDecimal ln(BigDecimal x, int n)
x
- the numbern
- the order up to which the approximation is computedpublic static BigDecimal ln2(BigDecimal x, int n)
x
- the numbern
- the order up to which the approximation is computedpublic static BigDecimal pi(int precision)
precision
- the length of the representation of πpublic static String pi(int precision, int radix)
precision
- the length of the representation of πradix
- the radix of the number systemIllegalArgumentException
- if the radix is not knownpublic static BigDecimal arctan(BigDecimal x)
x
- a numberarctan(BigDecimal,int)
public static BigDecimal cos(BigDecimal x)
x
- the angle in radianscos(BigDecimal,int)
public static BigDecimal sin(BigDecimal x)
x
- the angle in radianssin(BigDecimal,int)
public static BigDecimal arctan(BigDecimal x, int n)
x
- a numbern
- the number of iterationspublic static BigDecimal cos(BigDecimal x, int n)
x
- the angle in radiansn
- the number of iterationspublic static BigDecimal sin(BigDecimal x, int n)
x
- the angle in radiansn
- the number of iterationspublic static BigDecimal brown(int n, int precision)
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.n
- an integerprecision
- the number of digits which are calculatedpublic static BigInteger binToDec(String bin)
bin
- the binary string to be represented in decimal formNumberFormatException
- if the string is not binarypublic static String decToBin(BigInteger n)
n
- the decimal value to be represented in binary form.decToBin(BigDecimal, int)
public static String decToBin(BigInteger n, int minimumLength)
n
- the decimal value to be represented in binary formminimumLength
- the minimum length of the returned binary stringpublic static String decToBin(BigDecimal z, int limit)
limit
positions right of the binary point.z
- the decimal value to be represented in hexadecimal form.limit
- the maximum position after the binary point.public static BigDecimal binToBigDecimal(String bin)
bin
- the binary string to be represented in decimal form.NumberFormatException
- if the string is not binarypublic static BigDecimal binToBigDecimal(String bin, int length)
bin
- the binary string to be represented in decimal form.length
- precision (number of digits)NumberFormatException
- if the string is not binarypublic static BigDecimal binToBigDecimal(String bin, MathContext mc)
bin
- the binary string to be represented in decimal form.mc
- MATH_CONTEXT (precision and rounding mode)NumberFormatException
- if the string is not binarypublic static String decToTern(BigInteger n)
n
- the decimal value to be represented in ternary formpublic static String decToTern(BigInteger n, int minimumLength)
n
- the decimal value to be represented in ternary formminimumLength
- the minimum length of the returned ternary stringpublic static String decToTern(BigDecimal z)
z
- the decimal value to be represented in ternary form.public static String decToTern(BigDecimal z, int limit)
limit
positions right of the ternary point.z
- the decimal value to be represented in ternary form.limit
- the maximum position after the ternary point.public static BigInteger ternToDec(String tern)
tern
- the ternary string to be represented in decimal formNumberFormatException
- if the string is not ternarypublic static BigDecimal ternToBigDecimal(String tern)
tern
- the ternary string to be represented in decimal form.NumberFormatException
- if the string is not ternarypublic static BigDecimal ternToBigDecimal(String tern, int length)
tern
- the ternary string to be represented in decimal form.length
- the precision (number of digits)NumberFormatException
- if the string is not ternarypublic static BigDecimal ternToBigDecimal(String tern, MathContext mc)
tern
- the ternary string to be represented in decimal form.mc
- the MATH_CONTEXT (precision and rounding mode)NumberFormatException
- if the string is not ternarypublic static BigInteger div3b(BigInteger n)
n
- the decimal value to be divisedpublic static char mod3b(BigInteger n)
n
- the decimal value to be divisedpublic static String decToTernB(BigInteger n)
n
- the decimal value to be represented in ternary formpublic static String decToTernB(BigInteger n, int minimumLength)
n
- the decimal value to be represented in balanced ternary formminimumLength
- the minimum length of the returned ternary stringpublic static BigInteger ternBToDec(String tern)
tern
- the ternary string to be represented in decimal formNumberFormatException
- if the string is not ternarypublic static String decToTernB(BigDecimal z)
z
- the decimal value to be represented in balanced ternary form.public static String decToTernB(BigDecimal z, int limit)
limit
positions right of the ternary point.z
- the decimal value to be represented in balanced ternary form.limit
- the maximum position after the ternary point.public static BigDecimal ternBToBigDecimal(String tern)
tern
- the ternary string to be represented in decimal form.NumberFormatException
- if the string is not balanced ternarypublic static BigDecimal ternBToBigDecimal(String tern, int length)
tern
- the balanced ternary string to be represented in decimal form.length
- the precision of the decimal numberNumberFormatException
- if the string is not balanced ternarypublic static BigDecimal ternBToBigDecimal(String tern, MathContext mc)
tern
- the balanced ternary string to be represented in decimal form.mc
- the MATH_CONTEXT (digit number and rounding mode)NumberFormatException
- if the string is not balanced ternarypublic static String decToHex(BigInteger n)
n
- the decimal value to be represented in hexadecimal form.public static String decToHex(BigDecimal z)
z
- the decimal value to be represented in hexadecimal form.public static String decToHex(BigDecimal z, int limit)
limit
positions right of the hexadecimal point.z
- the decimal value to be represented in hexadecimal form.limit
- the maximum position after the hexadecimal point.public static BigInteger hexToDec(String hex)
hex
- the hexadecimal string to be represented in decimal formNumberFormatException
- if the string is not hexadecimalpublic static BigDecimal hexToBigDecimal(String hex)
hex
- the hexadecimal string to be represented in decimal form.NumberFormatException
- if the string is not hexadecimalpublic static BigDecimal hexToBigDecimal(String hex, int length)
hex
- the hexadecimal string to be represented in decimal form.length
- the precision (number of digits)NumberFormatException
- if the string is not hexadecimalpublic static BigDecimal hexToBigDecimal(String hex, MathContext mc)
hex
- the hexadecimal string to be represented in decimal form.mc
- the MATH_CONTEXT (precision and rounding mode)NumberFormatException
- if the string is not hexadecimalpublic static String grayCode(BigInteger x)
x
- an integergrayCode(BigInteger, int)
public static String grayCode(BigInteger x, int minimumLength)
x
- an integerminimumLength
- the minimum length of the returned Gray code stringgrayCode(BigInteger)
public static String grayCodeToBinary(String grayCode, int minimumLength)
grayCode
- a Gray code stringminimumLength
- the minimum length of the binary stringNumberFormatException
- if the string does not represent a Gray codegrayCodeToBinary(String)
public static String grayCodeToBinary(String grayCode)
grayCode
- a Gray code stringNumberFormatException
- if the string does not represent a Gray codegrayCodeToBinary(String, int)
public static BigInteger grayCodeToDecimal(String grayCode)
grayCode
- a Gray code stringNumberFormatException
- if the string does not represent a Gray code