org.apfloat
Class FixedPrecisionApcomplexHelper

java.lang.Object
  extended by org.apfloat.FixedPrecisionApcomplexHelper
Direct Known Subclasses:
FixedPrecisionApfloatHelper

public class FixedPrecisionApcomplexHelper
extends Object

Fixed-precision mathematical functions for complex numbers.

All results of the mathematical operations are rounded to the specified precision. Also all input arguments are rounded 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 ApcomplexMath.acos(Apcomplex.ZERO).

Since:
1.5
Version:
1.5
Author:
Mikko Tommila

Constructor Summary
FixedPrecisionApcomplexHelper(long precision)
          Constructs an apcomplex fixed-precison helper with the specified precision.
 
Method Summary
 Apfloat abs(Apcomplex z)
          Absolute value.
 Apcomplex acos(Apcomplex z)
          Arc cosine.
 Apcomplex acosh(Apcomplex z)
          Hyperbolic arc cosine.
 Apcomplex add(Apcomplex z, Apcomplex w)
          Addition.
 Apcomplex agm(Apcomplex a, Apcomplex b)
          Arithmetic-geometric mean.
 Apcomplex[] allRoots(Apcomplex z, int n)
          All branches of a root.
 Apfloat arg(Apcomplex z)
          Complex angle.
 Apcomplex asin(Apcomplex z)
          Arc sine.
 Apcomplex asinh(Apcomplex z)
          Hyperbolic arc sine.
 Apcomplex atan(Apcomplex z)
          Arc tangent.
 Apcomplex atanh(Apcomplex z)
          Hyperbolic arc tangent.
 Apcomplex cbrt(Apcomplex z)
          Cube root.
 Apcomplex conj(Apcomplex z)
          Complex conjugate.
 Apcomplex cos(Apcomplex z)
          Cosine.
 Apcomplex cosh(Apcomplex z)
          Hyperbolic cosine.
 Apcomplex divide(Apcomplex z, Apcomplex w)
          Division.
 Apcomplex exp(Apcomplex z)
          Exponential function.
 Apfloat imag(Apcomplex z)
          Imaginary part.
 Apcomplex inverseRoot(Apcomplex z, long n)
          Inverse root.
 Apcomplex log(Apcomplex z)
          Natural logarithm.
 Apcomplex multiply(Apcomplex z, Apcomplex w)
          Multiplication.
 Apcomplex negate(Apcomplex z)
          Negation.
 Apfloat norm(Apcomplex z)
          Norm.
 Apcomplex pow(Apcomplex z, Apcomplex w)
          Power.
 Apcomplex pow(Apcomplex z, long n)
          Integer power.
 long precision()
          Returns the precision where the results are rounded to.
 Apcomplex product(Apcomplex... z)
          Product.
 Apfloat real(Apcomplex z)
          Real part.
 Apcomplex root(Apcomplex z, long n)
          Root.
 Apcomplex root(Apcomplex z, long n, long k)
          Root with branch.
 Apcomplex scale(Apcomplex z, long scale)
          Move the radix point.
 Apcomplex sin(Apcomplex z)
          Sine.
 Apcomplex sinh(Apcomplex z)
          Hyperbolic sine.
 Apcomplex sqrt(Apcomplex z)
          Square root.
 Apcomplex subtract(Apcomplex z, Apcomplex w)
          Subtraction.
 Apcomplex sum(Apcomplex... z)
          Sum.
 Apcomplex tan(Apcomplex z)
          Tangent.
 Apcomplex tanh(Apcomplex z)
          Hyperbolic tangent.
 Apcomplex valueOf(Apcomplex z)
          Rounds the value to the specified precision.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedPrecisionApcomplexHelper

public FixedPrecisionApcomplexHelper(long precision)
                              throws IllegalArgumentException
Constructs an apcomplex 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 Apcomplex valueOf(Apcomplex z)
                  throws ApfloatRuntimeException
Rounds the value to the specified precision.

Parameters:
z - The value to round.
Returns:
The value rounded to the specified precision.
Throws:
ApfloatRuntimeException

negate

public Apcomplex negate(Apcomplex z)
                 throws ApfloatRuntimeException
Negation.

Parameters:
z - The value to negate.
Returns:
-z.
Throws:
ApfloatRuntimeException

conj

public Apcomplex conj(Apcomplex z)
               throws ApfloatRuntimeException
Complex conjugate.

Parameters:
z - The operand.
Returns:
x - i y where z is x + i y.
Throws:
ApfloatRuntimeException

add

public Apcomplex add(Apcomplex z,
                     Apcomplex w)
              throws ApfloatRuntimeException
