Package org.apfloat
Class FixedPrecisionApfloatHelper
java.lang.Object
org.apfloat.FixedPrecisionApcomplexHelper
org.apfloat.FixedPrecisionApfloatHelper
Fixed-precision mathematical functions for floating-point numbers.
All results of the mathematical operations are set to have the specified precision.
Also all input arguments are set to the specified precision before the operation.
If the specified precision is not infinite, this helper class also avoids
InfiniteExpansionException
e.g. in case where it would happen with
ApfloatMath.acos(Apfloat.ZERO)
.
- Since:
- 1.5
- Version:
- 1.12.0
- Author:
- Mikko Tommila
-
Constructor Summary
ConstructorsConstructorDescriptionFixedPrecisionApfloatHelper
(long precision) Constructs an apfloat fixed-precison helper with the specified precision. -
Method Summary
Modifier and TypeMethodDescriptionAbsolute value.Arc cosine.Hyperbolic arc cosine.Addition.Arithmetic-geometric mean.Arc sine.Hyperbolic arc sine.Arc tangent.Angle of point.Hyperbolic arc tangent.Binomial coefficient.Cube root.Ceiling function.Apfloat[]
continuedFraction
(Apfloat x, int n) Continued fraction.Apfloat[]
convergents
(Apfloat x, int n) Convergents.Copies the sign from one number to another.Cosine.Hyperbolic cosine.Digamma function.Division.Exponential function.factorial
(long n) Factorial.factorial
(long n, int radix) Factorial.Floor function.Modulus.Extract fractional part.Gamma function.Incomplete gamma function.Generalized incomplete gamma function.hypergeometric0F1
(Apfloat a, Apfloat x) Confluent hypergeometric function 0F1.hypergeometric1F1
(Apfloat a, Apfloat b, Apfloat x) Kummer confluent hypergeometric function 1F1.hypergeometric2F1
(Apfloat a, Apfloat b, Apfloat c, Apfloat x) Hypergeometric function 2F1.inverseRoot
(Apfloat x, long n) Inverse root.Natural logarithm.Logarithm in specified base.Logarithm of the gamma function.logRadix
(int radix) Logarithm.Maximum value.Minimum value.Modulus.Apfloat[]
Split to integer and fractional parts.Multiplication.multiplyAdd
(Apfloat a, Apfloat b, Apfloat c, Apfloat d) Fused multiply-add.multiplySubtract
(Apfloat a, Apfloat b, Apfloat c, Apfloat d) Fused multiply-subtract.Negation.The number adjacent to the first argument in the direction of the second argument.The adjacent value closer to negative infinity.The adjacent value closer to positive infinity.pi()
π.pi
(int radix) π.Integer power.Power.Product.random()
Return a uniformly distributed random number0 ≤ x < 1
.random
(int radix) Return a uniformly distributed random number0 ≤ x < 1
.Return a normally distributed random number with mean 0 and standard deviation 1.randomGaussian
(int radix) Return a normally distributed random number with mean 0 and standard deviation 1.Root.round
(Apfloat x, RoundingMode roundingMode) Deprecated.roundToInteger
(Apfloat x, RoundingMode roundingMode) Round to integer with specified rounding mode.roundToMultiple
(Apfloat x, Apfloat y, RoundingMode roundingMode) Round to multiple with specified rounding mode.roundToPlaces
(Apfloat x, long places, RoundingMode roundingMode) Round to specified number of places with specified rounding mode.roundToPrecision
(Apfloat x, RoundingMode roundingMode) Round to precision with specified rounding mode.Move the radix point.Sine.Hyperbolic sine.Square root.Subtraction.Sum.Tangent.Hyperbolic tangent.Convert radians to degrees.Convert degrees to radians.Truncate fractional part.Unit in the last place.Returns the value with the specified precision.Lambert W function.Riemann zeta function.Hurwitz zeta function.Methods inherited from class org.apfloat.FixedPrecisionApcomplexHelper
abs, acos, acosh, add, agm, allRoots, arg, asin, asinh, atan, atanh, bernoulli, bernoulli, binomial, binomial, binomial, catalan, catalan, cbrt, conj, cos, cosh, digamma, divide, e, e, euler, euler, exp, gamma, gamma, gamma, glaisher, glaisher, hypergeometric0F1, hypergeometric1F1, hypergeometric2F1, imag, inverseRoot, inverseRoot, khinchin, khinchin, log, log, logGamma, multiply, negate, norm, pow, pow, precision, product, real, root, root, scale, sin, sinh, sqrt, subtract, sum, tan, tanh, ulp, valueOf, w, w, zeta, zeta
-
Constructor Details
-
FixedPrecisionApfloatHelper
Constructs an apfloat fixed-precison helper with the specified precision. The results of all mathematical operations are set to the specified precision.- Parameters:
precision
- The precision of the results.- Throws:
IllegalArgumentException
- In case the precision is invalid.
-
-
Method Details
-
valueOf
Returns the value with the specified precision.- Parameters:
x
- The value.- Returns:
- The value with to the specified precision.
-
negate
Negation.- Parameters:
x
- The value to negate.- Returns:
-x
.- Throws:
ApfloatRuntimeException
-
add
Addition.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
x + y
.- Throws:
ApfloatRuntimeException
-
subtract
Subtraction.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
x - y
.- Throws:
ApfloatRuntimeException
-
multiply
Multiplication.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
x * y
.- Throws:
ApfloatRuntimeException
-
divide
Division.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
x / y
.- Throws:
ArithmeticException
- Ify
is zero.ApfloatRuntimeException
-
pow
Power.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
xy
.- Throws:
ArithmeticException
- Ifx
andy
are zero, orx
is negative andy
is not an integer.ApfloatRuntimeException
-
pow
Integer power.- Parameters:
x
- The first operand.n
- The second operand.- Returns:
xn
.- Throws:
ArithmeticException
- Ifx
andn
are zero, orx
is zero andn
is negative.ApfloatRuntimeException
-
abs
Absolute value.- Parameters:
x
- The operand.- Returns:
- The absolute value of
x
. - Throws:
ApfloatRuntimeException
-
acos
Arc cosine.- Parameters:
x
- The operand.- Returns:
- The arc cosine of
x
. - Throws:
ArithmeticException
- If the absolute value ofx
is more than one.ApfloatRuntimeException
-
acosh
Hyperbolic arc cosine.- Parameters:
x
- The operand.- Returns:
- The hyperbolic arc cosine of
x
. - Throws:
ArithmeticException
- If thex
is less than one.ApfloatRuntimeException
-
asin
Arc sine.- Parameters:
x
- The operand.- Returns:
- The arc sine of
x
. - Throws:
ArithmeticException
- If the absolute value ofx
is more than one.ApfloatRuntimeException
-
asinh
Hyperbolic arc sine.- Parameters:
x
- The operand.- Returns:
- The hyperbolic arc sine of
x
. - Throws:
ApfloatRuntimeException
-
atan
Arc tangent.- Parameters:
x
- The operand.- Returns:
- The arc tangent of
x
. - Throws:
ApfloatRuntimeException
-
atanh
Hyperbolic arc tangent.- Parameters:
x
- The operand.- Returns:
- The hyperbolic arc tangent of
x
. - Throws:
ArithmeticException
- If the absolute value ofx
is equal to or more than one.ApfloatRuntimeException
-
cbrt
Cube root.- Parameters:
x
- The operand.- Returns:
- The cube root of
x
. - Throws:
ApfloatRuntimeException
-
cos
Cosine.- Parameters:
x
- The operand.- Returns:
- The cosine of
x
. - Throws:
ApfloatRuntimeException
-
cosh
Hyperbolic cosine.- Parameters:
x
- The operand.- Returns:
- The hyperbolic cosine of
x
. - Throws:
ApfloatRuntimeException
-
exp
Exponential function.- Parameters:
x
- The operand.- Returns:
ex
.- Throws:
ApfloatRuntimeException
-
log
Natural logarithm.- Parameters:
x
- The operand.- Returns:
- The natural logarithm of
x
. - Throws:
ArithmeticException
- Ifx
is less than or equal to zero.ApfloatRuntimeException
-
log
Logarithm in specified base.- Parameters:
x
- The operand.b
- The base.- Returns:
- The base-
b
logarithm ofx
. - Throws:
ArithmeticException
- Ifx
orb
is less than or equal to zero.ApfloatRuntimeException
- Since:
- 1.6
-
sin
Sine.- Parameters:
x
- The operand.- Returns:
- The sine of
x
. - Throws:
ApfloatRuntimeException
-
sinh
Hyperbolic sine.- Parameters:
x
- The operand.- Returns:
- The hyperbolic sine of
x
. - Throws:
ApfloatRuntimeException
-
sqrt
Square root.- Parameters:
x
- The operand.- Returns:
- The square root of
x
. - Throws:
ArithmeticException
- Ifx
is negative.ApfloatRuntimeException
-
tan
Tangent.- Parameters:
x
- The operand.- Returns:
- The tangent of
x
. - Throws:
ArithmeticException
- Ifx
is π/2 + n π where n is an integer.ApfloatRuntimeException
-
tanh
Hyperbolic tangent.- Parameters:
x
- The operand.- Returns:
- The hyperbolic tangent of
x
. - Throws:
ApfloatRuntimeException
-
agm
Arithmetic-geometric mean.- Parameters:
a
- The first operand.b
- The first operand.- Returns:
- The arithmetic-geometric mean of
a
andb
. - Throws:
ApfloatRuntimeException
-
inverseRoot
Inverse root.- Parameters:
x
- The operand.n
- Which inverse root to take.- Returns:
x-1/n
.- Throws:
ArithmeticException
- Ifx
orn
is zero, orx
is negative andn
is even.ApfloatRuntimeException
-
root
Root.- Parameters:
x
- The operand.n
- Which root to take.- Returns:
x1/n
.- Throws:
ArithmeticException
- Ifn
is zero, orx
is negative andn
is even.ApfloatRuntimeException
-
scale
Move the radix point.- Parameters:
x
- The operand.scale
- The amount to move the radix point.- Returns:
x * x.radix()scale
.- Throws:
ApfloatRuntimeException
-
mod
Modulus.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
x % y
.- Throws:
ApfloatRuntimeException
-
ceil
Ceiling function.- Parameters:
x
- The operand.- Returns:
- The nearest integer greater than or equal to
x
. - Throws:
ApfloatRuntimeException
-
floor
Floor function.- Parameters:
x
- The operand.- Returns:
- The nearest integer less than or equal to
x
. - Throws:
ApfloatRuntimeException
-
truncate
Truncate fractional part.- Parameters:
x
- The operand.- Returns:
- The nearest integer rounded towards zero from
x
. - Throws:
ApfloatRuntimeException
-
frac
Extract fractional part.- Parameters:
x
- The operand.- Returns:
- The fractional part of
x
. - Throws:
ApfloatRuntimeException
- Since:
- 1.7.0
-
round
@Deprecated public Apfloat round(Apfloat x, RoundingMode roundingMode) throws ApfloatRuntimeException Deprecated.Round with specified rounding mode.- Parameters:
x
- The operand.roundingMode
- The rounding mode.- Returns:
x
rounded with the specified rounding mode.- Throws:
ApfloatRuntimeException
- Since:
- 1.7.0
-
roundToPrecision
public Apfloat roundToPrecision(Apfloat x, RoundingMode roundingMode) throws ApfloatRuntimeException Round to precision with specified rounding mode.- Parameters:
x
- The operand.roundingMode
- The rounding mode.- Returns:
x
rounded to the precision of this helper with the specified rounding mode.- Throws:
ArithmeticException
- If rounding is necessary (result is not exact) and rounding mode isRoundingMode.UNNECESSARY
.ApfloatRuntimeException
- Since:
- 1.11.0
-
roundToInteger
public Apfloat roundToInteger(Apfloat x, RoundingMode roundingMode) throws ApfloatRuntimeException, ArithmeticException Round to integer with specified rounding mode.- Parameters:
x
- The operand.roundingMode
- The rounding mode.- Returns:
x
rounded to integer with the specified rounding mode.- Throws:
ArithmeticException
- If rounding is necessary (result is not exact) and rounding mode isRoundingMode.UNNECESSARY
.ApfloatRuntimeException
- Since:
- 1.11.0
-
roundToPlaces
public Apfloat roundToPlaces(Apfloat x, long places, RoundingMode roundingMode) throws ApfloatRuntimeException, ArithmeticException Round to specified number of places with specified rounding mode.- Parameters:
x
- The operand.places
- The number of places.roundingMode
- The rounding mode.- Returns:
x
rounded to the specified number of places with the specified rounding mode.- Throws:
ArithmeticException
- If rounding is necessary (result is not exact) and rounding mode isRoundingMode.UNNECESSARY
.ApfloatRuntimeException
- Since:
- 1.11.0
-
roundToMultiple
public Apfloat roundToMultiple(Apfloat x, Apfloat y, RoundingMode roundingMode) throws ApfloatRuntimeException, ArithmeticException Round to multiple with specified rounding mode.- Parameters:
x
- The number to round.y
- The integer multiple to round to.roundingMode
- The rounding mode.- Returns:
x
rounded to the nearest multiple ofy
with the specified rounding mode.- Throws:
ArithmeticException
- If rounding is necessary (result is not exact) and rounding mode isRoundingMode.UNNECESSARY
.ApfloatRuntimeException
- Since:
- 1.11.0
-
w
Lambert W function.- Parameters:
x
- The operand.- Returns:
W0(x)
.- Throws:
ApfloatRuntimeException
- Since:
- 1.8.0
-
toDegrees
Convert radians to degrees.- Parameters:
x
- The angle in radians.- Returns:
x
converted to degrees.- Throws:
ApfloatRuntimeException
- Since:
- 1.8.0
-
toRadians
Convert degrees to radians.- Parameters:
x
- The angle in degrees.- Returns:
x
converted to radians.- Throws:
ApfloatRuntimeException
- Since:
- 1.8.0
-
atan2
Angle of point.- Parameters:
x
- The operand.y
- The operand.- Returns:
- The angle of the point
(y, x)
. - Throws:
ArithmeticException
- Ifx
andy
are zero.ApfloatRuntimeException
-
copySign
Copies the sign from one number to another.- Parameters:
x
- The number to copy the sign to.y
- The number to copy the sign from.- Returns:
x
with the sign ofy
.- Throws:
ApfloatRuntimeException
-
fmod
Modulus.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
x % y
.- Throws:
ApfloatRuntimeException
-
modf
Split to integer and fractional parts.- Parameters:
x
- The operand.- Returns:
- An array of two numbers
[i, f]
wherei
isfloor(x)
andf
isx - floor(x)
. - Throws:
ApfloatRuntimeException
-
factorial
Factorial.- Parameters:
n
- The operand.- Returns:
n!
.- Throws:
ApfloatRuntimeException
-
factorial
Factorial.- Parameters:
n
- The operand.radix
- The radix of the result.- Returns:
n!
.- Throws:
ApfloatRuntimeException
-
pi
π.- Returns:
π
.- Throws:
ApfloatRuntimeException
-
pi
π.- Parameters:
radix
- The radix of the result.- Returns:
π
.- Throws:
NumberFormatException
- If the radix is invalid.ApfloatRuntimeException
-
logRadix
Logarithm.- Parameters:
radix
- The radix of the result.- Returns:
log(radix)
.- Throws:
NumberFormatException
- If the radix is invalid.ApfloatRuntimeException
-
multiplyAdd
public Apfloat multiplyAdd(Apfloat a, Apfloat b, Apfloat c, Apfloat d) throws ApfloatRuntimeException Fused multiply-add.- Parameters:
a
- The first operand.b
- The second operand.c
- The third operand.d
- The fourth operand.- Returns:
a * b + c * d
.- Throws:
ApfloatRuntimeException
-
multiplySubtract
public Apfloat multiplySubtract(Apfloat a, Apfloat b, Apfloat c, Apfloat d) throws ApfloatRuntimeException Fused multiply-subtract.- Parameters:
a
- The first operand.b
- The second operand.c
- The third operand.d
- The fourth operand.- Returns:
a * b - c * d
.- Throws:
ApfloatRuntimeException
-
product
Product.- Parameters:
x
- The operand(s).- Returns:
- The product of the operands.
- Throws:
ApfloatRuntimeException
-
sum
Sum.- Parameters:
x
- The operand(s).- Returns:
- The sum of the operands.
- Throws:
ApfloatRuntimeException
-
gamma
Gamma function.- Parameters:
x
- The operand.- Returns:
Γ(x)
.- Throws:
ArithmeticException
- Ifx
is a nonpositive integer.ApfloatRuntimeException
- Since:
- 1.9.0
-
gamma
Incomplete gamma function.- Parameters:
a
- The first operand.x
- The second operand.- Returns:
Γ(a, x)
.- Throws:
ArithmeticException
- Ifa
is not a positive integer andx
is nonpositive.ApfloatRuntimeException
- Since:
- 1.10.0
-
gamma
public Apfloat gamma(Apfloat a, Apfloat x0, Apfloat x1) throws ArithmeticException, ApfloatRuntimeException Generalized incomplete gamma function.- Parameters:
a
- The first operand.x0
- The second operand.x1
- The third operand.- Returns:
Γ(a, x0) - Γ(a, x1)
.- Throws:
ArithmeticException
- Ifa
is not a positive integer and eitherx0
orx1
is nonpositive.ApfloatRuntimeException
- Since:
- 1.10.0
-
logGamma
Logarithm of the gamma function.- Parameters:
x
- The argument.- Returns:
logΓ(x)
- Throws:
ArithmeticException
- Ifx
is nonpositive.ApfloatRuntimeException
- Since:
- 1.11.0
-
digamma
Digamma function.- Parameters:
x
- The argument.- Returns:
ψ(x)
- Throws:
ArithmeticException
- Ifx
is a nonpositive integer.ApfloatRuntimeException
- Since:
- 1.11.0
-
binomial
Binomial coefficient.- Parameters:
n
- The argument.k
- The argument.- Returns:
- The binomial coefficient.
- Throws:
ArithmeticException
- Ifn
,k
orn - k
is a nonpositive integer.ApfloatRuntimeException
- Since:
- 1.11.0
-
zeta
Riemann zeta function.- Parameters:
s
- The argument.- Returns:
ζ(s)
- Throws:
ArithmeticException
- Ifs
is1
.ApfloatRuntimeException
- Since:
- 1.11.0
-
zeta
Hurwitz zeta function.- Parameters:
s
- The first argument.a
- The second argument.- Returns:
ζ(s, a)
- Throws:
ArithmeticException
- Ifs
is1
or ifa
is a nonpositive integer or ifs
is not an integer anda
is nonpositive.ApfloatRuntimeException
- Since:
- 1.11.0
-
hypergeometric0F1
public Apfloat hypergeometric0F1(Apfloat a, Apfloat x) throws ArithmeticException, ApfloatRuntimeException Confluent hypergeometric function 0F1.- Parameters:
a
- The first argument.x
- The second argument.- Returns:
- 0F1(; a; x)
- Throws:
ArithmeticException
- If the function value is not finite.ApfloatRuntimeException
- Since:
- 1.11.0
-
hypergeometric1F1
public Apfloat hypergeometric1F1(Apfloat a, Apfloat b, Apfloat x) throws ArithmeticException, ApfloatRuntimeException Kummer confluent hypergeometric function 1F1.- Parameters:
a
- The first argument.b
- The second argument.x
- The third argument.- Returns:
- 1F1(a; b; x)
- Throws:
ArithmeticException
- If the function value is not finite.ApfloatRuntimeException
- Since:
- 1.11.0
-
hypergeometric2F1
public Apfloat hypergeometric2F1(Apfloat a, Apfloat b, Apfloat c, Apfloat x) throws ArithmeticException, ApfloatRuntimeException Hypergeometric function 2F1.- Parameters:
a
- The first argument.b
- The second argument.c
- The third argument.x
- The fourth argument.- Returns:
- 2F1(a, b; c; x)
- Throws:
ArithmeticException
- If the function value is not finite or real.ApfloatRuntimeException
- Since:
- 1.11.0
-
random
Return a uniformly distributed random number0 ≤ x < 1
.- Returns:
- A random number.
- Throws:
ApfloatRuntimeException
- Since:
- 1.9.0
-
random
Return a uniformly distributed random number0 ≤ x < 1
.- Parameters:
radix
- The radix of the number.- Returns:
- A random number.
- Throws:
NumberFormatException
- If the radix is invalid.ApfloatRuntimeException
- Since:
- 1.9.0
-
randomGaussian
Return a normally distributed random number with mean 0 and standard deviation 1.- Returns:
- A random number.
- Throws:
ApfloatRuntimeException
- Since:
- 1.9.0
-
randomGaussian
Return a normally distributed random number with mean 0 and standard deviation 1.- Parameters:
radix
- The radix of the number.- Returns:
- A random number.
- Throws:
NumberFormatException
- If the radix is invalid.ApfloatRuntimeException
- Since:
- 1.9.0
-
continuedFraction
Continued fraction.- Parameters:
x
- The value.n
- Maximum number of terms.- Returns:
- The continued fraction.
- Throws:
IllegalArgumentException
- Ifn
is less than one.ApfloatRuntimeException
- Since:
- 1.12.0
-
convergents
Convergents.- Parameters:
x
- The value.n
- Maximum number of convergents.- Returns:
- The convergents.
- Throws:
IllegalArgumentException
- Ifn
is less than one.ApfloatRuntimeException
- Since:
- 1.12.0
-
max
Maximum value.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
- The maximum of
x
andy
. - Throws:
ApfloatRuntimeException
- Since:
- 1.9.0
-
min
Minimum value.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
- The minimum of
x
andy
. - Throws:
ApfloatRuntimeException
- Since:
- 1.9.0
-
nextAfter
The number adjacent to the first argument in the direction of the second argument.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
- The number adjacent to the first argument in the direction of the second argument.
- Throws:
ApfloatRuntimeException
- Since:
- 1.10.0
-
nextDown
The adjacent value closer to negative infinity.- Parameters:
x
- The operand.- Returns:
- The adjacent value closer to negative infinity.
- Throws:
ApfloatRuntimeException
- Since:
- 1.10.0
-
nextUp
The adjacent value closer to positive infinity.- Parameters:
x
- The operand.- Returns:
- The adjacent value closer to positive infinity.
- Throws:
ApfloatRuntimeException
- Since:
- 1.10.0
-
ulp
Unit in the last place.- Parameters:
x
- The operand.- Returns:
- The unit in the last place.
- Throws:
ApfloatRuntimeException
- Since:
- 1.10.0
-
roundToPrecision(Apfloat,RoundingMode)
.