Package org.apfloat
Class AprationalMath
- java.lang.Object
-
- org.apfloat.AprationalMath
-
public class AprationalMath extends java.lang.ObjectVarious mathematical functions for arbitrary precision rational numbers.- Version:
- 1.14.0
-
-
Constructor Summary
Constructors Modifier Constructor Description privateAprationalMath()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Aprationalabs(Aprational x)Absolute value.static Aprationalbernoulli(long n)Returns the specified Bernoulli number.static Aprationalbernoulli(long n, int radix)Returns the specified Bernoulli number in the given radix.(package private) static AprationalbernoulliBig(long n, int radix)(package private) static java.util.Iterator<Aprational>bernoullis(long n, int radix)(package private) static java.util.Iterator<Aprational>bernoullis2(long n, int radix)(package private) static java.util.Iterator<Aprational>bernoullis2Big(long n, int radix)(package private) static java.util.Iterator<Aprational>bernoullis2Small(int radix)(package private) static java.util.Iterator<Aprational>bernoullisBig(long n, int radix)(package private) static AprationalbernoulliSmall(long n, int radix)(package private) static java.util.Iterator<Aprational>bernoullisSmall(int radix)static Aprationalbinomial(Aprational n, Aprational k)Binomial coefficient.static Apint[]continuedFraction(Aprational x, int n)Generates the firstnterms in the continued fraction representation ofx.static Aprational[]convergents(Aprational x, int n)Generates the firstnconvergents corresponding to the continued fraction ofx.static AprationalcopySign(Aprational x, Aprational y)Copy sign from one argument to another.static AprationalharmonicNumber(Apint n)Harmonic number.static AprationalharmonicNumber(Apint n, Apint r)Generalized harmonic number.private static Apint[]harmonicNumber(Apint n, Apint m, long r)static Aprationalmax(Aprational x, Aprational y)Returns the greater of the two values.static Aprationalmin(Aprational x, Aprational y)Returns the smaller of the two values.static Aprationalnegate(Aprational x)Deprecated.UseAprational.negate().static Aprationalpochhammer(Aprational x, Apint n)Pochhammer symbol.static Aprationalpow(Aprational x, long n)Integer power.static Aprationalproduct(Aprational... x)Product of numbers.private static AprationalrecursiveSum(Aprational[] x, int n, int m)static Apfloatround(Aprational x, long precision, java.math.RoundingMode roundingMode)Deprecated.static ApintroundToInteger(Aprational x, java.math.RoundingMode roundingMode)Roundsxto integer using the specified rounding mode.static AprationalroundToMultiple(Aprational x, Aprational y, java.math.RoundingMode roundingMode)Roundsxto the nearest multiple ofyusing the specified rounding mode.static ApfloatroundToPlaces(Aprational x, long places, java.math.RoundingMode roundingMode)Roundsxto the specified number of places using the specified rounding mode.static ApfloatroundToPrecision(Aprational x, long precision, java.math.RoundingMode roundingMode)Rounds the given number to the specified precision with the specified rounding mode.static Aprationalscale(Aprational x, long scale)Multiply by a power of the radix.static Aprationalsum(Aprational... x)Sum of numbers.
-
-
-
Method Detail
-
pow
public static Aprational pow(Aprational x, long n) throws java.lang.ArithmeticException, ApfloatRuntimeException
Integer power.- Parameters:
x- Base of the power operator.n- Exponent of the power operator.- Returns:
xto then:th power, that isxn.- Throws:
java.lang.ArithmeticException- If bothxandnare zero.ApfloatRuntimeException
-
negate
@Deprecated public static Aprational negate(Aprational x) throws ApfloatRuntimeException
Deprecated.UseAprational.negate().Returns an aprational whose value is-x.- Parameters:
x- The argument.- Returns:
-x.- Throws:
ApfloatRuntimeException
-
abs
public static Aprational abs(Aprational x) throws ApfloatRuntimeException
Absolute value.- Parameters:
x- The argument.- Returns:
- Absolute value of
x. - Throws:
ApfloatRuntimeException
-
copySign
public static Aprational copySign(Aprational x, Aprational y) throws ApfloatRuntimeException
Copy sign from one argument to another.- Parameters:
x- The value whose sign is to be adjusted.y- The value whose sign is to be used.- Returns:
xwith its sign changed to match the sign ofy.- Throws:
ApfloatRuntimeException- Since:
- 1.1
-
scale
public static Aprational scale(Aprational x, long scale) throws ApfloatRuntimeException
Multiply by a power of the radix. Note that this method is prone to intermediate overflow errors. Also, scaling by a very large negative number won't result in an underflow and a zero result, but an overflow of the denominator and an exception thrown.- Parameters:
x- The argument.scale- The scaling factor.- Returns:
x * x.radix()scale.- Throws:
ApfloatRuntimeException
-
round
@Deprecated public static Apfloat round(Aprational x, long precision, java.math.RoundingMode roundingMode) throws java.lang.IllegalArgumentException, java.lang.ArithmeticException, ApfloatRuntimeException
Deprecated.Rounds the given number to the specified precision with the specified rounding mode.- Parameters:
x- The number to round.precision- The precision to round to.roundingMode- The rounding mode to use.- Returns:
- The rounded number.
- Throws:
java.lang.IllegalArgumentException- Ifprecisionis less than zero or zero.java.lang.ArithmeticException- If rounding is necessary (result is not exact) and rounding mode isRoundingMode.UNNECESSARY.ApfloatRuntimeException- Since:
- 1.7.0
-
roundToPrecision
public static Apfloat roundToPrecision(Aprational x, long precision, java.math.RoundingMode roundingMode) throws java.lang.IllegalArgumentException, java.lang.ArithmeticException, ApfloatRuntimeException
Rounds the given number to the specified precision with the specified rounding mode.- Parameters:
x- The number to round.precision- The precision to round to.roundingMode- The rounding mode to use.- Returns:
- The rounded number.
- Throws:
java.lang.IllegalArgumentException- Ifprecisionis less than zero or zero.java.lang.ArithmeticException- If rounding is necessary (result is not exact) and rounding mode isRoundingMode.UNNECESSARY.ApfloatRuntimeException- Since:
- 1.11.0
-
roundToInteger
public static Apint roundToInteger(Aprational x, java.math.RoundingMode roundingMode) throws java.lang.IllegalArgumentException, java.lang.ArithmeticException, ApfloatRuntimeException
Roundsxto integer using the specified rounding mode.- Parameters:
x- The number to round.roundingMode- The rounding mode to use.- Returns:
- The rounded number.
- Throws:
java.lang.ArithmeticException- If rounding is necessary (result is not exact) and rounding mode isRoundingMode.UNNECESSARY.java.lang.IllegalArgumentExceptionApfloatRuntimeException- Since:
- 1.11.0
-
roundToPlaces
public static Apfloat roundToPlaces(Aprational x, long places, java.math.RoundingMode roundingMode) throws java.lang.IllegalArgumentException, java.lang.ArithmeticException, ApfloatRuntimeException
Roundsxto the specified number of places using the specified rounding mode.- Parameters:
x- The number to round.places- The number of places to round to (in base 10, the number of decimal places).roundingMode- The rounding mode to use.- Returns:
- The rounded number.
- Throws:
java.lang.ArithmeticException- If rounding is necessary (result is not exact) and rounding mode isRoundingMode.UNNECESSARY.java.lang.IllegalArgumentExceptionApfloatRuntimeException- Since:
- 1.11.0
-
roundToMultiple
public static Aprational roundToMultiple(Aprational x, Aprational y, java.math.RoundingMode roundingMode) throws java.lang.IllegalArgumentException, java.lang.ArithmeticException, ApfloatRuntimeException
Roundsxto the nearest multiple ofyusing the specified rounding mode.- Parameters:
x- The number to round.y- The integer multiple to round to.roundingMode- The rounding mode to use.- Returns:
- The rounded number.
- Throws:
java.lang.ArithmeticException- If rounding is necessary (result is not exact) and rounding mode isRoundingMode.UNNECESSARY.java.lang.IllegalArgumentExceptionApfloatRuntimeException- Since:
- 1.11.0
-
product
public static Aprational product(Aprational... x) throws ApfloatRuntimeException
Product of numbers. This method may perform significantly better than simply multiplying the numbers sequentially.If there are no arguments, the return value is
1.- Parameters:
x- The argument(s).- Returns:
- The product of the given numbers.
- Throws:
ApfloatRuntimeException- Since:
- 1.3
-
sum
public static Aprational sum(Aprational... x) throws ApfloatRuntimeException
Sum of numbers. This method may perform significantly better than simply adding the numbers sequentially.If there are no arguments, the return value is
0.- Parameters:
x- The argument(s).- Returns:
- The sum of the given numbers.
- Throws:
ApfloatRuntimeException- Since:
- 1.3
-
continuedFraction
public static Apint[] continuedFraction(Aprational x, int n)
Generates the firstnterms in the continued fraction representation ofx.Note that the result length might be less than
n, depending on the input value.- Parameters:
x- The number whose continued fraction terms should be generated.n- The maximum number of terms to generate.- Returns:
- The continued fraction.
- Throws:
java.lang.IllegalArgumentException- Ifnis less than one.- Since:
- 1.12.0
-
convergents
public static Aprational[] convergents(Aprational x, int n)
Generates the firstnconvergents corresponding to the continued fraction ofx.Note that the result length might be less than
n, depending on the input value.- Parameters:
x- The number whose continued fraction convergents should be generated.n- The maximum number of convergents to generate.- Returns:
- The convergents.
- Throws:
java.lang.IllegalArgumentException- Ifnis less than one.- Since:
- 1.12.0
-
max
public static Aprational max(Aprational x, Aprational y) throws ApfloatRuntimeException
Returns the greater of the two values.- Parameters:
x- An argument.y- Another argument.- Returns:
- The greater of the two values.
- Throws:
ApfloatRuntimeException- Since:
- 1.9.0
-
min
public static Aprational min(Aprational x, Aprational y) throws ApfloatRuntimeException
Returns the smaller of the two values.- Parameters:
x- An argument.y- Another argument.- Returns:
- The smaller of the two values.
- Throws:
ApfloatRuntimeException- Since:
- 1.9.0
-
binomial
public static Aprational binomial(Aprational n, Aprational k) throws java.lang.ArithmeticException, ApfloatRuntimeException
Binomial coefficient.- Parameters:
n- The first argument.k- The second argument.- Returns:
- Throws:
java.lang.ArithmeticException- If the result is not finite or not a rational number.ApfloatRuntimeException- Since:
- 1.11.0
-
pochhammer
public static Aprational pochhammer(Aprational x, Apint n)
Pochhammer symbol.- Parameters:
x- The first argument.n- The second argument.- Returns:
(x)n- Since:
- 1.13.0
-
bernoulli
public static Aprational bernoulli(long n) throws java.lang.IllegalArgumentException, ApfloatRuntimeException
Returns the specified Bernoulli number. The default radix is used.- Parameters:
n- The argument.- Returns:
- The Bernoulli number
Bn. - Throws:
java.lang.IllegalArgumentException- Ifn < 0.ApfloatRuntimeException- Since:
- 1.11.0
-
bernoulli
public static Aprational bernoulli(long n, int radix) throws java.lang.IllegalArgumentException, java.lang.NumberFormatException, ApfloatRuntimeException
Returns the specified Bernoulli number in the given radix.- Parameters:
n- The argument.radix- The radix.- Returns:
- The Bernoulli number
Bn. - Throws:
java.lang.IllegalArgumentException- Ifn < 0.java.lang.NumberFormatException- If the radix is not valid.ApfloatRuntimeException- Since:
- 1.11.0
-
bernoulliSmall
static Aprational bernoulliSmall(long n, int radix)
-
bernoulliBig
static Aprational bernoulliBig(long n, int radix)
-
bernoullis
static java.util.Iterator<Aprational> bernoullis(long n, int radix)
-
bernoullis2
static java.util.Iterator<Aprational> bernoullis2(long n, int radix)
-
bernoullisSmall
static java.util.Iterator<Aprational> bernoullisSmall(int radix)
-
bernoullis2Small
static java.util.Iterator<Aprational> bernoullis2Small(int radix)
-
bernoullisBig
static java.util.Iterator<Aprational> bernoullisBig(long n, int radix)
-
bernoullis2Big
static java.util.Iterator<Aprational> bernoullis2Big(long n, int radix)
-
harmonicNumber
public static Aprational harmonicNumber(Apint n) throws java.lang.ArithmeticException, ApfloatRuntimeException
Harmonic number.- Parameters:
n- The argument.- Returns:
- Hn
- Throws:
java.lang.ArithmeticException- Ifnis negative.ApfloatRuntimeException- Since:
- 1.14.0
-
harmonicNumber
public static Aprational harmonicNumber(Apint n, Apint r) throws java.lang.ArithmeticException, ApfloatRuntimeException
Generalized harmonic number.- Parameters:
n- The first argument.r- The second argument.- Returns:
- Hn(r)
- Throws:
java.lang.ArithmeticException- Ifnis negative andris positive.ApfloatRuntimeException- Since:
- 1.14.0
-
harmonicNumber
private static Apint[] harmonicNumber(Apint n, Apint m, long r) throws java.lang.ArithmeticException, ApfloatRuntimeException
- Throws:
java.lang.ArithmeticExceptionApfloatRuntimeException
-
recursiveSum
private static Aprational recursiveSum(Aprational[] x, int n, int m) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
-