Non-Confidential | PDF version | ARM DUI0472J | ||

| ||||

Home > Compiler Coding Practices > <tgmath.h> type-generic math macros in C99 |

The new standard header `<tgmath.h>`

defines several families of mathematical functions that are type generic in the sense that they are overloaded on floating-point types.

For example, the trigonometric function `cos`

works as if it has the
overloaded declaration:

extern float cos(float x); extern double cos(double x); extern long double cos(long double x); ...

A statement such as:

p = cos(0.78539f); // p = cos(pi / 4)

calls the single-precision version of the `cos`

function, as determined by
the type of the literal `0.78539f`

.

Type-generic families of mathematical functions can be defined in C++ using the operator
overloading mechanism. The semantics of type-generic families of functions defined using
operator overloading in C++ are different from the semantics of the corresponding families
of type-generic functions defined in `<tgmath.h>`

.