"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">     <html
xmlns="http://www.w3.org/1999/xhtml"> <head>
    <link            rel="stylesheet"             type="text/css"
href="../../../style.css" title="style" />
    <link  rel="stylesheet"  type="text/css"  href="../style.css"
title="style" />
    <meta             http‐equiv="content‐type"              con‐
tent="text/html;charset=utf‐8" />

    <title>tgmath.h.0p ‐ Linux manual page</title> </head>


<div        class="page‐top"><a       id="top_of_page"></a></div>
<!‐‐%%%TOP_BAR%%%‐‐> <!‐‐%%%PAGE_START%%%‐‐>

<table class="sec‐table"> <tr>
        <p class="section‐dir"> <a href="#PROLOG">PROLOG</a> | <a
href="#NAME">NAME</a>  |  <a  href="#SYNOPSIS">SYNOPSIS</a>  | <a
NALE</a>   |   <a    href="#FUTURE_DIRECTIONS">FUTURE&nbsp;DIREC‐
TIONS</a>    |   <a   href="#SEE_ALSO">SEE&nbsp;ALSO</a>   |   <a
    <td class="search‐box">
        <div class="man‐search‐box">

            <form                method="get"                 ac‐
                <fieldset class="man‐search">
                    <input    type="text"    name="q"   size="10"
maxlength="255" value="" />
                    <input type="hidden"  name="sitesearch"  val‐
ue="man7.org/linux/man‐pages" />
                    <input  type="submit" name="sa" value="Search
online pages" />

    <td> </td> </tr> </table>

<pre> <span class="headline">tgmath.h(0P)              POSIX Pro‐
grammer’s  Manual              tgmath.h(0P)</span>  </pre> <h2><a
id="PROLOG" href="#PROLOG"></a>PROLOG  &nbsp; &nbsp; &nbsp;  &nb‐
sp;        <a        href="#top_of_page"><span        class="top‐
       This manual page is part of the POSIX Programmer’s Manual.
The Linux
       implementation of this interface may differ (consult the
       corresponding  Linux  manual page for details of Linux be‐
havior), or
       the interface may not be  implemented  on  Linux.   </pre>
<h2><a id="NAME" href="#NAME"></a>NAME  &nbsp; &nbsp; &nbsp; &nb‐
sp;        <a        href="#top_of_page"><span        class="top‐
       tgmath.h — type‐generic macros </pre> <h2><a id="SYNOPSIS"
href="#SYNOPSIS"></a>SYNOPSIS  &nbsp;  &nbsp;  &nbsp;  &nbsp;  <a
href="#top_of_page"><span                             class="top‐
       #include &lt;tgmath.h&gt; </pre>  <h2><a  id="DESCRIPTION"
href="#DESCRIPTION"></a>DESCRIPTION   &nbsp; &nbsp; &nbsp; &nbsp;
<a             href="#top_of_page"><span              class="top‐
       The  functionality  described  on  this  reference page is
aligned with
       the ISO C standard. Any conflict between the  requirements
       here  and the ISO C standard is unintentional. This volume
       POSIX.1‐2008 defers to the ISO C standard.

       The <i>&lt;tgmath.h&gt;</i> header shall include the head‐
ers <i>&lt;math.h&gt;</i> and
       <i>&lt;complex.h&gt;</i>  and  shall  define several type‐
generic macros.

       Of     the     functions     contained     within      the
<i>&lt;math.h&gt;</i> and <i>&lt;complex.h&gt;</i>
       headers  without  an  <i>f</i>  (<b>float</b>) or <i>l</i>
(<b>long double</b>) suffix, several have
       one or more parameters whose corresponding  real  type  is
<b>double</b>.  For
       each  such  function,  except  <i>modf</i>(), <i>j0</i>(),
<i>j1</i>(), <i>jn</i>(), <i>y0</i>(), <i>y1</i>(), and
       <i>yn</i>(), there shall be a  corresponding  type‐generic
macro. The
       parameters  whose  corresponding  real  type  is <b>double
</b>in the function
       synopsis are generic parameters. Use of the macro  invokes
a function
       whose  corresponding  real type and type domain are deter‐
mined by the
       arguments for the generic parameters.

       Use of the macro invokes a function whose generic  parame‐
ters have the
       corresponding real type determined as follows:

        *  First, if any argument for generic parameters has type
           <b>double</b>, the type  determined  is  <b>long  dou‐

        *   Otherwise, if any argument for generic parameters has
type <b>double</b>
           or is of integer type, the type determined is  <b>dou‐

        *  Otherwise, the type determined is <b>float</b>.

       For  each unsuffixed function in the <i>&lt;math.h&gt;</i>
header for which there
       is a function in the <i>&lt;complex.h&gt;</i> header  with
