# Operations on complex numbers

SYNOPSIS

#include "zmatrix.h"
complex zmake(double real, double imag)
complex zconj(complex z)
complex zneg(complex z)
double zabs(complex z)
complex zadd(complex z1, complex z2)
complex zsub(complex z1, complex z2)
complex zmlt(complex z1, complex z2)
complex zinv(complex z)
complex zdiv(complex z1, complex z2)
complex zsqrt(complex z)
complex zexp(complex z)
complex zlog(complex z)

DESCRIPTION

These routines provide the basic operations on complex numbers.
Complex numbers are represented by the `complex` data structure which
is defined as

typedef struct { Real re, im; } complex;

and the real part of `complex z;` is `z.re` and its imaginary
part is `z.im`.
Let $z = x+iy$.
The routine `zmake(real,imag)` returns the complex number with real
part `real` and imaginary part `imag`.
The routine `zconj(z)` returns $\bar z = x - iy$
The routine `zneg(z)` returns $-z$.
The routine `zabs(z)` returns $|z|=\sqrt{x^2+y^2}$.
Note that it is done safely to avoid overflow if $|x|$ or $|y|$ is close to
floating point limits.
The routine `zadd(z1,z2)` returns $z_1+z_2$.
The routine `zsub(z1,z2)` returns $z_1-z_2$.
The routine `zmlt(z1,z2)` returns $z_1 z_2$.
The routine `zinv(z)` returns $1/z$.
An `E_SING` error is raised if $z=0$.
The routine `zdiv(z1,z2)` returns $z_1/z_2$.
An `E_SING` error is raised if $z_2=0$.
The routine `zsqrt(z)` returns $\sqrt{z}$.
The principle branch is used for a branch cut along the negative real axis,
so the real part of $\sqrt{z}$ as computed is not negative.
The routine `zexp(z)` returns $\exp(z)=e^{z}=e^x(\cos y+i\sin y)$.
The routine `zlog(z)` returns $\log(z)$.
The principle branch is used for a branch cut along the negative real axis,
so the imaginary part of $\log(z)$ lies between or on $\pm\pi$.
EXAMPLE

To compute $\log(z+e^w)/\sqrt{1+z^2}$:

complex w, z, result;
......
result = zdiv(zlog(zadd(z,zexp(w))),
zsqrt(zadd(ONE,zmlt(z,z))));

where `ONE` is $1+0i$; `ONE = zmake(1.0,0.0);`.
SOURCE FILE: `zfunc.c`