The functions described in this chapter provide support for complex
numbers. The algorithms take care to avoid unnecessary intermediate
underflows and overflows, allowing the functions to be evaluated over
as much of the complex plane as possible.
For multiple-valued functions the branch cuts have been chosen to follow
the conventions of Abramowitz and Stegun in the Handbook of
Mathematical Functions. The functions return principal values which are
the same as those in GNU Calc, which in turn are the same as those in
Common Lisp, The Language (Second Edition) (n.b. The second
edition uses different definitions from the first edition) and the
HP-28/48 series of calculators.
The complex types are defined in the header file `gsl_complex.h',
while the corresponding complex functions and arithmetic operations are
defined in `gsl_complex_math.h'.
Complex numbers are represented using the type gsl_complex. The
internal representation of this type may vary across platforms and
should not be accessed directly. The functions and macros described
below allow complex numbers to be manipulated in a portable way.
For reference, the default form of the gsl_complex type is
given by the following struct,
typedef struct
{
double dat[2];
} gsl_complex;
The real and imaginary part are stored in contiguous elements of a two
element array. This eliminates any padding between the real and
imaginary parts, dat[0] and dat[1], allowing the struct to
be mapped correctly onto packed complex arrays.
This function returns the natural logarithm of the magnitude of the
complex number z, \log|z|. It allows an accurate
evaluation of \log|z| when |z| is close to one. The direct
evaluation of log(gsl_complex_abs(z)) would lead to a loss of
precision in this case.
This function returns the square root of the complex number z,
\sqrt z. The branch cut is the negative real axis. The result
always lies in the right half of the complex plane.
This function returns the complex square root of the real number
x, where x may be negative.
Function: gsl_complex gsl_complex_pow(gsl_complex z, gsl_complex a)
The function returns the complex number z raised to the complex
power a, z^a. This is computed as \exp(\log(z)*a)
using complex logarithms and complex exponentials.
This function returns the complex arcsine of the real number z,
\arcsin(z). For z between -1 and 1, the
function returns a real value in the range (-\pi,\pi]. For
z less than -1 the result has a real part of -\pi/2
and a positive imaginary part. For z greater than 1 the
result has a real part of \pi/2 and a negative imaginary part.
This function returns the complex arccosine of the complex number z,
\arccos(z). The branch cuts are on the real axis, less than -1
and greater than 1.
This function returns the complex arccosine of the real number z,
\arccos(z). For z between -1 and 1, the
function returns a real value in the range [0,\pi]. For z
less than -1 the result has a real part of \pi/2 and a
negative imaginary part. For z greater than 1 the result
is purely imaginary and positive.
This function returns the complex hyperbolic arcsine of the
complex number z, \arcsinh(z). The branch cuts are on the
imaginary axis, below -i and above i.
This function returns the complex hyperbolic arctangent of the complex
number z, \arctanh(z). The branch cuts are on the real
axis, less than -1 and greater than 1.
The implementations of the elementary and trigonometric functions are
based on the following papers,
T. E. Hull, Thomas F. Fairgrieve, Ping Tak Peter Tang,
"Implementing Complex Elementary Functions Using Exception
Handling", ACM Transactions on Mathematical Software, Volume 20
(1994), pp 215-244, Corrigenda, p553
T. E. Hull, Thomas F. Fairgrieve, Ping Tak Peter Tang,
"Implementing the complex arcsin and arccosine functions using exception
handling", ACM Transactions on Mathematical Software, Volume 23
(1997) pp 299-335
The general formulas and details of branch cuts can be found in the
following books,
Abramowitz and Stegun, Handbook of Mathematical Functions,
"Circular Functions in Terms of Real and Imaginary Parts", Formulas
4.3.55--58,
"Inverse Circular Functions in Terms of Real and Imaginary Parts",
Formulas 4.4.37--39,
"Hyperbolic Functions in Terms of Real and Imaginary Parts",
Formulas 4.5.49--52,
"Inverse Hyperbolic Functions -- relation to Inverse Circular Functions",
Formulas 4.6.14--19.
Dave Gillespie, Calc Manual, Free Software Foundation, ISBN
1-882114-18-3