the same name except for
       a  <i>c</i>  prefix,  the corresponding type‐generic macro
(for both functions)
       has   the   same   name   as   the   function    in    the
<i>&lt;math.h&gt;</i> header. The
       corresponding  type‐generic  macro  for  <i>fabs</i>() and
<i>cabs</i>() is <i>fabs</i>().

          │<b>&lt;math.h&gt;  Function </b>│ <b>&lt;complex.h&gt;
Function </b>│ <b>Type‐Generic Macro </b>│
          │<i>acos</i>()                   │       <i>cacos</i>()
│ <i>acos</i>()             │
          │<i>asin</i>()                  │        <i>casin</i>()
│ <i>asin</i>()             │
          │<i>atan</i>()                   │       <i>catan</i>()
│ <i>atan</i>()             │
          │<i>acosh</i>()                 │       <i>cacosh</i>()
│ <i>acosh</i>()            │
          │<i>asinh</i>()                 │       <i>casinh</i>()
│ <i>asinh</i>()            │
          │<i>atanh</i>()                 │       <i>catanh</i>()
│ <i>atanh</i>()            │
          │<i>cos</i>()                    │        <i>ccos</i>()
│ <i>cos</i>()              │
          │<i>sin</i>()                    │        <i>csin</i>()
│ <i>sin</i>()              │
          │<i>tan</i>()                    │        <i>ctan</i>()
│ <i>tan</i>()              │
          │<i>cosh</i>()                  │        <i>ccosh</i>()
│ <i>cosh</i>()             │
          │<i>sinh</i>()                   │       <i>csinh</i>()
│ <i>sinh</i>()             │
          │<i>tanh</i>()                  │        <i>ctanh</i>()
│ <i>tanh</i>()             │
          │<i>exp</i>()                    │        <i>cexp</i>()
│ <i>exp</i>()              │
          │<i>log</i>()                    │        <i>clog</i>()
│ <i>log</i>()              │
          │<i>pow</i>()                    │        <i>cpow</i>()
│ <i>pow</i>()              │
          │<i>sqrt</i>()                  │        <i>csqrt</i>()
│ <i>sqrt</i>()             │
          │<i>fabs</i>()                   │        <i>cabs</i>()
│ <i>fabs</i>()             │
       If  at  least one argument for a generic parameter is com‐
plex, then use
       of the macro invokes a complex function; otherwise, use of
the macro
       invokes a real function.

       For  each unsuffixed function in the <i>&lt;math.h&gt;</i>
header without a <i>c</i>‐
       prefixed counterpart in the <i>&lt;complex.h&gt;</i> head‐
er, except for <i>modf</i>(),
       <i>j0</i>(),    <i>j1</i>(),   <i>jn</i>(),   <i>y0</i>(),
<i>y1</i>(), and <i>yn</i>(), the corresponding type‐
       generic macro has the same name as  the  function.   These
       macros are:

              <i>atan2</i>()          <i>fma</i>()         <i>ll‐
round</i>()      <i>remainder</i>()
              <i>cbrt</i>()                         <i>fmax</i>()
<i>log10</i>()        <i>remquo</i>()
              <i>ceil</i>()                         <i>fmin</i>()
<i>log1p</i>()        <i>rint</i>()
              <i>copysign</i>()   <i>fmod</i>()     <i>log2</i>()
              <i>erf</i>()        <i>frexp</i>()    <i>logb</i>()
              <i>erfc</i>()                        <i>hypot</i>()
<i>lrint</i>()        <i>scalbn</i>()
              <i>exp2</i>()                        <i>ilogb</i>()
<i>lround</i>()       <i>tgamma</i>()
              <i>expm1</i>()        <i>ldexp</i>()       <i>near‐
byint</i>()    <i>trunc</i>()
              <i>fdim</i>()                       <i>lgamma</i>()
              <i>floor</i>()       <i>llrint</i>()     <i>nextto‐

       If all arguments for generic parameters are real, then use
of the
       macro invokes a real function; otherwise, use of the macro
results in
       undefined behavior.

       For   each   unsuffixed   function   in   the  <i>&lt;com‐
plex.h&gt;</i> header that is not a
       <i>c</i>‐prefixed  counterpart  to  a  function   in   the
<i>&lt;math.h&gt;</i> header, the
       corresponding  type‐generic macro has the same name as the
       These type‐generic macros are:

              <i>carg</i>()     <i>cimag</i>()      <i>conj</i>()
<i>cproj</i>() <i>creal</i>()

       Use of the macro with any real or complex argument invokes
a complex

       <i>The  following  sections  are  informative.</i>  </pre>
