tgmath.h is aStandard C header that defines many type-genericmacros that can be used for a variety of mathematical operations. This header also includesmath.h andcomplex.h. For all of the functions in themath.h andcomplex.h headers that do not have an f (float) or l (long double) suffix, and whose corresponding type is double (with the exception ofmodf()), there is a corresponding macro.[1]
A type generic macro is something which allows calling a function whose type is determined by the type of argument in the macro. This means, for example, x is declared as anint data type but has been called this way:
tan((float)x)
then this expression will have a typefloat[2].
Also, if any one of the parameters or arguments of a type-generic macro is complex, it will call a complex function, otherwise a real function will be called. The type of function that is called, ultimately depends upon the final converted type of parameter.[3].
The flowchart below shows the Dependency graph for tgmath.h.[4]

math.hThe functions listed below handle real arguments and return real output only. If complex arguments are passed to these functions, NaN or other special numbers are returned[5].
| Name | Description |
|---|---|
acos | inverse cosine |
asin | inverse sine |
atan | one-parameter inverse tangent |
atan2 | two-parameter inverse tangent |
ceil | ceiling, the smallest integer not less than parameter |
cos | cosine |
cosh | hyperbolic cosine |
exp | exponential function |
fabs | absolute value of a floating-point number |
floor | floor, the largest integer not greater than parameter |
fmod | floating-point remainder |
frexp | decomposes a number into significand and a power of 2 |
ldexp | scale floating-point number by exponent (see article) |
log | natural logarithm |
log10 | base-10 logarithm |
modf(x,p) | returns fractional part ofx and stores integral part where pointerp points to |
pow(x,y) | raisex to the power ofy,xy |
sin | sine |
sinh | hyperbolic sine |
sqrt | square root, returns non-negative square-root of the number |
tan | tangent |
tanh | hyperbolic tangent |
isgreater | If x > y, it returns 1, otherwise 0 |
isnan(x) | returns 1, if x is NaN (Not A Number) |
islessequal | returns 1, if x is less than or equal to y, otherwise returns 0 |
isinf(x) | represents whether x is infinite |
signbit | represents whether x is negative (returns 8 if x is less than 0, otherwise returns 0) |
complex.hThe functions defined below handle complex parameters, but do not return complex output[5].
| Name | Description |
|---|---|
cacos | inverse cosine |
casin | inverse sine |
catan | one-parameter inverse tangent |
catan2 | two-parameter inverse tangent |
cceil | ceiling, the smallest integer not less than parameter |
ccos | cosine |
ccosh | hyperbolic cosine |
cexp | exponential function |
cabs | absolute value of a complex floating-point number |
cfloor | floor, the largest integer not greater than parameter |
cfmod | floating-point remainder |
cfrexp | decomposes a number into significand and a power of 2 |
cldexp | scale floating-point number by exponent (see article) |
clog | natural logarithm |
clog10 | base-10 logarithm |
cmodf(x,p) | returns fractional part ofx and stores integral part where pointerp points to |
cpow(x,y) | raisex to the power ofy,xy |
csin | sine |
csinh | hyperbolic sine |
csqrt | square root, returns non-negative square-root of the number |
ctan | tangent |
ctanh | hyperbolic tangent |
The code below illustrates usage of ,atan function defined intgmath.h, which computes the inverse of tangent of a number defined in the domain of tangent.
#include<stdio.h>#include<tgmath.h>intmain(){floatang,ans;scanf("%f",&ang);ans=atan(ang);printf("%0.3f\n",ans);return0;}
The similar functions defined here have notable difference when it comes to return value of "tricky" numbers. For example, using sqrt to compute square root of -25 returns-NaN(Not a Number), whereas, csqrt returns 0.000000. Such differences may be noticed in other functions also.
This header file is mainly included while calculating mathematical functions.As it includes bothmath.h andcomplex.h, the problem arising due to inconsistent input is solved. Including any of the header files, individually, involves inconsistent outputs for some inputs.