org.apfloat

Class 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 with `ApfloatMath.acos(Apfloat.ZERO)`.

Since:
1.5
Version:
1.8.0
Author:
Mikko Tommila
• Constructor Summary

Constructors
Constructor and Description
`FixedPrecisionApfloatHelper(long precision)`
Constructs an apfloat fixed-precison helper with the specified precision.
• Method Summary

All Methods
Modifier and Type Method and 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)```
`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` ```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` ```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)```
`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, Apfloat y)```
Power.
`Apfloat` ```pow(Apfloat x, long n)```
Integer power.
`Apfloat` `product(Apfloat... x)`
Product.
`Apfloat` ```root(Apfloat x, long n)```
Root.
`Apfloat` ```round(Apfloat x, RoundingMode roundingMode)```
Round with specified rounding mode.
`Apfloat` ```scale(Apfloat x, long scale)```
`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)`
`Apfloat` `toRadians(Apfloat x)`
`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, 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`
• Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• 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`

```public Apfloat add(Apfloat x,
Apfloat y)
throws ApfloatRuntimeException```
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` - If `y` 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` - If `x` and `y` are zero, or `x` 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` - If `x` and `n` are zero, or `x` is zero and `n` 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 of `x` 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 the `x` 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 of `x` 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 of `x` 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` - If `x` 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 of `x`.
Throws:
`ArithmeticException` - If `x` or `b` 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` - If `x` is negative.
`ApfloatRuntimeException`
• tan

```public Apfloat tan(Apfloat x)
throws ArithmeticException,
ApfloatRuntimeException```
Tangent.
Parameters:
`x` - The operand.
Returns:
The tangent of `x`.
Throws:
`ArithmeticException` - If `x` 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` and `b`.
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` - If `x` or `n` is zero, or `x` is negative and `n` 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` - If `n` is zero, or `x` is negative and `n` is even.
`ApfloatRuntimeException`
• scale

```public Apfloat scale(Apfloat x,
long scale)
throws ApfloatRuntimeException```
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```
Parameters:
`x` - The angle in radians.
Returns:
`x` converted to degrees.
Throws:
`ApfloatRuntimeException`
Since:
1.8.0

```public Apfloat toRadians(Apfloat x)
throws ApfloatRuntimeException```
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` - If `x` and `y` 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 of `y`.
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]` where `i` is `floor(x)` and `f` is `x - 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,
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`

```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`

```public Apfloat multiplyAdd(Apfloat a,
Apfloat b,
Apfloat c,
Apfloat d)
throws ApfloatRuntimeException```
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`