Sun Studio 12: C++ User's Guide

# 15.3 Mathematical Functions

The complex arithmetic library provides a number of mathematical functions. Some are peculiar to complex numbers; the rest are complex-number versions of functions in the standard C mathematical library.

All of these functions produce a result for every possible argument. If a function cannot produce a mathematically acceptable result, it calls complex_error and returns some suitable value. In particular, the functions try to avoid actual overflow and call complex_error with a message instead. The following tables describe the remainder of the complex arithmetic library functions.

Note –

The implementation of the sqrt and atan2 functions is aligned with the C99 csqrt Annex G specification.

Table 15–1 Complex Arithmetic Library Functions

Complex Arithmetic Library Function

Description

double abs(const complex)

Returns the magnitude of a complex number.

double arg(const complex)

Returns the angle of a complex number.

complex conj(const complex)

Returns the complex conjugate of its argument.

double imag(const complex&)

Returns the imaginary part of a complex number.

double norm(const complex)

Returns the square of the magnitude of its argument. Faster than abs, but more likely to cause an overflow. For comparing magnitudes.

complex polar(double mag, double ang=0.0)

Takes a pair of polar coordinates that represent the magnitude and angle of a complex number and returns the corresponding complex number.

double real(const complex&)

Returns the real part of a complex number.

Table 15–2 Complex Mathematical and Trigonometric Functions

Complex Arithmetic Library Function

Description

complex acos(const complex)

Returns the angle whose cosine is its argument.

complex asin(const complex)

Returns the angle whose sine is its argument.

complex atan(const complex)

Returns the angle whose tangent is its argument.

complex cos(const complex)

Returns the cosine of its argument.

complex cosh(const complex)

Returns the hyperbolic cosine of its argument.

complex exp(const complex)

Computes e**x, where e is the base of the natural logarithms, and x is the argument given to exp.

complex log(const complex)

Returns the natural logarithm of its argument.

complex log10(const complex)

Returns the common logarithm of its argument.

complex pow(double b, const complex exp)

complex pow(const complex b, int exp)

complex pow(const complex b, double exp)

complex pow(const complex b, const

complex exp)

Takes two arguments: pow(b, exp). It raises b to the power of exp.

complex sin(const complex)

Returns the sine of its argument.

complex sinh(const complex)

Returns the hyperbolic sine of its argument.

complex sqrt(const complex)

Returns the square root of its argument.

complex tan(const complex)

Returns the tangent of its argument.

complex tanh(const complex)

Returns the hyperbolic tangent of its argument.