Tgmath.h: Difference between revisions

Content deleted Content added
 
(25 intermediate revisions by 4 users not shown)
Line 1:
#REDIRECT [[C mathematical functions#tgmath.h]]
{{merge to|C mathematical operations|discuss=Talk:C_standard_library#Pages_for_each_function_and_WP:NOTMANUAL|date=October 2011}}
{{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|long double]]) suffix, and whose corresponding type is [[Double|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 />
tan((float)x)<br />
then this [[Expression (computer science)|expression]] will have a type [[floating point|float]].<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 ==
Dependency graph for tgmath.h has been shown in the adjacent image.<ref>http://www-zeuthen.desy.de/apewww/APE/software/nlibc/html/tgmath_8h.html</ref>
[[File:Dependency Graph for tgmath.h|thumb|Dependency Graph]]
 
== Functions from <code>math.h</code>==
{|class="wikitable"
|-
! Name !! Description
|-
|<code>acos</code> || [[arccosine|inverse cosine]]
|-
|<code>asin</code> || [[arcsine|inverse sine]]
|-
|<code>atan</code> || [[arctangent|one-parameter inverse tangent]]
|-
|<code>atan2</code> || [[atan2|two-parameter inverse tangent]]
|-
|<code>ceil</code> || [[ceil (programming)|ceiling]], the smallest [[integer]] not less than parameter
|-
|<code>cos</code> || [[cosine]]
|-
|<code>cosh</code> || [[hyperbolic cosine]]
|-
|<code>exp</code> || [[exponential function]]
|-
|<code>fabs</code> || [[absolute value]] (of a [[floating-point number]])
|-
|<code>floor</code> || [[floor (programming)|floor]], the largest integer not greater than parameter
|-
|<code>fmod</code> || [[floating-point]] [[remainder]]
|-
|<code>frexp</code> || break [[floating-point]] number down into [[significand|mantissa]] and [[exponent]]
|-
|<code>ldexp</code> || scale [[floating-point]] number by [[exponent]] (see [[ldexp|article]])
|-
|<code>log</code> || [[natural logarithm]]
|-
|<code>log10</code> || [[common logarithm|base-10 logarithm]]
|-
|<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
|-
|<code>tan</code> || [[tangent (trigonometric function)|tangent]]
|-
|<code>tanh</code> || [[hyperbolic tangent]]
|}
 
== Functions from complex.h ==
{|class="wikitable"
|-
! Name !! Description
|-
|<code>cacos</code> || [[arccosine|inverse cosine]]
|-
|<code>casin</code> || [[arcsine|inverse sine]]
|-
|<code>catan</code> || [[arctangent|one-parameter inverse tangent]]
|-
|<code>catan2</code> || [[atan2|two-parameter inverse tangent]]
|-
|<code>cceil</code> || [[ceil (programming)|ceiling]], the smallest [[integer]] not less than parameter
|-
|<code>ccos</code> || [[cosine]]
|-
|<code>ccosh</code> || [[hyperbolic cosine]]
|-
|<code>cexp</code> || [[exponential function]]
|-
|<code>cfabs</code> || [[absolute value]] (of a [[floating-point number]])
|-
|<code>cfloor</code> || [[floor (programming)|floor]], the largest integer not greater than parameter
|-
|<code>cfmod</code> || [[fmod|floating-point remainder]]
|-
|<code>cfrexp</code> || break floating-point number down into [[significand|mantissa]] and [[exponent]]
|-
|<code>cldexp</code> || scale [[floating-point]] number by [[exponent]] (see [[ldexp|article]])
|-
|<code>clog</code> || [[natural logarithm]]
|-
|<code>clog10</code> || [[common logarithm|base-10 logarithm]]
|-
|<code>cmodf(''x'',''p'')</code> || returns fractional part of ''x'' and stores integral part where [[pointer (computing)|pointer]] ''p'' points to
|-
|<code>cpow(''x'',''y'')</code> || raise ''x'' to the power of ''y'', ''x<sup>y</sup>''
|-
|<code>csin</code> || [[sine]]
|-
|<code>csinh</code> || [[hyperbolic sine]]
|-
|<code>csqrt</code> || [[square root]]
|-
|<code>ctan</code> || [[tangent (trigonometric function)|tangent]]
|-
|<code>ctanh</code> || [[hyperbolic tangent]]
|}
 
== 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.
 
==References==
<references/>
 
{{DEFAULTSORT:TgmatH.H}}
[[Category:C standard library headers]]
 
== See also ==
* [[math.h]]
* [[complex.h]]
* [[Trigonometric Functions]]
* [[Hyperbolic trigonometric functions]]
 
== External Links ==
* Documentation http://clang.llvm.org/doxygen/tgmath_8h-source.html
* http://www.unix.com/man-page/OpenSolaris/3head/tgmath.h/
* http://publib.boulder.ibm.com/infocenter/zos/v1r11/index.jsp?topic=/com.ibm.zos.r11.bpxbd00/tgmathh.htm