Addition.

Parameters:
z - The first operand.
w - The second operand.
Returns:
z + w.
Throws:
ApfloatRuntimeException

subtract

public Apcomplex subtract(Apcomplex z,
                          Apcomplex w)
                   throws ApfloatRuntimeException
Subtraction.

Parameters:
z - The first operand.
w - The second operand.
Returns:
z - w.
Throws:
ApfloatRuntimeException

multiply

public Apcomplex multiply(Apcomplex z,
                          Apcomplex w)
                   throws ApfloatRuntimeException
Multiplication.

Parameters:
z - The first operand.
w - The second operand.
Returns:
z * w.
Throws:
ApfloatRuntimeException

divide

public Apcomplex divide(Apcomplex z,
                        Apcomplex w)
                 throws ArithmeticException,
                        ApfloatRuntimeException
Division.

Parameters:
z - The first operand.
w - The second operand.
Returns:
z / w.
Throws:
ArithmeticException - If w is zero.
ApfloatRuntimeException

pow

public Apcomplex pow(Apcomplex z,
                     Apcomplex w)
              throws ArithmeticException,
                     ApfloatRuntimeException
Power.

Parameters:
z - The first operand.
w - The second operand.
Returns:
zw.
Throws:
ArithmeticException - If z and w are zero.
ApfloatRuntimeException

pow

public Apcomplex pow(Apcomplex z,
                     long n)
              throws ArithmeticException,
                     ApfloatRuntimeException
Integer power.

Parameters:
z - The first operand.
n - The first operand.
Returns:
zn.
Throws:
ArithmeticException - If z and n are zero, or z is zero and n is negative.
ApfloatRuntimeException

arg

public Apfloat arg(Apcomplex z)
            throws ArithmeticException,
                   ApfloatRuntimeException
Complex angle.

Parameters:
z - The operand.
Returns:
The angle of z on the complex plane.
Throws:
ArithmeticException - If z is zero.
ApfloatRuntimeException

imag

public Apfloat imag(Apcomplex z)
Imaginary part.

Parameters:
z - The operand.
Returns:
The imaginary part of z.

real

public Apfloat real(Apcomplex z)
Real part.

Parameters:
z - The operand.
Returns:
The real part of z.

abs

public Apfloat abs(Apcomplex z)
            throws ApfloatRuntimeException
Absolute value.

Parameters:
z - The operand.
Returns:
The absolute value of z.
Throws:
ApfloatRuntimeException

norm

public Apfloat norm(Apcomplex z)
             throws ApfloatRuntimeException
Norm.

Parameters:
z - The operand.
Returns:
x2 + y2 where z is x + i y.
Throws:
ApfloatRuntimeException

acos

public Apcomplex acos(Apcomplex z)
               throws ApfloatRuntimeException
Arc cosine.

Parameters:
z - The operand.
Returns:
The arc cosine of z.
Throws:
ApfloatRuntimeException

acosh

public Apcomplex acosh(Apcomplex z)
                throws ApfloatRuntimeException
Hyperbolic arc cosine.

Parameters:
z - The operand.
Returns:
The hyperbolic arc cosine of z.
Throws:
ApfloatRuntimeException

asin

public Apcomplex asin(Apcomplex z)
               throws ApfloatRuntimeException
Arc sine.

Parameters:
z - The operand.
Returns:
The arc sine of z.
Throws:
ApfloatRuntimeException

asinh

public Apcomplex asinh(Apcomplex z)
                throws ApfloatRuntimeException
Hyperbolic arc sine.

Parameters:
z - The operand.
Returns:
The hyperbolic arc sine of z.
Throws:
ApfloatRuntimeException

atan

public Apcomplex atan(Apcomplex z)
               throws ApfloatRuntimeException
Arc tangent.

Parameters:
z - The operand.
Returns:
The arc tangent of z.
Throws:
ArithmeticException - If z is i.
ApfloatRuntimeException

atanh

public Apcomplex atanh(Apcomplex z)
                throws ArithmeticException,
                       ApfloatRuntimeException
Hyperbolic arc tangent.

Parameters:
z - The operand.
Returns:
The hyperbolic arc tangent of z.
Throws:
ArithmeticException - If z is 1 or -1.
ApfloatRuntimeException

cbrt

public Apcomplex cbrt(Apcomplex z)
               throws ApfloatRuntimeException
Cube root.

Parameters:
z - The operand.
Returns:
The cube root of z.
Throws:
ApfloatRuntimeException

cos

public Apcomplex cos(Apcomplex z)
              throws ApfloatRuntimeException
Cosine.

Parameters:
z - The operand.
Returns:
The cosine of z.
Throws:
ApfloatRuntimeException

cosh

public Apcomplex cosh(Apcomplex z)
               throws ApfloatRuntimeException
Hyperbolic cosine.

Parameters:
z - The operand.
Returns:
The hyperbolic cosine of z.
Throws:
ApfloatRuntimeException

exp

public Apcomplex exp(Apcomplex z)
              throws ApfloatRuntimeException
Exponential function.

Parameters:
z - The operand.
Returns:
ez.
Throws:
ApfloatRuntimeException

log

public Apcomplex log(Apcomplex z)
              throws ArithmeticException,
                     ApfloatRuntimeException
Natural logarithm.

Parameters:
z - The operand.
Returns:
The natural logarithm of z.
Throws:
ArithmeticException - If z is zero.
ApfloatRuntimeException

sin

public Apcomplex sin(Apcomplex z)
              throws ApfloatRuntimeException
Sine.

Parameters:
z - The operand.
Returns:
The sine of z.
Throws:
ApfloatRuntimeException

sinh

public Apcomplex sinh(Apcomplex z)
               throws ApfloatRuntimeException
Hyperbolic sine.

Parameters:
z - The operand.
Returns:
The hyperbolic sine of z.
Throws:
ApfloatRuntimeException

sqrt

public Apcomplex sqrt(Apcomplex z)
               throws ApfloatRuntimeException
Square root.

Parameters:
z - The operand.
Returns:
The square root of z.
Throws:
ApfloatRuntimeException

tan

public Apcomplex tan(Apcomplex z)
              throws ArithmeticException,
                     ApfloatRuntimeException
Tangent.

Parameters:
z - The operand.
Returns:
The tangent of z.
Throws:
ArithmeticException - If z is π/2 + n π where n is an integer.
ApfloatRuntimeException

tanh

public Apcomplex tanh(Apcomplex z)
               throws ArithmeticException,
                      ApfloatRuntimeException
Hyperbolic tangent.

Parameters:
z - The operand.
Returns:
The hyperbolic tangent of z.
Throws:
ArithmeticException - If z is i (π/2 + n π) where n is an integer.
ApfloatRuntimeException

agm

public Apcomplex agm(Apcomplex a,
                     Apcomplex 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 Apcomplex inverseRoot(Apcomplex z,
                             long n)
                      throws ArithmeticException,
                             ApfloatRuntimeException
Inverse root.

Parameters:
z - The operand.
n - Which inverse root to take.
Returns:
z-1/n.
Throws:
ArithmeticException - If z or n is zero.
ApfloatRuntimeException

root

public Apcomplex root(Apcomplex z,
                      long n)
               throws ArithmeticException,
                      ApfloatRuntimeException
Root.

Parameters:
z - The operand.
n - Which root to take.
Returns:
z1/n.
Throws:
ArithmeticException - If n is zero, or z is zero and n is negative.
ApfloatRuntimeException

root

public Apcomplex root(Apcomplex z,
                      long n,
                      long k)
               throws ArithmeticException,
                      ApfloatRuntimeException
Root with branch.

Parameters:
z - The operand.
n - Which root to take.
k - Which branch to take.
Returns:
z1/nei2πsk/n where s is the signum of the imaginary part of z.
Throws:
ArithmeticException - If n is zero, or z is zero and n is negative.
ApfloatRuntimeException

allRoots

public Apcomplex[] allRoots(Apcomplex z,
                            int n)
                     throws ArithmeticException,
                            ApfloatRuntimeException
All branches of a root.

Parameters:
z - The operand.
n - Which root to take.
Returns:
z1/n.
Throws:
ArithmeticException - If n is zero, or z is zero and n is negative.
ApfloatRuntimeException

scale

public Apcomplex scale(Apcomplex z,
                       long scale)
                throws ApfloatRuntimeException
Move the radix point.

Parameters:
z - The operand.
scale - The amount to move the radix point.
Returns:
z * z.radix()scale.
Throws:
ApfloatRuntimeException

product

public Apcomplex product(Apcomplex... z)
                  throws ApfloatRuntimeException
Product.

Parameters:
z - The operand(s).
Returns:
The product of the operands.
Throws:
ApfloatRuntimeException

sum

public Apcomplex sum(Apcomplex... z)
              throws ApfloatRuntimeException
Sum.

Parameters:
z - The operand(s).
Returns:
The sum of the operands.
Throws:
ApfloatRuntimeException

precision

public long precision()
Returns the precision where the results are rounded to.

Returns:
The precision of the results.