{{merge#redirect to|[[C mathematical operations|discuss=Talk:math.h#Single page for C mathematical functions|date=OctoberFunction 2011}}overview]]
{{lowercase|title=tgmath.h}}
{{C_Standard_library}}
'''tgmath.h''' is a [[Standard C]] header that defines many type-generic [[macro]]s that can be used for a variety of mathematical operations. This header also includes <code>[[math.h]]</code> and <code>[[complex.h]]</code>. For all of the [[Function (computer science)|functions]] in the <code>math.h</code> and <code>complex.h</code> headers that do not have an f ([[Floating point|float]]) or l ([[long double]]) suffix, and whose corresponding type is [[double]] (with the exception of <code>modf()</code>), there is a corresponding macro.<ref>http://www.opengroup.org/onlinepubs/009695399/basedefs/tgmath.h.html</ref>
== Type-generic macro ==
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 an [[int (computer science)|int]] data type but [[tangent|tan]] has been called this way:<br />
<source lang="c"> tan((float)x)</source><br />
then this [[Expression (computer science)|expression]] will have a type [[floating point|float]]<ref>http://manpages.ubuntu.com/manpages/hardy/man7/tgmath.h.7posix.html</ref>.<br />
Also, if any one of the [[Parameter (computer programming)|parameters]] or [[Argument (computer science)|arguments]] of a type-generic macro is [[Complex number|complex]], it will call a complex function, otherwise a [[Real number|real]] function will be called. The type of function that is called, ultimately depends upon the final converted type of parameter.<ref>http://www.qnx.com/developers/docs/6.4.1/dinkum_en/c99/tgmath.html</ref>.
== Dependency Graph ==
The [[flowchart]] below shows the [[Dependency graph]] for tgmath.h.<ref>http://www-zeuthen.desy.de/apewww/APE/software/nlibc/html/tgmath_8h.html</ref>
[[File:Dependency Graph for tgmath.h.PNG|center|thumb|400px|Dependency Graph]]
== Functions from <code>math.h<ref name = "pubs"> http://pubs.opengroup.org/onlinepubs/009604599/basedefs/tgmath.h.html</ref></code>==
|<code>modf(''x'',''p'')</code> || returns [[fractional part]] of ''x'' and stores [[floor and ceiling functions|integral part]] where [[pointer (computing)|pointer]] ''p'' points to
|-
|<code>pow(''x'',''y'')</code> || raise ''x'' to the [[exponentiation|power]] of ''y'', ''x<sup>y</sup>''
|-
|<code>sin</code> || [[sine]]
|-
|<code>sinh</code> || [[hyperbolic sine]]
|-
|<code>sqrt</code> || [[square root]], returns non-negative square-root of the number
The code below illustrates usage of ,<code>atan</code> function defined in tgmath.h, which computes the [[Trigonometric functions|inverse of tangent]] of a number defined in the [[Domain of a function|___domain]] of [[Trigonometric functions|tangent]].
<source lang="c">
#include <stdio.h>
#include <tgmath.h>
int main()
{
float ang, ans;
scanf("%f", &ang);
ans = atan(ang);
printf("%0.3f\n", ans);
return 0;
}</source>
== Notable differences ==
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|nan]], whereas, csqrt returns 0.000000. Such differences may be noticed in other functions also.
== Rationale ==
This header file is mainly included while calculating mathematical functions.As it includes both [[math.h]] and [[complex.h]], the problem arising due to inconsistent input is solved. Including any of the header files, individually, involves inconsistent outputs for some inputs.