Package org.apfloat
Class FixedPrecisionApfloatHelper
- java.lang.Object
-
- org.apfloat.FixedPrecisionApcomplexHelper
-
- org.apfloat.FixedPrecisionApfloatHelper
-
public class FixedPrecisionApfloatHelper extends FixedPrecisionApcomplexHelper
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 withApfloatMath.acos(Apfloat.ZERO)
.- Since:
- 1.5
- Version:
- 1.9.0
- Author:
- Mikko Tommila
-
-
Constructor Summary
Constructors Constructor Description FixedPrecisionApfloatHelper(long precision)
Constructs an apfloat fixed-precison helper with the specified precision.
-
Method Summary
Modifier and Type Method Description Apfloat
abs(Apfloat x)
Absolute value.Apfloat
acos(Apfloat x)
Arc cosine.Apfloat
acosh(Apfloat x)
Hyperbolic arc cosine.Apfloat
add(Apfloat x, Apfloat y)
Addition.Apfloat
agm(Apfloat a, Apfloat b)
Arithmetic-geometric mean.Apfloat
asin(Apfloat x)
Arc sine.Apfloat
asinh(Apfloat x)
Hyperbolic arc sine.Apfloat
atan(Apfloat x)
Arc tangent.Apfloat
atan2(Apfloat x, Apfloat y)
Angle of point.Apfloat
atanh(Apfloat x)
Hyperbolic arc tangent.Apfloat
cbrt(Apfloat x)
Cube root.Apfloat
ceil(Apfloat x)
Ceiling function.Apfloat
copySign(Apfloat x, Apfloat y)
Copies the sign from one number to another.Apfloat
cos(Apfloat x)
Cosine.Apfloat
cosh(Apfloat x)
Hyperbolic cosine.Apfloat
divide(Apfloat x, Apfloat y)
Division.Apfloat
exp(Apfloat x)
Exponential function.Apfloat
factorial(long n)
Factorial.Apfloat
factorial(long n, int radix)
Factorial.Apfloat
floor(Apfloat x)
Floor function.Apfloat
fmod(Apfloat x, Apfloat y)
Modulus.Apfloat
frac(Apfloat x)
Extract fractional part.Apfloat
gamma(Apfloat x)
Gamma function.Apfloat
inverseRoot(Apfloat x, long n)
Inverse root.Apfloat
log(Apfloat x)
Natural logarithm.Apfloat
log(Apfloat x, Apfloat b)
Logarithm in specified base.Apfloat
logRadix(int radix)
Logarithm.Apfloat
max(Apfloat x, Apfloat y)
Maximum value.Apfloat
min(Apfloat x, Apfloat y)
Minimum value.Apfloat
mod(Apfloat x, Apfloat y)
Modulus.Apfloat[]
modf(Apfloat x)
Split to integer and fractional parts.Apfloat
multiply(Apfloat x, Apfloat y)
Multiplication.Apfloat
multiplyAdd(Apfloat a, Apfloat b, Apfloat c, Apfloat d)
Fused multiply-add.Apfloat
multiplySubtract(Apfloat a, Apfloat b, Apfloat c, Apfloat d)
Fused multiply-subtract.Apfloat
negate(Apfloat x)
Negation.Apfloat
pi()
π.Apfloat
pi(int radix)
π.Apfloat
pow(Apfloat x, long n)
Integer power.Apfloat
pow(Apfloat x, Apfloat y)
Power.Apfloat
product(Apfloat... x)
Product.Apfloat
random()
Return a uniformly distributed random number0 ≤ x < 1
.Apfloat
random(int radix)
Return a uniformly distributed random number0 ≤ x < 1
.Apfloat
randomGaussian()
Return a normally distributed random number with mean 0 and standard deviation 1.Apfloat
randomGaussian(int radix)
Return a normally distributed random number with mean 0 and standard deviation 1.Apfloat
root(Apfloat x, long n)
Root.Apfloat
round(Apfloat x, RoundingMode roundingMode)
Round with specified rounding mode.Apfloat
scale(Apfloat x, long scale)
Move the radix point.Apfloat
sin(Apfloat x)
Sine.Apfloat
sinh(Apfloat x)
Hyperbolic sine.Apfloat
sqrt(Apfloat x)
Square root.Apfloat
subtract(Apfloat x, Apfloat y)
Subtraction.Apfloat
sum(Apfloat... x)
Sum.Apfloat
tan(Apfloat x)
Tangent.Apfloat
tanh(Apfloat x)
Hyperbolic tangent.Apfloat
toDegrees(Apfloat x)
Convert radians to degrees.Apfloat
toRadians(Apfloat x)
Convert degrees to radians.Apfloat
truncate(Apfloat x)
Truncate fractional part.Apfloat
valueOf(Apfloat x)
Returns the value with the specified precision.Apfloat
w(Apfloat x)
Lambert W function.-
Methods inherited from class org.apfloat.FixedPrecisionApcomplexHelper
abs, acos, acosh, add, agm, allRoots, arg, asin, asinh, atan, atanh, cbrt, conj, cos, cosh, divide, exp, gamma, imag, inverseRoot, inverseRoot, log, log, multiply, negate, norm, pow, pow, precision, product, real, root, root, scale, sin, sinh, sqrt, subtract, sum, tan, tanh, valueOf, w, w
-
-
-
-
Constructor Detail
-
FixedPrecisionApfloatHelper
public FixedPrecisionApfloatHelper(long precision) throws IllegalArgumentException
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 Detail
-
valueOf
public Apfloat valueOf(Apfloat x)
Returns the value with the specified precision.- Parameters:
x
- The value.- Returns:
- The value with to the specified precision.
-
negate
public Apfloat negate(Apfloat x) throws ApfloatRuntimeException
Negation.- Parameters:
x
- The value to negate.- Returns:
-x
.- Throws:
ApfloatRuntimeException
-
add
public Apfloat add(Apfloat x, Apfloat y) throws ApfloatRuntimeException
Addition.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
x + y
.- Throws:
ApfloatRuntimeException
-
subtract
public Apfloat subtract(Apfloat x, Apfloat y) throws ApfloatRuntimeException
Subtraction.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
x - y
.- Throws:
ApfloatRuntimeException
-
multiply
public Apfloat multiply(Apfloat x, Apfloat y) throws ApfloatRuntimeException
Multiplication.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
x * y
.- Throws:
ApfloatRuntimeException
-
divide
public Apfloat divide(Apfloat x, Apfloat y) throws ArithmeticException, ApfloatRuntimeException
Division.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
x / y
.- Throws:
ArithmeticException
- Ify
is zero.ApfloatRuntimeException
-
pow
public Apfloat pow(Apfloat x, Apfloat y) throws ArithmeticException, ApfloatRuntimeException
Power.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
xy
.- Throws:
ArithmeticException
- Ifx
andy
are zero, orx
is negative.ApfloatRuntimeException
-
pow
public Apfloat pow(Apfloat x, long n) throws ArithmeticException, ApfloatRuntimeException
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
public Apfloat abs(Apfloat x) throws ApfloatRuntimeException
Absolute value.- Parameters:
x
- The operand.- Returns:
- The absolute value of
x
. - Throws:
ApfloatRuntimeException
-
acos
public Apfloat acos(Apfloat x) throws ArithmeticException, ApfloatRuntimeException
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
public Apfloat acosh(Apfloat x) throws ArithmeticException, ApfloatRuntimeException
Hyperbolic arc cosine.- Parameters:
x
- The operand.- Returns:
- The hyperbolic arc cosine of
x
. - Throws:
ArithmeticException
- If thex
is less than one.ApfloatRuntimeException
-
asin
public Apfloat asin(Apfloat x) throws ArithmeticException, ApfloatRuntimeException
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
public Apfloat asinh(Apfloat x) throws ApfloatRuntimeException
Hyperbolic arc sine.- Parameters:
x
- The operand.- Returns:
- The hyperbolic arc sine of
x
. - Throws:
ApfloatRuntimeException
-
atan
public Apfloat atan(Apfloat x) throws ApfloatRuntimeException
Arc tangent.- Parameters:
x
- The operand.- Returns:
- The arc tangent of
x
. - Throws:
ApfloatRuntimeException
-
atanh
public Apfloat atanh(Apfloat x) throws ArithmeticException, ApfloatRuntimeException
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
public Apfloat cbrt(Apfloat x) throws ApfloatRuntimeException
Cube root.- Parameters:
x
- The operand.- Returns:
- The cube root of
x
. - Throws:
ApfloatRuntimeException
-
cos
public Apfloat cos(Apfloat x) throws ApfloatRuntimeException
Cosine.- Parameters:
x
- The operand.- Returns:
- The cosine of
x
. - Throws:
ApfloatRuntimeException
-
cosh
public Apfloat cosh(Apfloat x) throws ApfloatRuntimeException
Hyperbolic cosine.- Parameters:
x
- The operand.- Returns:
- The hyperbolic cosine of
x
. - Throws:
ApfloatRuntimeException
-
exp
public Apfloat exp(Apfloat x) throws ApfloatRuntimeException
Exponential function.- Parameters:
x
- The operand.- Returns:
ex
.- Throws:
ApfloatRuntimeException
-
log
public Apfloat log(Apfloat x) throws ArithmeticException, ApfloatRuntimeException
Natural logarithm.- Parameters:
x
- The operand.- Returns:
- The natural logarithm of
x
. - Throws:
ArithmeticException
- Ifx
is less than or equal to zero.ApfloatRuntimeException
-
log
public Apfloat log(Apfloat x, Apfloat b) throws ArithmeticException, ApfloatRuntimeException
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
public Apfloat sin(Apfloat x) throws ApfloatRuntimeException
Sine.- Parameters:
x
- The operand.- Returns:
- The sine of
x
. - Throws:
ApfloatRuntimeException
-
sinh
public Apfloat sinh(Apfloat x) throws ApfloatRuntimeException
Hyperbolic sine.- Parameters:
x
- The operand.- Returns:
- The hyperbolic sine of
x
. - Throws:
ApfloatRuntimeException
-
sqrt
public Apfloat sqrt(Apfloat x) throws ArithmeticException, ApfloatRuntimeException
Square root.- Parameters:
x
- The operand.- Returns:
- The square root of
x
. - Throws:
ArithmeticException
- Ifx
is negative.ApfloatRuntimeException
-
tan
public Apfloat tan(Apfloat x) throws ArithmeticException, ApfloatRuntimeException
Tangent.- Parameters:
x
- The operand.- Returns:
- The tangent of
x
. - Throws:
ArithmeticException
- Ifx
is π/2 + n π where n is an integer.ApfloatRuntimeException
-
tanh
public Apfloat tanh(Apfloat x) throws ApfloatRuntimeException
Hyperbolic tangent.- Parameters:
x
- The operand.- Returns:
- The hyperbolic tangent of
x
. - Throws:
ApfloatRuntimeException
-
agm
public Apfloat agm(Apfloat a, Apfloat b) throws ApfloatRuntimeException
Arithmetic-geometric mean.- Parameters:
a
- The first operand.b
- The first operand.- Returns:
- The arithmetic-geometric mean of
a
andb
. - Throws:
ApfloatRuntimeException
-
inverseRoot
public Apfloat inverseRoot(Apfloat x, long n) throws ArithmeticException, ApfloatRuntimeException
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
public Apfloat root(Apfloat x, long n) throws ArithmeticException, ApfloatRuntimeException
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
public Apfloat scale(Apfloat x, long scale) throws ApfloatRuntimeException
Move the radix point.- Parameters:
x
- The operand.scale
- The amount to move the radix point.- Returns:
x * x.radix()scale
.- Throws:
ApfloatRuntimeException
-
mod
public Apfloat mod(Apfloat x, Apfloat y) throws ApfloatRuntimeException
Modulus.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
x % y
.- Throws:
ApfloatRuntimeException
-
ceil
public Apfloat ceil(Apfloat x) throws ApfloatRuntimeException
Ceiling function.- Parameters:
x
- The operand.- Returns:
- The nearest integer greater than or equal to
x
. - Throws:
ApfloatRuntimeException
-
floor
public Apfloat floor(Apfloat x) throws ApfloatRuntimeException
Floor function.- Parameters:
x
- The operand.- Returns:
- The nearest integer less than or equal to
x
. - Throws:
ApfloatRuntimeException
-
truncate
public Apfloat truncate(Apfloat x) throws ApfloatRuntimeException
Truncate fractional part.- Parameters:
x
- The operand.- Returns:
- The nearest integer rounded towards zero from
x
. - Throws:
ApfloatRuntimeException
-
frac
public Apfloat frac(Apfloat x) throws ApfloatRuntimeException
Extract fractional part.- Parameters:
x
- The operand.- Returns:
- The fractional part of
x
. - Throws:
ApfloatRuntimeException
- Since:
- 1.7.0
-
round
public Apfloat round(Apfloat x, RoundingMode roundingMode) throws ApfloatRuntimeException
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
-
w
public Apfloat w(Apfloat x) throws ApfloatRuntimeException
Lambert W function.- Parameters:
x
- The operand.- Returns:
W0(x)
.- Throws:
ApfloatRuntimeException
- Since:
- 1.8.0
-
toDegrees
public Apfloat toDegrees(Apfloat x) throws ApfloatRuntimeException
Convert radians to degrees.- Parameters:
x
- The angle in radians.- Returns:
x
converted to degrees.- Throws:
ApfloatRuntimeException
- Since:
- 1.8.0
-
toRadians
public Apfloat toRadians(Apfloat x) throws ApfloatRuntimeException
Convert degrees to radians.- Parameters:
x
- The angle in degrees.- Returns:
x
converted to radians.- Throws:
ApfloatRuntimeException
- Since:
- 1.8.0
-
atan2
public Apfloat atan2(Apfloat x, Apfloat y) throws ArithmeticException, ApfloatRuntimeException
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
public Apfloat copySign(Apfloat x, Apfloat y) throws ApfloatRuntimeException
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
public Apfloat fmod(Apfloat x, Apfloat y) throws ApfloatRuntimeException
Modulus.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
x % y
.- Throws:
ApfloatRuntimeException
-
modf
public Apfloat[] modf(Apfloat x) throws ApfloatRuntimeException
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
public Apfloat factorial(long n) throws ApfloatRuntimeException
Factorial.- Parameters:
n
- The operand.- Returns:
n!
.- Throws:
ApfloatRuntimeException
-
factorial
public Apfloat factorial(long n, int radix) throws ApfloatRuntimeException
Factorial.- Parameters:
n
- The operand.radix
- The radix of the result.- Returns:
n!
.- Throws:
ApfloatRuntimeException
-
pi
public Apfloat pi() throws ApfloatRuntimeException
π.- Returns:
π
.- Throws:
ApfloatRuntimeException
-
pi
public Apfloat pi(int radix) throws NumberFormatException, ApfloatRuntimeException
π.- Parameters:
radix
- The radix of the result.- Returns:
π
.- Throws:
NumberFormatException
- If the radix is invalid.ApfloatRuntimeException
-
logRadix
public Apfloat logRadix(int radix) throws NumberFormatException, ApfloatRuntimeException
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
public Apfloat product(Apfloat... x) throws ApfloatRuntimeException
Product.- Parameters:
x
- The operand(s).- Returns:
- The product of the operands.
- Throws:
ApfloatRuntimeException
-
sum
public Apfloat sum(Apfloat... x) throws ApfloatRuntimeException
Sum.- Parameters:
x
- The operand(s).- Returns:
- The sum of the operands.
- Throws:
ApfloatRuntimeException
-
gamma
public Apfloat gamma(Apfloat x) throws ArithmeticException, ApfloatRuntimeException
Gamma function.- Parameters:
x
- The operand(s).- Returns:
Γ(x)
.- Throws:
ArithmeticException
- Ifx
is a nonpositive integer.ApfloatRuntimeException
- Since:
- 1.9.0
-
random
public Apfloat random() throws ApfloatRuntimeException
Return a uniformly distributed random number0 ≤ x < 1
.- Returns:
- A random number.
- Throws:
ApfloatRuntimeException
- Since:
- 1.9.0
-
random
public Apfloat random(int radix) throws NumberFormatException, ApfloatRuntimeException
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
public Apfloat randomGaussian() throws ApfloatRuntimeException
Return a normally distributed random number with mean 0 and standard deviation 1.- Returns:
- A random number.
- Throws:
ApfloatRuntimeException
- Since:
- 1.9.0
-
randomGaussian
public Apfloat randomGaussian(int radix) throws NumberFormatException, ApfloatRuntimeException
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
-
max
public Apfloat max(Apfloat x, Apfloat y) throws ApfloatRuntimeException
Maximum value.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
- The maximum of
x
andy
. - Throws:
ApfloatRuntimeException
-
min
public Apfloat min(Apfloat x, Apfloat y) throws ApfloatRuntimeException
Minimum value.- Parameters:
x
- The first operand.y
- The second operand.- Returns:
- The minimum of
x
andy
. - Throws:
ApfloatRuntimeException
-
-