Manual browser: tgmath(3)

Section:
Page:
TGMATH(3) Library Functions Manual TGMATH(3)

NAME

tgmathtype-generic macros

SYNOPSIS

#include <tgmath.h>

DESCRIPTION

The header <tgmath.h> provides type-generic macros for <math.h> and <complex.h> functions that have float (suffixed with f), double, and long double (suffixed with l) versions. The arguments that vary across the three functions and have type float, double, and long double, respectively, are called generic arguments.

The following rules describe which function is actually called if a type-generic macro is invoked. If any generic argument has type long double or long double complex, the long double function is called. Else, if any generic argument has type double, double complex, or an integer type, the double version is invoked. Otherwise, the macro expands to the float implementation.

For the macros in the following table, both real and complex functions exist. The real functions are prototyped in <math.h> and the complex equivalents in <complex.h>. The complex function is called if any of the generic arguments is a complex value. Otherwise, the real equivalent is called.

Macro Real function Complex function
acos() acos(3) cacos(3)
asin() asin(3) casin(3)
atan() atan(3) catan(3)
acosh() acosh(3) cacosh(3)
asinh() asinh(3) casinh(3)
atanh() atanh(3) catanh(3)
cos() cos(3) ccos(3)
sin() sin(3) csin(3)
tan() tan(3) ctan(3)
cosh() cosh(3) ccosh(3)
sinh() sinh(3) csinh(3)
tanh() tanh(3) ctanh(3)
exp() exp(3) cexp(3)
log() log(3) clog(3)
pow() pow(3) cpow(3)
sqrt() sqrt(3) csqrt(3)
fabs() fabs(3) cabs(3)

No complex functions exist for the following macros, so passing a complex value to a generic argument invokes undefined behaviour:

atan2(3) fma() llround() remainder(3)
cbrt(3) fmax(3) log10(3) remquo()
ceil(3) fmin(3) log1p(3) rint(3)
copysign(3) fmod(3) log2(3) round(3)
erf(3) frexp(3) logb(3) scalbn(3)
erfc(3) hypot(3) lrint(3) tgamma()
exp2(3) ilogb(3) lround() trunc(3)
expm1(3) ldexp(3) nextafter(3)
fdim(3) lgamma(3)
floor(3) llrint(3)

The following macros always expand to a complex function:

carg(3) cimag(3) conj(3) cproj() creal(3)

This header includes <complex.h> and <math.h>.

STANDARDS

The header <tgmath.h> conforms to ISO/IEC 9899:1999 (“ISO C99”).

AUTHORS

Matt Thomas <matt@3am-software.com>

BUGS

The header <tgmath.h> cannot be implemented with strictly conforming C code and needs special compiler support. The current implementation only works for GCC.

Many of the functions mentioned here are not prototyped in <math.h> or <complex.h> as they are not yet implemented.

December 14, 2010 NetBSD 7.0