|
|
The C99 Standard added features to the C library two ways. First, it added functions to headers previously defined by C89. For example, significant additions were made to the mathematics library supported by the <math.h> header. These additional functions were covered in the preceding chapters. Second, new categories of functions, ranging from support for complex arithmetic to type-generic macros, were created, along with new headers to support them. These new library elements are described in this chapter. Keep in mind that none of the features described here are supported by C++.
C99 adds complex arithmetic capabilities to C. At the outset, it is important to state that the C99 complex math library differs completely from the complex class library defined by C++. If you will be programming in C++, you will want to use the C++ complex library. The C99 complex library is appropriate only for programmers restricted to the C language.
The C99 complex library is supported by the <complex.h> header. The following macros are defined:
Macro | Expands To |
---|---|
complex | _Complex |
imaginary | _Imaginary |
_Complex_I | (const float _Complex) i |
_Imaginary_I | (const float _Imaginary) i |
I | _Imaginary_I (or _Complex_I if imaginary types are not supported) |
Here, i represents the imaginary value, which is the square root of –1. Support for imaginary types is optional.
_Complex and _Imaginary, rather than complex and imaginary, were specified as a keywords by C99 because many existing C89 programs had already defined their own custom complex data types using the names complex and imaginary. By using the keywords _Complex and _Imaginary, C99 avoids breaking preexisting code. For new programs, however, it is best to include <complex.h> and then use the complex and imaginary macros.
The complex math functions are shown below. Notice that float complex, double complex, and long double complex versions of each function are defined. The float complex version uses the suffix f, and the long double complex version uses the suffix l. Also, angles are in radians.
Function | Description |
---|---|
float cabsf(float complex arg); | Returns the complex absolute value of arg |
float complex cacosf(float complex arg); | Returns the complex arc cosine of arg |
float complex cacoshf(float complex arg); | Returns the complex arc hyperbolic cosine of arg |
float cargf(float complex arg); | Returns the phase angle of arg |
float complex casinf(float complex arg); | Returns the complex arc sine of arg |
float complex casinhf(float complex arg); | Returns the complex arc hyperbolic sine of arg |
float complex catanf(float complex arg); | Returns the complex arc tangent of arg |
float complex catanhf(float complex arg); | Returns the complex arc hyperbolic tangent of arg |
float complex ccosf(float complex arg); | Returns the complex cosine of arg |
float complex ccoshf(float complex arg); | Returns the complex hyperbolic cosine of arg |
float complex cexpf(float complex arg); | Returns the complex value earg, where e is the natural |
float cimagf(float complex arg); | Returns the imaginary part of arg |
float complex clogf(float complex arg); | Returns the complex natural logarithm of arg |
float complex conjf(float complex arg); | Returns the complex conjugate of arg |
float complex cpowf(float complex a, | Returns the complex value of ab |
float complex cprojf(float complex arg); | Returns the projection of arg onto the Riemann sphere |
float crealf(float complex arg); | Returns the real part of arg |
float complex csinf(float complex arg); | Returns the complex sine of arg |
float complex csinhf(float complex arg); | Returns the complex hyperbolic sine of arg |
float complex csqrtf(float complex arg); | Returns the complex square root of arg |
float complex ctanf(float complex arg); | Returns the complex tangent of arg |
float complex ctanhf(float complex arg); | Returns the complex hyperbolic tangent of arg |
|
|