complex numbers
The complex types, functions and arithmetic operations are defined in the header file cml/complex.h
.
single: representations of complex numbers single: polar form of complex numbers single: cml_complex_t
Complex numbers are represented using the type cml_complex_t
. 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 cml_complex_t
type is given by the following struct:
typedef struct
{
union
{
double p[2];
double parts[2];
struct
{
double re;
double im;
};
struct
{
double real;
double imaginary;
};
};
} cml_complex_t;
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, parts[0]
and parts[1]
, allowing the struct to be mapped correctly onto packed complex arrays.
cml_complex_t complex (double x, double y)
This function uses the rectangular Cartesian components (x, y) to return the complex number z = x + yi. An inline version of this function is used when HAVE_INLINE
is defined.
cml_complex_t cml_complex_polar (double r, double theta)
This function returns the complex number z = rexp (iθ) = r(cos (θ) + isin (θ)) from the polar representation (r
, theta
).
creal (z) cimag (z)
These macros return the real and imaginary parts of the complex number z
.
argument of complex number
double cml_complex_arg (cml_complex_t z)
This function returns the argument of the complex number z
, arg (z), where − π < arg (z) < = π.
magnitude of complex number
double cml_complex_abs (cml_complex_t z)
This function returns the magnitude of the complex number z
, |z|.
double cml_complex_abs2 (cml_complex_t z)
This function returns the squared magnitude of the complex number z
, |z|2.
double cml_complex_logabs (cml_complex_t z)
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(cml_complex_abs(z))
would lead to a loss of precision in this case.
complex arithmetic
cml_complex_t cml_complex_add (cml_complex_t a, cml_complex_t b)
This function returns the sum of the complex numbers a
and b
, z = a + b.
cml_complex_t cml_complex_sub (cml_complex_t a, cml_complex_t b)
This function returns the difference of the complex numbers a
and b
, z = a − b.
cml_complex_t cml_complex_mul (cml_complex_t a, cml_complex_t b)
This function returns the product of the complex numbers a
and b
, z = ab.
cml_complex_t cml_complex_div (cml_complex_t a, cml_complex_t b)
This function returns the quotient of the complex numbers a
and b
, z = a/b.
cml_complex_t cml_complex_add_real (cml_complex_t a, double x)
This function returns the sum of the complex number a
and the real number x
, z = a + x.
cml_complex_t cml_complex_sub_real (cml_complex_t a, double x)
This function returns the difference of the complex number a
and the real number x
, z = a − x.
cml_complex_t cml_complex_mul_real (cml_complex_t a, double x)
This function returns the product of the complex number a
and the real number x
, z = ax.
cml_complex_t cml_complex_div_real (cml_complex_t a, double x)
This function returns the quotient of the complex number a
and the real number x
, z = a/x.
cml_complex_t cml_complex_add_imag (cml_complex_t a, double y)
This function returns the sum of the complex number a
and the imaginary number iy, z = a + iy.
cml_complex_t cml_complex_sub_imag (cml_complex_t a, double y)
This function returns the difference of the complex number a
and the imaginary number iy, z = a − iy.
cml_complex_t cml_complex_mul_imag (cml_complex_t a, double y)
This function returns the product of the complex number a
and the imaginary number iy, z = a * (iy).
cml_complex_t cml_complex_div_imag (cml_complex_t a, double y)
This function returns the quotient of the complex number a
and the imaginary number iy, z = a/(iy).
conjugate of complex number
cml_complex_t cml_complex_conj (cml_complex_t z)
This function returns the complex conjugate of the complex number z
, z* = x − yi.
cml_complex_t cml_complex_inverse (cml_complex_t z)
This function returns the inverse, or reciprocal, of the complex number z
, 1/z = (x − yi)/(x2 + y2).
cml_complex_t cml_complex_negative (cml_complex_t z)
This function returns the negative of the complex number z
, − z = ( − x) + ( − y)i.
square root of complex number
cml_complex_t cml_complex_sqrt (cml_complex_t z)
This function returns the square root of the complex number z
,
cml_complex_t cml_complex_sqrt_real (double x)
This function returns the complex square root of the real number x
, where x
may be negative.
single: power of complex number single: exponentiation of complex number
cml_complex_t cml_complex_pow (cml_complex_t z, cml_complex_t a)
The function returns the complex number z
raised to the complex power a
, za. This is computed as exp (log (z) * a) using complex logarithms and complex exponentials.
cml_complex_t cml_complex_pow_real (cml_complex_t z, double x)
This function returns the complex number z
raised to the real power x
, zx.
cml_complex_t cml_complex_exp (cml_complex_t z)
This function returns the complex exponential of the complex number z
, exp (z).
logarithm of complex number
cml_complex_t cml_complex_log (cml_complex_t z)
This function returns the complex natural logarithm (base e) of the complex number z
, log (z). The branch cut is the negative real axis.
cml_complex_t cml_complex_log10 (cml_complex_t z)
This function returns the complex base-10 logarithm of the complex number z
, log10(z).
cml_complex_t cml_complex_log_b (cml_complex_t z, cml_complex_t b)
This function returns the complex base-b
logarithm of the complex number z
, logb(z). This quantity is computed as the ratio log (z)/log (b).
trigonometric functions of complex numbers
single: sin, of complex number
cml_complex_t cml_complex_sin (cml_complex_t z)
This function returns the complex sine of the complex number z
, sin (z) = (exp (iz) − exp ( − iz))/(2i).
cosine of complex number
cml_complex_t cml_complex_cos (cml_complex_t z)
This function returns the complex cosine of the complex number z
, cos (z) = (exp (iz) + exp ( − iz))/2.
tangent of complex number
cml_complex_t cml_complex_tan (cml_complex_t z)
This function returns the complex tangent of the complex number z
, tan (z) = sin (z)/cos (z).
cml_complex_t cml_complex_sec (cml_complex_t z)
This function returns the complex secant of the complex number z
, sec (z) = 1/cos (z).
cml_complex_t cml_complex_csc (cml_complex_t z)
This function returns the complex cosecant of the complex number z
, csc (z) = 1/sin (z).
cml_complex_t cml_complex_cot (cml_complex_t z)
This function returns the complex cotangent of the complex number z
, cot (z) = 1/tan (z).
inverse complex trigonometric functions
cml_complex_t cml_complex_asin (cml_complex_t z)
This function returns the complex arcsine of the complex number z
, arcsin (z). The branch cuts are on the real axis, less than − 1 and greater than 1.
cml_complex_t cml_complex_asin_real (double z)
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 [ − π/2, π/2]. For z less than − 1 the result has a real part of − π/2 and a positive imaginary part. For z greater than 1 the result has a real part of π/2 and a negative imaginary part.
cml_complex_t cml_complex_acos (cml_complex_t z)
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.
cml_complex_t cml_complex_acos_real (double z)
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, π]. For z less than − 1 the result has a real part of π and a negative imaginary part. For z greater than 1 the result is purely imaginary and positive.
cml_complex_t cml_complex_atan (cml_complex_t z)
This function returns the complex arctangent of the complex number z
, arctan (z). The branch cuts are on the imaginary axis, below − i and above i.
cml_complex_t cml_complex_asec (cml_complex_t z)
This function returns the complex arcsecant of the complex number z
,
cml_complex_t cml_complex_asec_real (double z)
This function returns the complex arcsecant of the real number z
,
cml_complex_t cml_complex_acsc (cml_complex_t z)
This function returns the complex arccosecant of the complex number z
,
cml_complex_t cml_complex_acsc_real (double z)
This function returns the complex arccosecant of the real number z
,
cml_complex_t cml_complex_acot (cml_complex_t z)
This function returns the complex arccotangent of the complex number z
,
single: hyperbolic functions, complex numbers
cml_complex_t cml_complex_sinh (cml_complex_t z)
This function returns the complex hyperbolic sine of the complex number z
, sinh (z) = (exp (z) − exp ( − z))/2.
cml_complex_t cml_complex_cosh (cml_complex_t z)
This function returns the complex hyperbolic cosine of the complex number z
, cosh (z) = (exp (z) + exp ( − z))/2.
cml_complex_t cml_complex_tanh (cml_complex_t z)
This function returns the complex hyperbolic tangent of the complex number z
, tanh (z) = sinh (z)/cosh (z).
cml_complex_t cml_complex_sech (cml_complex_t z)
This function returns the complex hyperbolic secant of the complex number z
,
cml_complex_t cml_complex_csch (cml_complex_t z)
This function returns the complex hyperbolic cosecant of the complex number z
,
cml_complex_t cml_complex_coth (cml_complex_t z)
This function returns the complex hyperbolic cotangent of the complex number z
, coth (z) = 1/tanh (z).
single: inverse hyperbolic functions, complex numbers
cml_complex_t cml_complex_asinh (cml_complex_t z)
This function returns the complex hyperbolic arcsine of the complex number z
,
cml_complex_t cml_complex_acosh (cml_complex_t z)
This function returns the complex hyperbolic arccosine of the complex number z
,
cml_complex_t cml_complex_acosh_real (double z)
This function returns the complex hyperbolic arccosine of the real number z
,
cml_complex_t cml_complex_atanh (cml_complex_t z)
This function returns the complex hyperbolic arctangent of the complex number z
,
cml_complex_t cml_complex_atanh_real (double z)
This function returns the complex hyperbolic arctangent of the real number z
,
cml_complex_t cml_complex_asech (cml_complex_t z)
This function returns the complex hyperbolic arcsecant of the complex number z
,
cml_complex_t cml_complex_acsch (cml_complex_t z)
This function returns the complex hyperbolic arccosecant of the complex number z
,
cml_complex_t cml_complex_acoth (cml_complex_t z)
This function returns the complex hyperbolic arccotangent of the complex number z
,