|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apfloat.ApfloatMath
public class ApfloatMath
Various mathematical functions for arbitrary precision floating-point numbers.
Due to different types of round-off errors that can occur in the implementation, no guarantees about e.g. monotonicity are given for any of the methods.
Method Summary | |
---|---|
static Apfloat |
abs(Apfloat x)
Absolute value. |
static Apfloat |
acos(Apfloat x)
Inverse cosine. |
static Apfloat |
acosh(Apfloat x)
Inverse hyperbolic cosine. |
static Apfloat |
agm(Apfloat a,
Apfloat b)
Arithmetic-geometric mean. |
static Apfloat |
asin(Apfloat x)
Inverse sine. |
static Apfloat |
asinh(Apfloat x)
Inverse hyperbolic sine. |
static Apfloat |
atan(Apfloat x)
Inverse tangent. |
static Apfloat |
atan2(Apfloat x,
Apfloat y)
Converts cartesian coordinates to polar coordinates. |
static Apfloat |
atanh(Apfloat x)
Inverse hyperbolic tangent. |
static Apfloat |
cbrt(Apfloat x)
Cube root. |
static Apint |
ceil(Apfloat x)
Ceiling function. |
static Apfloat |
copySign(Apfloat x,
Apfloat y)
Copy sign from one argument to another. |
static Apfloat |
cos(Apfloat x)
Cosine. |
static Apfloat |
cosh(Apfloat x)
Hyperbolic cosine. |
static Apfloat |
exp(Apfloat x)
Exponent function. |
static Apint |
floor(Apfloat x)
Floor function. |
static Apfloat |
fmod(Apfloat x,
Apfloat y)
Returns x modulo y. |
static Apfloat |
inverseRoot(Apfloat x,
long n)
Inverse positive integer root. |
static Apfloat |
inverseRoot(Apfloat x,
long n,
long targetPrecision)
Inverse positive integer root. |
static Apfloat |
inverseRoot(Apfloat x,
long n,
long targetPrecision,
Apfloat initialGuess)
Inverse positive integer root. |
static Apfloat |
inverseRoot(Apfloat x,
long n,
long targetPrecision,
Apfloat initialGuess,
long initialPrecision)
Inverse positive integer root. |
static Apfloat |
log(Apfloat x)
Natural logarithm. |
static Apfloat |
logRadix(long precision,
int radix)
Gets or calculates logarithm of a radix to required precision. |
static Apfloat[] |
modf(Apfloat x)
Split to integer and fractional parts. |
static Apfloat |
multiplyAdd(Apfloat a,
Apfloat b,
Apfloat c,
Apfloat d)
Fused multiply-add. |
static Apfloat |
multiplySubtract(Apfloat a,
Apfloat b,
Apfloat c,
Apfloat d)
Fused multiply-subtract. |
static Apfloat |
negate(Apfloat x)
Deprecated. Use Apfloat.negate() . |
static Apfloat |
pi(long precision)
Calculates π. |
static Apfloat |
pi(long precision,
int radix)
Calculates π. |
static Apfloat |
pow(Apfloat x,
Apfloat y)
Arbitrary power. |
static Apfloat |
pow(Apfloat x,
long n)
Integer power. |
static Apfloat |
product(Apfloat... x)
Product of numbers. |
static Apfloat |
root(Apfloat x,
long n)
Positive integer root. |
static Apfloat |
scale(Apfloat x,
long scale)
Multiply by a power of the radix. |
static Apfloat |
sin(Apfloat x)
Sine. |
static Apfloat |
sinh(Apfloat x)
Hyperbolic sine. |
static Apfloat |
sqrt(Apfloat x)
Square root. |
static Apfloat |
sum(Apfloat... x)
Sum of numbers. |
static Apfloat |
tan(Apfloat x)
Tangent. |
static Apfloat |
tanh(Apfloat x)
Hyperbolic tangent. |
static Apint |
truncate(Apfloat x)
Truncates fractional part. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Apfloat pow(Apfloat x, long n) throws ArithmeticException, ApfloatRuntimeException
x
- Base of the power operator.n
- Exponent of the power operator.
x
to the n
:th power, that is xn
.
ArithmeticException
- If both x
and n
are zero.
ApfloatRuntimeException
public static Apfloat sqrt(Apfloat x) throws ArithmeticException, ApfloatRuntimeException
x
- The argument.
x
.
ArithmeticException
- If x
is negative.
ApfloatRuntimeException
public static Apfloat cbrt(Apfloat x) throws ApfloatRuntimeException
x
- The argument.
x
.
ApfloatRuntimeException
public static Apfloat root(Apfloat x, long n) throws ArithmeticException, ApfloatRuntimeException
x
- The argument.n
- Which root to take.
n
:th root of x
, that is x1/n
.
ArithmeticException
- If n
and x
are zero, or x
is negative and n
is even.
ApfloatRuntimeException
public static Apfloat inverseRoot(Apfloat x, long n) throws ArithmeticException, ApfloatRuntimeException
x
- The argument.n
- Which inverse root to take.
n
:th root of x
, that is x-1/n
.
ArithmeticException
- If x
or n
is zero, or x
is negative and n
is even.
ApfloatRuntimeException
public static Apfloat inverseRoot(Apfloat x, long n, long targetPrecision) throws IllegalArgumentException, ArithmeticException, ApfloatRuntimeException
x
- The argument.n
- Which inverse root to take.targetPrecision
- Precision of the desired result.
n
:th root of x
, that is x-1/n
.
IllegalArgumentException
- If targetPrecision <= 0
.
ArithmeticException
- If x
or n
is zero, or x
is negative and n
is even.
ApfloatRuntimeException
public static Apfloat inverseRoot(Apfloat x, long n, long targetPrecision, Apfloat initialGuess) throws IllegalArgumentException, ArithmeticException, ApfloatRuntimeException
x
- The argument.n
- Which inverse root to take.targetPrecision
- Precision of the desired result.initialGuess
- Initial guess for the result value, or null
if none is available.
n
:th root of x
, that is x-1/n
.
IllegalArgumentException
- If targetPrecision <= 0
.
ArithmeticException
- If x
or n
is zero, or x
is negative and n
is even.
ApfloatRuntimeException
public static Apfloat inverseRoot(Apfloat x, long n, long targetPrecision, Apfloat initialGuess, long initialPrecision) throws IllegalArgumentException, ArithmeticException, ApfloatRuntimeException
This method is the basis for most of apfloat's non-elementary operations.
It is used e.g. in Apfloat.divide(Apfloat)
, sqrt(Apfloat)
and root(Apfloat,long)
.
x
- The argument.n
- Which inverse root to take.targetPrecision
- Precision of the desired result.initialGuess
- Initial guess for the result value, or null
if none is available.initialPrecision
- Precision of the initial guess, if available.
n
:th root of x
, that is x-1/n
.
IllegalArgumentException
- If targetPrecision <= 0
or initialPrecision <= 0
.
ArithmeticException
- If x
or n
is zero, or x
is negative and n
is even.
ApfloatRuntimeException
public static Apint floor(Apfloat x) throws ApfloatRuntimeException
x
- The argument.
x
rounded towards negative infinity.
ApfloatRuntimeException
public static Apint ceil(Apfloat x) throws ApfloatRuntimeException
x
- The argument.
x
rounded towards positive infinity.
ApfloatRuntimeException
public static Apint truncate(Apfloat x) throws ApfloatRuntimeException
x
- The argument.
x
rounded towards zero.
ApfloatRuntimeException
@Deprecated public static Apfloat negate(Apfloat x) throws ApfloatRuntimeException
Apfloat.negate()
.
-x
.
x
- The argument.
-x
.
ApfloatRuntimeException
public static Apfloat abs(Apfloat x) throws ApfloatRuntimeException
x
- The argument.
x
.
ApfloatRuntimeException
public static Apfloat copySign(Apfloat x, Apfloat y) throws ApfloatRuntimeException
x
- The value whose sign is to be adjusted.y
- The value whose sign is to be used.
x
with its sign changed to match the sign of y
.
ApfloatRuntimeException
public static Apfloat scale(Apfloat x, long scale) throws ApfloatRuntimeException
x
- The argument.scale
- The scaling factor.
x * x.radix()scale
.
ApfloatRuntimeException
public static Apfloat[] modf(Apfloat x) throws ApfloatRuntimeException
i = floor(x)
.
For the fractional part f
the following is always true:
0 <= f < 1
x
- The argument.
[i, f]
, the first being the integer part and the last being the fractional part.
ApfloatRuntimeException
public static Apfloat fmod(Apfloat x, Apfloat y) throws ApfloatRuntimeException
This function calculates the remainder f
of x / y
such that x = i * y + f
, where i
is an integer,
f
has the same sign as x
,
and the absolute value of f
is less than the absolute value of y
.
If y
is zero, then zero is returned.
x
- The dividend.y
- The divisor.
ApfloatRuntimeException
public static Apfloat multiplyAdd(Apfloat a, Apfloat b, Apfloat c, Apfloat d) throws ApfloatRuntimeException
a * b + c * d
so that the precision used in the multiplications is only
what is needed for the end result. Performance can this way
be better than by calculating a.multiply(b).add(c.multiply(d))
.
a
- First argument.b
- Second argument.c
- Third argument.d
- Fourth argument.
a * b + c * d
.
ApfloatRuntimeException
public static Apfloat multiplySubtract(Apfloat a, Apfloat b, Apfloat c, Apfloat d) throws ApfloatRuntimeException
a * b - c * d
so that the precision used in the multiplications is only
what is needed for the end result. Performance can this way
be better than by calculating a.multiply(b).subtract(c.multiply(d))
.
a
- First argument.b
- Second argument.c
- Third argument.d
- Fourth argument.
a * b - c * d
.
ApfloatRuntimeException
public static Apfloat agm(Apfloat a, Apfloat b) throws ApfloatRuntimeException
a
- First argument.b
- Second argument.
ApfloatRuntimeException
public static Apfloat pi(long precision) throws IllegalArgumentException, NumberFormatException, ApfloatRuntimeException
precision
- Number of digits of π to calculate.
precision
digits, in the default radix.
NumberFormatException
- If the default radix is not valid.
IllegalArgumentException
- In case the precision is invalid.
ApfloatRuntimeException
public static Apfloat pi(long precision, int radix) throws IllegalArgumentException, NumberFormatException, ApfloatRuntimeException
precision
- Number of digits of π to calculate.radix
- The radix in which the number should be presented.
precision
digits, in base radix
.
NumberFormatException
- If the radix is not valid.
IllegalArgumentException
- In case the precision is invalid.
ApfloatRuntimeException
public static Apfloat log(Apfloat x) throws ArithmeticException, ApfloatRuntimeException
The logarithm is calculated using the arithmetic-geometric mean. See the Borweins' book for the formula.
x
- The argument.
x
.
ArithmeticException
- If x <= 0
.
ApfloatRuntimeException
public static Apfloat logRadix(long precision, int radix) throws ApfloatRuntimeException
precision
- The needed precision.radix
- The radix.
radix
to the specified precision.
NumberFormatException
- If the radix is invalid.
ApfloatRuntimeException
public static Apfloat exp(Apfloat x) throws ApfloatRuntimeException
x
- The argument.
ex
.
ApfloatRuntimeException
public static Apfloat pow(Apfloat x, Apfloat y) throws ArithmeticException, ApfloatRuntimeException
log()
and exp()
.
This method doesn't calculate the result properly if x
is negative
and y
is an integer. For that you should use pow(Apfloat,long)
.
x
- The base.y
- The exponent.
xy
.
ArithmeticException
- If both x
and y
are zero, or x
is negative.
ApfloatRuntimeException
public static Apfloat acosh(Apfloat x) throws ArithmeticException, ApfloatRuntimeException
log()
.
x
- The argument.
x
.
ArithmeticException
- If x < 1
.
ApfloatRuntimeException
public static Apfloat asinh(Apfloat x) throws ApfloatRuntimeException
log()
.
x
- The argument.
x
.
ApfloatRuntimeException
public static Apfloat atanh(Apfloat x) throws ArithmeticException, ApfloatRuntimeException
log()
.
x
- The argument.
x
.
ArithmeticException
- If abs(x) >= 1
.
ApfloatRuntimeException
public static Apfloat cosh(Apfloat x) throws ApfloatRuntimeException
exp()
.
x
- The argument.
x
.
ApfloatRuntimeException
public static Apfloat sinh(Apfloat x) throws ApfloatRuntimeException
exp()
.
x
- The argument.
x
.
ApfloatRuntimeException
public static Apfloat tanh(Apfloat x) throws ApfloatRuntimeException
exp()
.
x
- The argument.
x
.
ApfloatRuntimeException
public static Apfloat acos(Apfloat x) throws ArithmeticException, ApfloatRuntimeException
x
- The argument.
x
.
ArithmeticException
- If abs(x) > 1
.
ApfloatRuntimeException
public static Apfloat asin(Apfloat x) throws ArithmeticException, ApfloatRuntimeException
x
- The argument.
x
.
ArithmeticException
- If abs(x) > 1
.
ApfloatRuntimeException
public static Apfloat atan(Apfloat x) throws ApfloatRuntimeException
x
- The argument.
x
.
ApfloatRuntimeException
public static Apfloat atan2(Apfloat x, Apfloat y) throws ArithmeticException, ApfloatRuntimeException
Computes the phase angle by computing an arc tangent of x/y
in the range of -π < angle <= π.
x
- The argument.y
- The argument.
(y, x)
in the plane.
ArithmeticException
- If x
and y
are both zero.
ApfloatRuntimeException
public static Apfloat cos(Apfloat x) throws ApfloatRuntimeException
x
- The argument.
x
.
ApfloatRuntimeException
public static Apfloat sin(Apfloat x) throws ApfloatRuntimeException
x
- The argument.
x
.
ApfloatRuntimeException
public static Apfloat tan(Apfloat x) throws ApfloatRuntimeException
x
- The argument.
x
.
ArithmeticException
- If x
is π/2 + n π where n is an integer.
ApfloatRuntimeException
public static Apfloat product(Apfloat... x) throws IllegalArgumentException, ApfloatRuntimeException
x
- The argument(s).
IllegalArgumentException
- If there are no arguments.
ApfloatRuntimeException
public static Apfloat sum(Apfloat... x) throws IllegalArgumentException, ApfloatRuntimeException
x
- The argument(s).
IllegalArgumentException
- If there are no arguments.
ApfloatRuntimeException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |