bigcomplex multiple precision complex floating point arithmetic
bigcomplex is a class for doing multiprecision complex floating point arithmetic. It supports for example arithmetic operations, comparisons and basic triginometric functions.
A bigcomplex is a pair of two bigfloats
, where re is called the real part and im the
imaginary part. This pair represents the complex number
, where i is the imaginary unit. Before declaring a
bigcomplex
it is possible to set the decimal precision of the
bigfloats
to p by bigcomplex::precision(p)
or by bigfloat::precision(p) . Both calls have the same effect to set the bigfloat precision to p (compare bigfloat ).
If the precision has not been set, a default precision of t = 5 bigint base digits is used.
Constructors/Destructor
bigcomplex()
bigcomplex(const bigfloat &)
bigcomplex(const bigcomplex &)
bigcomplex(const bigfloat & re,
const bigfloat & im)
bigcomplex()
Initialization
static void precision(long p)
sets the global decimal
precision of the bigfloats
re, im to p
decimal places
(compare bigfloat
). Note that the bigfloat
precision
globally is set to p by this call. Whenever necessary, internal
computations are done with a higher precision.
static void mode(int m)
sets the rounding mode for the normalization routine according to the IEEE standard (see [22]). The following modes are available:
MP_TRUNC : round to zero.
MP_RND : round to nearest. If there are two possibilities to do this, round to the even number of them.
MP_RND_UP
round to
.
MP_RND_DOWN
round to
.
Type Checking
Before assigning a bigcomplex to a bigfloat it is often useful to check whether the assignment can be done without error, i.e., whether the imaginary part im is zero.
int is_bigfloat(const bigcomplex &)
returns 1
, if the imaginary part is zero, 0
otherwise.
int is_double(const bigcomplex &)
returns 1
, if the imaginary part is zero and the real part is not to
large to be stored in a double variable, 0
otherwise.
Assignments
Let x be of type bigcomplex .
The operator = is overloaded. For efficiency reasons the following functions are implemented:
void x.assign_zero()
x = 0.
void x.assign_one()
x = 1.
void x.assign(const bigfloat & y)
x = y.
void x.assign(const bigfloat &y, const bigfloat & z)
.
void x.assign(const bigcomplex & y)
x = y.
Access Functions
Let x be of type bigcomplex .
bigfloat x.real() const
returns the real part of x.
bigfloat real(const bigcomplex & x)
returns the real part of x.
bigfloat x.imag() const
returns the imaginary part of x.
bigfloat imag(const bigcomplex & x)
returns the imaginary part of x.
Arithmetical Operations
The following operators are overloaded and can be used in exactly the same way as in C:
(unary) -
(binary) +, -, *, /
(binary with assignment) +=, -=, *=, /=
void add(bigcomplex & x, const bigcomplex & y, const bigcomplex & z)
x = y + z.
void add(bigcomplex & x, const bigcomplex & y, const bigfloat & z)
x = y + z.
void add(bigcomplex & x, const bigfloat & y, const bigcomplex & z)
x = y + z.
void subtract(bigcomplex & x, const bigcomplex & y, const bigcomplex & z)
x = y - z.
void subtract(bigcomplex & x, const bigcomplex & y, const bigfloat & z)
x = y - z.
void subtract(bigcomplex & x, const bigfloat & y, const bigcomplex & z)
x = y - z.
void multiply(bigcomplex & x, const bigcomplex & y, const bigcomplex & z)
.
void multiply(bigcomplex & x, const bigcomplex & y, const bigfloat & z)
.
void multiply(bigcomplex & x, const bigfloat & y, const bigcomplex & z)
.
void divide(bigcomplex & x, const bigcomplex & y, const bigcomplex & z)
, if
.
Otherwise the error_handler
will be invoked.
void divide(bigcomplex & x, const bigcomplex & y, const bigfloat & z)
, if
.
Otherwise the error_handler
will be invoked.
void divide(bigcomplex & x, const bigfloat & y, const bigcomplex & z)
, if
.
Otherwise the error_handler
will be invoked.
void negate(bigcomplex & x, const bigcomplex & y)
x = -y.
void x.negate()
x = -x.
void x.invert()
, if
. Otherwise the error_handler
will be invoked.
void invert(bigcomplex & x, const bigcomplex & y)
, if
. Otherwise the error_handler
will be invoked.
bigcomplex inverse(const bigcomplex & x)
returns , if
.
Otherwise the error_handler
will be invoked.
void square(bigcomplex & x, const bigcomplex & y)
.
bigcomplex square(const bigcomplex & x)
returns .
void sqrt(bigcomplex & x, const bigcomplex & x)
.
bigcomplex sqrt(const bigcomplex & x)
returns .
void power(bigcomplex & x, const bigcomplex & y, const bigcomplex & z)
sets .
void power(bigcomplex & x, const bigcomplex & y, const bigfloat & z)
sets .
void power(bigcomplex & x, const bigcomplex & y, long i)
sets .
bigcomplex power(const bigcomplex & y, const bigcomplex & z)
returns .
bigcomplex power(const bigcomplex & y, const bigfloat & z)
returns .
bigcomplex power(const bigcomplex & y,
long i)
returns .
Comparisons
bigcomplex supports the binary operators == and != . Furthermore there exists the following function:
int x.is_zero() const
returns 1
, if x = 0, 0
otherwise.
Basic Functions
void conj(bigcomplex & x, const bigcomplex & y)
returns x as the complex conjugate of y.
void exp(bigcomplex & x, const bigcomplex & y)
.
void log(bigcomplex & x, const bigcomplex & y)
(natural logarithm to base
).
void polar(bigcomplex & x, const bigfloat & r, const bigfloat & t)
.
bigcomplex conj(const bigcomplex & x)
returns the complex conjugate of x.
bigcomplex exp(const bigcomplex & x)
returns e.
bigcomplex log(const bigcomplex & x)
returns .
bigfloat abs(const bigcomplex & x)
returns .
bigcomplex polar(const bigfloat & r, const bigfloat & t)
returns the complex number .
bigfloat hypot(const bigcomplex & x)
returns .
bigfloat arg(const bigcomplex & x)
returns .
bigfloat norm(const bigcomplex & x)
returns the norm of x.
void swap(bigcomplex & x, bigcomplex & y)
exchanges the values of x and y.
(Inverse) Trigonometric Functions
void sin(bigcomplex & x, const bigcomplex & y)
.
void cos(bigcomplex & x, const bigcomplex & y)
.
bigcomplex sin(const bigcomplex & x)
returns .
bigcomplex cos(const bigcomplex & x)
returns .
(Inverse) Hyperbolic Trigonometric Functions
void sinh(bigcomplex & x, const bigcomplex & y)
.
void cosh(bigcomplex & x, const bigcomplex & x)
.
bigcomplex sinh(const bigcomplex & x)
returns .
bigcomplex cosh(const bigcomplex & x)
returns .
Input/Output
istream operator >> and ostream operator << are overloaded and can be used in the same way as in C. If the imaginary part of the bigcomplex is zero then input and output of a bigcomplex may be in one of the following formats:
where re is a bigfloat in the appropriate format described in the bigfloat class description. If the imaginary part of the bigfloat is not zero then input and output have the format
where re and im are bigfloat s in the appropriate format described in the bigfloat class description.
Note that you have to manage by yourself that successive bigcomplex numbers have to be separated by blanks.
bigfloat
The structure of bigcomplex is strongly based on AT&T's and GNU's complex class. bigcomplex is not yet complete. Further methods will be incorporated in the next release.
See LiDIA/src/simple_classes/bigcomplex_appl.c
Ingrid Biehl, Thomas Papanikolaou
Copyright 1995 by the
LiDIA -Group, Universität des Saarlandes