c/numeric/tgmath

The header includes the headers  and  and defines several type-generic macros that determine which real or, when applicable, complex function to call based on the types of the arguments.

For each macro, the parameters whose corresponding real type in the unsuffixed math.h function is are known as generic parameters (for example, both parameters of pow are generic parameters, but only the first parameter of scalbn is a generic parameter).

When a macro is used the types of the arguments passed to the generic parameters determine which function is selected by the macro as described below. If the types of the arguments are not compatible with the parameter types of the selected function, the behavior is undefined (e.g. if a complex argument is passed into a real-only 's macro: or  are examples of undefined behavior).

Note: type-generic macros were implemented in implementation-defined manner in C99, but C11 keyword makes it possible to implement these macros in portable manner.

Complex/real type-generic macros
For all functions that have both real and complex counterparts, a type-generic macro exists, which calls either of:
 * real function:
 * variant
 * variant
 * variant


 * complex function:
 * variant
 * variant
 * variant

An exception to the above rule is the macro (see the table below).

The function to call is determined as follows:


 * If any of the arguments for the generic parameters is imaginary, the behavior is specified on each function reference page individually (in particular,, , , , , , , , , and call real functions, the return types of , , , , , , , and  are imaginary, and the return types of  and  are real).
 * If any of the arguments for the generic parameters is complex, then the complex function is called, otherwise the real function is called.
 * If any of the arguments for the generic parameters is, then the variant is called. Otherwise, if any of the parameters is  or integer, then the  variant is called. Otherwise,  variant is called.

The type-generic macros are as follows:

Real-only functions
For all functions that do not have complex counterparts, with the exception of, a type-generic macro exists, which calls either of the variants of a real function:
 * variant
 * variant
 * variant

The function to call is determined as follows:


 * If any of the arguments for the generic parameters is, then the variant is called. Otherwise, if any of the arguments for the generic parameters is , then the  variant is called. Otherwise,  variant is called.

Complex-only functions
For all complex number functions that do not have real counterparts, a type-generic macro exists, which calls either of the variants of a complex function:
 * variant
 * variant
 * variant

The function to call is determined as follows:


 * If any of the arguments for the generic parameters is real, complex, or imaginary, then the appropriate complex function is called.