PLICATION    USAGE     &nbsp;    &nbsp;    &nbsp;    &nbsp;    <a
href="#top_of_page"><span                             class="top‐
       With the declarations:

           <b>#include &lt;tgmath.h&gt;</b>
           <b>int n;</b>
           <b>float f;</b>
           <b>double d;</b>
           <b>long double ld;</b>
           <b>float complex fc;</b>
           <b>double complex dc;</b>
           <b>long double complex ldc;</b>

       functions invoked by use of type‐generic macros are  shown
in the
       following table:

                │     <b>Macro        </b>│           <b>Use  In‐
vokes          </b>│
                │<i>exp</i>(<i>n</i>)                           │
<i>exp</i>(<i>n</i>), the function          │
                │<i>acosh</i>(<i>f</i>)                         │
<i>acoshf</i>(<i>f</i>)                     │
                │<i>sin</i>(<i>d</i>)                           │
<i>sin</i>(<i>d</i>), the function          │
                │<i>atan</i>(<i>ld</i>)                         │
<i>atanl</i>(<i>ld</i>)                     │
                │<i>log</i>(<i>fc</i>)                          │
<i>clogf</i>(<i>fc</i>)                     │
                │<i>sqrt</i>(<i>dc</i>)                         │
<i>csqrt</i>(<i>dc</i>)                     │
                │<i>pow</i>(<i>ldc,f</i>)                       │
<i>cpowl</i>(<i>ldc, f</i>)                 │
                │<i>remainder</i>(<i>n,n</i>)      │   <i>remain‐
der</i>(<i>n, n</i>), the function │
                │<i>nextafter</i>(<i>d,f</i>)                   │
<i>nextafter</i>(<i>d, f</i>), the function │
                │<i>nexttoward</i>(<i>f,ld</i>)    │   <i>nextto‐
wardf</i>(<i>f, ld</i>)            │
                │<i>copysign</i>(<i>n,ld</i>)      │     <i>copy‐
signl</i>(<i>n, ld</i>)              │
                │<i>ceil</i>(<i>fc</i>)          │  Undefined be‐
havior            │
                │<i>rint</i>(<i>dc</i>)         │  Undefined  be‐
havior            │
                │<i>fmax</i>(<i>ldc,ld</i>)      │  Undefined be‐
havior            │
                │<i>carg</i>(<i>n</i>)                          │
<i>carg</i>(<i>n</i>), the function         │
                │<i>cproj</i>(<i>f</i>)             │    <i>cpro‐
jf</i>(<i>f</i>)                     │
                │<i>creal</i>(<i>d</i>)             │     <i>cre‐
al</i>(<i>d</i>), the function        │
                │<i>cimag</i>(<i>ld</i>)                        │
<i>cimagl</i>(<i>ld</i>)                    │
                │<i>cabs</i>(<i>fc</i>)             │     <i>cab‐
sf</i>(<i>fc</i>)                     │
                │<i>carg</i>(<i>dc</i>)                         │
<i>carg</i>(<i>dc</i>), the function        │
                │<i>cproj</i>(<i>ldc</i>)          │     <i>cpro‐
jl</i>(<i>ldc</i>)                   │
</pre>  <h2><a   id="RATIONALE"   href="#RATIONALE"></a>RATIONALE
&nbsp;   &nbsp;   &nbsp;   &nbsp;   <a  href="#top_of_page"><span
       Type‐generic macros allow calling a function whose type is
       by  the argument type, as is the case for C operators such
as <b>’+’ </b>and
       <b>’*’</b>.  For example, with a type‐generic <i>cos</i>()
macro, the expression
       <i>cos</i>((<b>float</b>)<i>x</i>)    will    have    type
<b>float</b>.  This feature enables writing
       more portably efficient code and alleviates need for  awk‐
ward casting
       and  suffixing in the process of porting or adjusting pre‐
       Generic math functions are a widely appreciated feature of

       The only arguments that affect the type resolution are the
       corresponding to the parameters that have  type  <b>double
</b>in the
       synopsis.  Hence  the  type  of  a  type‐generic  call  to
       whose second parameter is <b>long double </b>in the synop‐
sis, is determined
       solely by the type of the first argument.

       The term ‘‘type‐generic’’ was chosen over the proposed al‐
       of intrinsic and overloading. The term  is  more  specific
       intrinsic, which already is widely used with a more gener‐
al meaning,
       and reflects a closer match to Fortran’s generic functions
than to
       C++ overloading.

       The  macros are placed in their own header in order not to
       break old programs that include the  <i>&lt;math.h&gt;</i>
header; for example,

           <b>printf ("%e", sin(x))</b>

       <i>modf</i>(<b>double</b>,  <b>double  *</b>)  is excluded
because no way was seen to make it
       safe without complicating the type resolution.

       The implementation might, as an extension, endow appropri‐
ate ones of
       the macros that POSIX.1‐2008 specifies only for real argu‐
