Copyright (c) 2004 Stefan Farfeleder
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

$FreeBSD$

.Dd August 14, 2004 .Dt TGMATH 3 .Os .Sh NAME .Nm tgmath .Nd "type-generic macros" .Sh SYNOPSIS n tgmath.h .Sh DESCRIPTION The header n tgmath.h provides type-generic macros for n math.h and n complex.h functions that have .Vt float (suffixed with .Sy f ) , .Vt double and .Vt "long double" (suffixed with .Sy l ) versions. The arguments that vary across the three functions and have type .Vt float , double and .Vt "long double" , respectively, are called .Em "generic arguments" .

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

p For the macros in the following table, both real and complex functions exist. The real functions are prototyped in n math.h and the complex equivalents in n complex.h . The complex function is called if any of the generic arguments is a complex value. Otherwise, the real equivalent is called. l -column -offset indent ".Fn acosh" "Sy real function" ".Sy complex function" t Sy Macro Ta Sy real function Ta Sy complex function t Fn acos Ta Fn acos Ta Fn cacos t Fn asin Ta Fn asin Ta Fn casin t Fn atan Ta Fn atan Ta Fn catan t Fn acosh Ta Fn acosh Ta Fn cacosh t Fn asinh Ta Fn asinh Ta Fn casinh t Fn atanh Ta Fn atanh Ta Fn catanh t Fn cos Ta Fn cos Ta Fn ccos t Fn sin Ta Fn sin Ta Fn csin t Fn tan Ta Fn tan Ta Fn ctan t Fn cosh Ta Fn cosh Ta Fn ccosh t Fn sinh Ta Fn sinh Ta Fn csinh t Fn tanh Ta Fn tanh Ta Fn ctanh t Fn exp Ta Fn exp Ta Fn cexp t Fn log Ta Fn log Ta Fn clog t Fn pow Ta Fn pow Ta Fn cpow t Fn sqrt Ta Fn sqrt Ta Fn csqrt t Fn fabs Ta Fn fabs Ta Fn cabs .El

p No complex functions exist for the following macros, so passing a complex value to a generic argument invokes undefined behaviour: l -column -offset indent ".Fn nexttoward" ".Fn nexttoward" ".Fn nexttoward" ".Fn nexttoward" t Fn atan2 Ta Fn fma Ta Fn llround Ta Fn remainder t Fn cbrt Ta Fn fmax Ta Fn log10 Ta Fn remquo t Fn ceil Ta Fn fmin Ta Fn log1p Ta Fn rint t Fn copysign Ta Fn fmod Ta Fn log2 Ta Fn round t Fn erf Ta Fn frexp Ta Fn logb Ta Fn scalbn t Fn erfc Ta Fn hypot Ta Fn lrint Ta Fn scalbln t Fn exp2 Ta Fn ilogb Ta Fn lround Ta Fn tgamma t Fn expm1 Ta Fn ldexp Ta Fn nextbyint Ta Fn trunc t Fn fdim Ta Fn lgamma Ta Fn nextafter t Fn floor Ta Fn llrint Ta Fn nexttoward .El

p The following macros always expand to a complex function: l -column -offset indent ".Fn cimag" ".Fn cimag" ".Fn cimag" ".Fn cimag" ".Fn cimag" t Fn carg Ta Fn cimag Ta Fn conj Ta Fn cproj Ta Fn creal .El

p This header includes n complex.h and n math.h . .Sh STANDARDS The header n tgmath.h conforms to .St -isoC-99 . .Sh HISTORY The header n tgmath.h first appeared in .Fx 5.3 . .Sh BUGS The header n tgmath.h cannot be implemented with strictly conforming C code and needs special compiler support. The current implementation only works for GCC.

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