482 Appendix B The Standard C Library
Math Functions
The following list identifies the math functions.To use these routines, include the
following statement in your program:
#include <math.h>
The standard header file <tgmath.h>defines type-generic macros that can be used to
call a function from the math or complex math libraries without worrying about the
argument type. For example, you can use six different square root functions based upon
the argument type and return type:
n double sqrt (double x)
n float sqrtf (float x)
n long double sqrtl (long double x)
n double complex csqrt (double complex x)
n float complex csqrtf (float complex f)
n long double complex csqrtl (long double complex)
Instead of having to worry about all six functions, you can include <tgmath.h>instead
of <math.h>and <complex.h>and just use the “generic” version of the function under
the name sqrt.The corresponding macro defined in <tgmath.h>ensures that the cor-
rect function gets called.
Returning to <math.h>, the following macros can be used to test specific properties
of floating-point values given as argument(s):
int fpclassify (x)
Classifies xas NaN (FP_NAN), infinite (FP_INFINITE), normal (FP_NORMAL), subnormal
(FP_SUBNORMAL), zero (FP_ZERO), or in some other implementation-defined category;
each FP_...value is defined in math.h.
int isfin (x)
Does xrepresent a finite value?
int isinf (x)
Does xrepresent an infinite value?
int isgreater (x, y)
Is x> y?
int isgreaterequal (x, y)
Is x≥ y?
21 0672326663 AppB 6/10/04 2:03 PM Page 482