ments with
       the ability to invoke the complex functions.

       POSIX.1‐2008 does not prescribe any particular implementa‐
       mechanism for generic macros. It could be implemented sim‐
ply with
       built‐in macros. The generic macro for <i>sqrt</i>(),  for
example, could be
       implemented with:

           <b>#undef sqrt</b>
           <b>#define sqrt(x) __BUILTIN_GENERIC_sqrt(x)</b>

       Generic  macros are designed for a useful level of consis‐
tency with
       C++ overloaded math functions.

       The great majority of existing C programs are expected  to
       unaffected  when the <i>&lt;tgmath.h&gt;</i> header is in‐
cluded instead of the
       <i>&lt;math.h&gt;</i> or <i>&lt;complex.h&gt;</i> headers.
Generic macros are similar to the
       ISO/IEC  9899:1999 standard library masking macros, though
       semantic types of return values differ.

       The ability to overload on integer  as  well  as  floating
types would
       have been useful for some functions; for example, <i>copy‐
       Overloading with different numbers of arguments would have
       reusing   names;   for   example,  <i>remainder</i>()  for
<i>remquo</i>().  However, these
       facilities would have complicated the  specification;  and
       natural   consistent   use,   such   as   for  a  floating
<i>abs</i>() or a two‐
       argument <i>atan</i>(), would have introduced further  in‐
consistencies with
       the ISO/IEC 9899:1999 standard for insufficient benefit.

       The  ISO  C standard in no way limits the implementation’s
options for
       efficiency, including inlining library functions.   </pre>
TURE    DIRECTIONS     &nbsp;    &nbsp;    &nbsp;    &nbsp;    <a
href="#top_of_page"><span                             class="top‐
       None.    </pre>   <h2><a   id="SEE_ALSO"    href="#SEE_AL‐
SO"></a>SEE    ALSO     &nbsp;    &nbsp;    &nbsp;    &nbsp;   <a
href="#top_of_page"><span                             class="top‐
       <a     href="../man0/math.h.0p.html">math.h(0p)</a>,    <a

       The  System  Interfaces   volume   of   POSIX.1‐2008,   <a
href="../man3/cabs.3p.html">cabs(3p)</a>,                      <a
       <a href="../man3/modf.3p.html">modf(3p)</a> </pre>  <h2><a
id="COPYRIGHT"   href="#COPYRIGHT"></a>COPYRIGHT   &nbsp;  &nbsp;
&nbsp;   &nbsp;    <a    href="#top_of_page"><span    class="top‐
       Portions  of  this  text  are  reprinted and reproduced in
electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for  Informa‐
       Technology ‐‐ Portable Operating System Interface (POSIX),
The Open
       Group Base Specifications Issue 7, Copyright (C)  2013  by
       Institute of Electrical and Electronics Engineers, Inc and
The Open
       Group.  (This is POSIX.1‐2008 with the 2013 Technical Cor‐
rigendum 1
       applied.)  In  the  event  of any discrepancy between this
version and
       the original IEEE and The Open Group Standard, the  origi‐
nal IEEE and
       The Open Group Standard is the referee document. The orig‐
       Standard    can    be    obtained     online     at     <a
line.html</a> .

       Any typographical or formatting errors that appear in this
page are
       most  likely to have been introduced during the conversion
of the
       source files to man page format. To  report  such  errors,
       <a      href="https://www.kernel.org/doc/man‐pages/report‐
ing_bugs.html</a> .

<span  class="footline">IEEE/The  Open Group                 2013
tgmath.h(0P)</span> </pre>

<hr class="end‐man‐text" />

<hr class="start‐footer" />

<div class="footer">

<table class="colophon‐table">
    <td class="pub‐info">
            HTML rendering created 2019‐08‐02
            by  <a  href="http://man7.org/mtk/index.html">Michael
            author of
            <a  href="http://man7.org/tlpi/"><em>The  Linux  Pro‐
gramming Interface</em></a>,
            maintainer of the
            <a href="https://www.kernel.org/doc/man‐pages/">Linux
<em>man‐pages</em> project</a>.
            For details of in‐depth
            <strong>Linux/UNIX  system programming training cour‐
            that I teach,  look  <a  href="http://man7.org/train‐
            Hosting    by    <a   href="http://www.jambit.com/in‐
dex_en.html">jambit GmbH</a>.
            <a href="http://validator.w3.org/check?uri=referer">
            <img src="http://www.w3.org/Icons/valid‐xhtml11"
                alt="Valid XHTML 1.1" height="31" width="88" />
    <td class="colophon‐divider">
    <td class="tlpi‐cover">
        <a                      href="http://man7.org/tlpi/"><img
alt="Cover of TLPI" /></a>
    </tr> </table>


<hr class="end‐footer" />

</body> </html>