summaryrefslogtreecommitdiff
path: root/devdocs/c/numeric%2Ftgmath.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/c/numeric%2Ftgmath.html')
-rw-r--r--devdocs/c/numeric%2Ftgmath.html138
1 files changed, 138 insertions, 0 deletions
diff --git a/devdocs/c/numeric%2Ftgmath.html b/devdocs/c/numeric%2Ftgmath.html
new file mode 100644
index 00000000..2e53991e
--- /dev/null
+++ b/devdocs/c/numeric%2Ftgmath.html
@@ -0,0 +1,138 @@
+ <h1 id="firstHeading" class="firstHeading">Type-generic math</h1> <p>The header <code>&lt;tgmath.h&gt;</code> includes the headers <code>&lt;math.h&gt;</code> and <code>&lt;complex.h&gt;</code> and defines several type-generic macros that determine which real or, when applicable, complex function to call based on the types of the arguments.</p>
+<p>For each macro, the parameters whose corresponding real type in the unsuffixed math.h function is <code>double</code> are known as <i>generic parameters</i> (for example, both parameters of <code><a href="math/pow" title="c/numeric/math/pow">pow</a></code> are generic parameters, but only the first parameter of <code><a href="math/scalbn" title="c/numeric/math/scalbn">scalbn</a></code> is a generic parameter).</p>
+<p>When a <code>&lt;tgmath.h&gt;</code> macro is used the types of the arguments passed to the generic parameters determine which function is selected by the macro as described below. If the types of the arguments are not <a href="../language/type#Compatible_types" title="c/language/type">compatible</a> with the parameter types of the selected function, the behavior is undefined (e.g. if a complex argument is passed into a real-only <code>&lt;tgmath.h&gt;</code>'s macro: <code><span class="kw4">float</span> <a href="http://en.cppreference.com/w/c/numeric/complex/complex"><span class="kw743">complex</span></a> fc<span class="sy4">;</span> <a href="http://en.cppreference.com/w/c/numeric/math/ceil"><span class="kw686">ceil</span></a><span class="br0">(</span>fc<span class="br0">)</span><span class="sy4">;</span></code> or <code><span class="kw4">double</span> <a href="http://en.cppreference.com/w/c/numeric/complex/complex"><span class="kw743">complex</span></a> dc<span class="sy4">;</span> <span class="kw4">double</span> d<span class="sy4">;</span> <a href="http://en.cppreference.com/w/c/numeric/math/fmax"><span class="kw651">fmax</span></a><span class="br0">(</span>dc, d<span class="br0">)</span><span class="sy4">;</span></code> are examples of undefined behavior).</p>
+<p>Note: type-generic macros were implemented in implementation-defined manner in C99, but C11 keyword <a href="../keyword/_generic" title="c/keyword/ Generic"><code>_Generic</code></a> makes it possible to implement these macros in portable manner.</p>
+<h3 id="Complex.2Freal_type-generic_macros"> Complex/real type-generic macros</h3> <p>For all functions that have both real and complex counterparts, a type-generic macro <code>XXX</code> exists, which calls either of:</p>
+<ul>
+<li> real function: </li>
+<ul>
+<li> <code>float</code> variant <code>XXXf</code> </li>
+<li> <code>double</code> variant <code>XXX</code> </li>
+<li> <code>long double</code> variant <code>XXXl</code> </li>
+</ul>
+<li> complex function: </li>
+<ul>
+<li> <code>float</code> variant <code>cXXXf</code> </li>
+<li> <code>double</code> variant <code>cXXX</code> </li>
+<li> <code>long double</code> variant <code>cXXXl</code> </li>
+</ul>
+</ul> <p>An exception to the above rule is the <code>fabs</code> macro (see the table below).</p>
+<p>The function to call is determined as follows:</p>
+<ul>
+<li> If any of the arguments for the generic parameters is imaginary, the behavior is specified on each function reference page individually (in particular, <code>sin</code>, <code>cos</code>, <code>tag</code>, <code>cosh</code>, <code>sinh</code>, <code>tanh</code>, <code>asin</code>, <code>atan</code>, <code>asinh</code>, and <code>atanh</code> call <i>real</i> functions, the return types of <code>sin</code>, <code>tan</code>, <code>sinh</code>, <code>tanh</code>, <code>asin</code>, <code>atan</code>, <code>asinh</code>, and <code>atanh</code> are imaginary, and the return types of <code>cos</code> and <code>cosh</code> are real). </li>
+<li> If any of the arguments for the generic parameters is complex, then the complex function is called, otherwise the real function is called. </li>
+<li> If any of the arguments for the generic parameters is <code>long double</code>, then the <code>long double</code> variant is called. Otherwise, if any of the parameters is <code>double</code> or integer, then the <code>double</code> variant is called. Otherwise, <code>float</code> variant is called. </li>
+</ul> <p>The type-generic macros are as follows:</p>
+<table class="wikitable"> <tr> <th> Type-generic macro </th> <th colspan="3"> Real function <br> variants </th> <th colspan="3"> Complex function <br> variants </th>
+</tr> <tr> <th> </th> <th> <div><code>float</code></div> </th> <th> <div><code>double</code></div> </th> <th> <div><code>long double</code></div> </th> <th> <div><code>float</code></div> </th> <th> <div><code>double</code></div> </th> <th> <div><code>long double</code></div> </th>
+</tr> <tr> <th> fabs </th> <td> <a href="math/fabs" title="c/numeric/math/fabs"><code>fabsf</code></a> </td> <td> <a href="math/fabs" title="c/numeric/math/fabs"><code>fabs</code></a> </td> <td> <a href="math/fabs" title="c/numeric/math/fabs"><code>fabsl</code></a> </td> <td> <a href="complex/cabs" title="c/numeric/complex/cabs"><code>cabsf</code></a> </td> <td> <a href="complex/cabs" title="c/numeric/complex/cabs"><code>cabs</code></a> </td> <td> <a href="complex/cabs" title="c/numeric/complex/cabs"><code>cabsl</code></a> </td>
+</tr> <tr> <th> exp </th> <td> <a href="math/exp" title="c/numeric/math/exp"><code>expf</code></a> </td> <td> <a href="math/exp" title="c/numeric/math/exp"><code>exp</code></a> </td> <td> <a href="math/exp" title="c/numeric/math/exp"><code>expl</code></a> </td> <td> <a href="complex/cexp" title="c/numeric/complex/cexp"><code>cexpf</code></a> </td> <td> <a href="complex/cexp" title="c/numeric/complex/cexp"><code>cexp</code></a> </td> <td> <a href="complex/cexp" title="c/numeric/complex/cexp"><code>cexpl</code></a> </td>
+</tr> <tr> <th> log </th> <td> <a href="math/log" title="c/numeric/math/log"><code>logf</code></a> </td> <td> <a href="math/log" title="c/numeric/math/log"><code>log</code></a> </td> <td> <a href="math/log" title="c/numeric/math/log"><code>logl</code></a> </td> <td> <a href="complex/clog" title="c/numeric/complex/clog"><code>clogf</code></a> </td> <td> <a href="complex/clog" title="c/numeric/complex/clog"><code>clog</code></a> </td> <td> <a href="complex/clog" title="c/numeric/complex/clog"><code>clogl</code></a> </td>
+</tr> <tr> <th> pow </th> <td> <a href="math/pow" title="c/numeric/math/pow"><code>powf</code></a> </td> <td> <a href="math/pow" title="c/numeric/math/pow"><code>pow</code></a> </td> <td> <a href="math/pow" title="c/numeric/math/pow"><code>powl</code></a> </td> <td> <a href="complex/cpow" title="c/numeric/complex/cpow"><code>cpowf</code></a> </td> <td> <a href="complex/cpow" title="c/numeric/complex/cpow"><code>cpow</code></a> </td> <td> <a href="complex/cpow" title="c/numeric/complex/cpow"><code>cpowl</code></a> </td>
+</tr> <tr> <th> sqrt </th> <td> <a href="math/sqrt" title="c/numeric/math/sqrt"><code>sqrtf</code></a> </td> <td> <a href="math/sqrt" title="c/numeric/math/sqrt"><code>sqrt</code></a> </td> <td> <a href="math/sqrt" title="c/numeric/math/sqrt"><code>sqrtl</code></a> </td> <td> <a href="complex/csqrt" title="c/numeric/complex/csqrt"><code>csqrtf</code></a> </td> <td> <a href="complex/csqrt" title="c/numeric/complex/csqrt"><code>csqrt</code></a> </td> <td> <a href="complex/csqrt" title="c/numeric/complex/csqrt"><code>csqrtl</code></a> </td>
+</tr> <tr> <th> sin </th> <td> <a href="math/sin" title="c/numeric/math/sin"><code>sinf</code></a> </td> <td> <a href="math/sin" title="c/numeric/math/sin"><code>sin</code></a> </td> <td> <a href="math/sin" title="c/numeric/math/sin"><code>sinl</code></a> </td> <td> <a href="complex/csin" title="c/numeric/complex/csin"><code>csinf</code></a> </td> <td> <a href="complex/csin" title="c/numeric/complex/csin"><code>csin</code></a> </td> <td> <a href="complex/csin" title="c/numeric/complex/csin"><code>csinl</code></a> </td>
+</tr> <tr> <th> cos </th> <td> <a href="math/cos" title="c/numeric/math/cos"><code>cosf</code></a> </td> <td> <a href="math/cos" title="c/numeric/math/cos"><code>cos</code></a> </td> <td> <a href="math/cos" title="c/numeric/math/cos"><code>cosl</code></a> </td> <td> <a href="complex/ccos" title="c/numeric/complex/ccos"><code>ccosf</code></a> </td> <td> <a href="complex/ccos" title="c/numeric/complex/ccos"><code>ccos</code></a> </td> <td> <a href="complex/ccos" title="c/numeric/complex/ccos"><code>ccosl</code></a> </td>
+</tr> <tr> <th> tan </th> <td> <a href="math/tan" title="c/numeric/math/tan"><code>tanf</code></a> </td> <td> <a href="math/tan" title="c/numeric/math/tan"><code>tan</code></a> </td> <td> <a href="math/tan" title="c/numeric/math/tan"><code>tanl</code></a> </td> <td> <a href="complex/ctan" title="c/numeric/complex/ctan"><code>ctanf</code></a> </td> <td> <a href="complex/ctan" title="c/numeric/complex/ctan"><code>ctan</code></a> </td> <td> <a href="complex/ctan" title="c/numeric/complex/ctan"><code>ctanl</code></a> </td>
+</tr> <tr> <th> asin </th> <td> <a href="math/asin" title="c/numeric/math/asin"><code>asinf</code></a> </td> <td> <a href="math/asin" title="c/numeric/math/asin"><code>asin</code></a> </td> <td> <a href="math/asin" title="c/numeric/math/asin"><code>asinl</code></a> </td> <td> <a href="complex/casin" title="c/numeric/complex/casin"><code>casinf</code></a> </td> <td> <a href="complex/casin" title="c/numeric/complex/casin"><code>casin</code></a> </td> <td> <a href="complex/casin" title="c/numeric/complex/casin"><code>casinl</code></a> </td>
+</tr> <tr> <th> acos </th> <td> <a href="math/acos" title="c/numeric/math/acos"><code>acosf</code></a> </td> <td> <a href="math/acos" title="c/numeric/math/acos"><code>acos</code></a> </td> <td> <a href="math/acos" title="c/numeric/math/acos"><code>acosl</code></a> </td> <td> <a href="complex/cacos" title="c/numeric/complex/cacos"><code>cacosf</code></a> </td> <td> <a href="complex/cacos" title="c/numeric/complex/cacos"><code>cacos</code></a> </td> <td> <a href="complex/cacos" title="c/numeric/complex/cacos"><code>cacosl</code></a> </td>
+</tr> <tr> <th> atan </th> <td> <a href="math/atan" title="c/numeric/math/atan"><code>atanf</code></a> </td> <td> <a href="math/atan" title="c/numeric/math/atan"><code>atan</code></a> </td> <td> <a href="math/atan" title="c/numeric/math/atan"><code>atanl</code></a> </td> <td> <a href="complex/catan" title="c/numeric/complex/catan"><code>catanf</code></a> </td> <td> <a href="complex/catan" title="c/numeric/complex/catan"><code>catan</code></a> </td> <td> <a href="complex/catan" title="c/numeric/complex/catan"><code>catanl</code></a> </td>
+</tr> <tr> <th> sinh </th> <td> <a href="math/sinh" title="c/numeric/math/sinh"><code>sinhf</code></a> </td> <td> <a href="math/sinh" title="c/numeric/math/sinh"><code>sinh</code></a> </td> <td> <a href="math/sinh" title="c/numeric/math/sinh"><code>sinhl</code></a> </td> <td> <a href="complex/csinh" title="c/numeric/complex/csinh"><code>csinhf</code></a> </td> <td> <a href="complex/csinh" title="c/numeric/complex/csinh"><code>csinh</code></a> </td> <td> <a href="complex/csinh" title="c/numeric/complex/csinh"><code>csinhl</code></a> </td>
+</tr> <tr> <th> cosh </th> <td> <a href="math/cosh" title="c/numeric/math/cosh"><code>coshf</code></a> </td> <td> <a href="math/cosh" title="c/numeric/math/cosh"><code>cosh</code></a> </td> <td> <a href="math/cosh" title="c/numeric/math/cosh"><code>coshl</code></a> </td> <td> <a href="complex/ccosh" title="c/numeric/complex/ccosh"><code>ccoshf</code></a> </td> <td> <a href="complex/ccosh" title="c/numeric/complex/ccosh"><code>ccosh</code></a> </td> <td> <a href="complex/ccosh" title="c/numeric/complex/ccosh"><code>ccoshl</code></a> </td>
+</tr> <tr> <th> tanh </th> <td> <a href="math/tanh" title="c/numeric/math/tanh"><code>tanhf</code></a> </td> <td> <a href="math/tanh" title="c/numeric/math/tanh"><code>tanh</code></a> </td> <td> <a href="math/tanh" title="c/numeric/math/tanh"><code>tanhl</code></a> </td> <td> <a href="complex/ctanh" title="c/numeric/complex/ctanh"><code>ctanhf</code></a> </td> <td> <a href="complex/ctanh" title="c/numeric/complex/ctanh"><code>ctanh</code></a> </td> <td> <a href="complex/ctanh" title="c/numeric/complex/ctanh"><code>ctanhl</code></a> </td>
+</tr> <tr> <th> asinh </th> <td> <a href="math/asinh" title="c/numeric/math/asinh"><code>asinhf</code></a> </td> <td> <a href="math/asinh" title="c/numeric/math/asinh"><code>asinh</code></a> </td> <td> <a href="math/asinh" title="c/numeric/math/asinh"><code>asinhl</code></a> </td> <td> <a href="complex/casinh" title="c/numeric/complex/casinh"><code>casinhf</code></a> </td> <td> <a href="complex/casinh" title="c/numeric/complex/casinh"><code>casinh</code></a> </td> <td> <a href="complex/casinh" title="c/numeric/complex/casinh"><code>casinhl</code></a> </td>
+</tr> <tr> <th> acosh </th> <td> <a href="math/acosh" title="c/numeric/math/acosh"><code>acoshf</code></a> </td> <td> <a href="math/acosh" title="c/numeric/math/acosh"><code>acosh</code></a> </td> <td> <a href="math/acosh" title="c/numeric/math/acosh"><code>acoshl</code></a> </td> <td> <a href="complex/cacosh" title="c/numeric/complex/cacosh"><code>cacoshf</code></a> </td> <td> <a href="complex/cacosh" title="c/numeric/complex/cacosh"><code>cacosh</code></a> </td> <td> <a href="complex/cacosh" title="c/numeric/complex/cacosh"><code>cacoshl</code></a> </td>
+</tr> <tr> <th> atanh </th> <td> <a href="math/atanh" title="c/numeric/math/atanh"><code>atanhf</code></a> </td> <td> <a href="math/atanh" title="c/numeric/math/atanh"><code>atanh</code></a> </td> <td> <a href="math/atanh" title="c/numeric/math/atanh"><code>atanhl</code></a> </td> <td> <a href="complex/catanh" title="c/numeric/complex/catanh"><code>catanhf</code></a> </td> <td> <a href="complex/catanh" title="c/numeric/complex/catanh"><code>catanh</code></a> </td> <td> <a href="complex/catanh" title="c/numeric/complex/catanh"><code>catanhl</code></a> </td>
+</tr>
+</table> <h3 id="Real-only_functions"> Real-only functions</h3> <p>For all functions that do not have complex counterparts, with the exception of <code>modf</code>, a type-generic macro <code>XXX</code> exists, which calls either of the variants of a real function:</p>
+<ul>
+<li> <code>float</code> variant <code>XXXf</code> </li>
+<li> <code>double</code> variant <code>XXX</code> </li>
+<li> <code>long double</code> variant <code>XXXl</code> </li>
+</ul> <p>The function to call is determined as follows:</p>
+<ul><li> If any of the arguments for the generic parameters is <code>long double</code>, then the <code>long double</code> variant is called. Otherwise, if any of the arguments for the generic parameters is <code>double</code>, then the <code>double</code> variant is called. Otherwise, <code>float</code> variant is called. </li></ul> <table class="wikitable"> <tr> <th> Type-generic macro </th> <th colspan="3"> Real function <br> variants </th>
+</tr> <tr> <th> </th> <th> <div><code>float</code></div> </th> <th> <div><code>double</code></div> </th> <th> <div><code>long double</code></div> </th>
+</tr> <tr> <th> atan2 </th> <td> <a href="math/atan2" title="c/numeric/math/atan2"><code>atan2f</code></a> </td> <td> <a href="math/atan2" title="c/numeric/math/atan2"><code>atan2</code></a> </td> <td> <a href="math/atan2" title="c/numeric/math/atan2"><code>atan2l</code></a> </td>
+</tr> <tr> <th> cbrt </th> <td> <a href="math/cbrt" title="c/numeric/math/cbrt"><code>cbrtf</code></a> </td> <td> <a href="math/cbrt" title="c/numeric/math/cbrt"><code>cbrt</code></a> </td> <td> <a href="math/cbrt" title="c/numeric/math/cbrt"><code>cbrtl</code></a> </td>
+</tr> <tr> <th> ceil </th> <td> <a href="math/ceil" title="c/numeric/math/ceil"><code>ceilf</code></a> </td> <td> <a href="math/ceil" title="c/numeric/math/ceil"><code>ceil</code></a> </td> <td> <a href="math/ceil" title="c/numeric/math/ceil"><code>ceill</code></a> </td>
+</tr> <tr> <th> copysign </th> <td> <a href="math/copysign" title="c/numeric/math/copysign"><code>copysignf</code></a> </td> <td> <a href="math/copysign" title="c/numeric/math/copysign"><code>copysign</code></a> </td> <td> <a href="math/copysign" title="c/numeric/math/copysign"><code>copysignl</code></a> </td>
+</tr> <tr> <th> erf </th> <td> <a href="math/erf" title="c/numeric/math/erf"><code>erff</code></a> </td> <td> <a href="math/erf" title="c/numeric/math/erf"><code>erf</code></a> </td> <td> <a href="math/erf" title="c/numeric/math/erf"><code>erfl</code></a> </td>
+</tr> <tr> <th> erfc </th> <td> <a href="math/erfc" title="c/numeric/math/erfc"><code>erfcf</code></a> </td> <td> <a href="math/erfc" title="c/numeric/math/erfc"><code>erfc</code></a> </td> <td> <a href="math/erfc" title="c/numeric/math/erfc"><code>erfcl</code></a> </td>
+</tr> <tr> <th> exp2 </th> <td> <a href="math/exp2" title="c/numeric/math/exp2"><code>exp2f</code></a> </td> <td> <a href="math/exp2" title="c/numeric/math/exp2"><code>exp2</code></a> </td> <td> <a href="math/exp2" title="c/numeric/math/exp2"><code>exp2l</code></a> </td>
+</tr> <tr> <th> expm1 </th> <td> <a href="math/expm1" title="c/numeric/math/expm1"><code>expm1f</code></a> </td> <td> <a href="math/expm1" title="c/numeric/math/expm1"><code>expm1</code></a> </td> <td> <a href="math/expm1" title="c/numeric/math/expm1"><code>expm1l</code></a> </td>
+</tr> <tr> <th> fdim </th> <td> <a href="math/fdim" title="c/numeric/math/fdim"><code>fdimf</code></a> </td> <td> <a href="math/fdim" title="c/numeric/math/fdim"><code>fdim</code></a> </td> <td> <a href="math/fdim" title="c/numeric/math/fdim"><code>fdiml</code></a> </td>
+</tr> <tr> <th> floor </th> <td> <a href="math/floor" title="c/numeric/math/floor"><code>floorf</code></a> </td> <td> <a href="math/floor" title="c/numeric/math/floor"><code>floor</code></a> </td> <td> <a href="math/floor" title="c/numeric/math/floor"><code>floorl</code></a> </td>
+</tr> <tr> <th> fma </th> <td> <a href="math/fma" title="c/numeric/math/fma"><code>fmaf</code></a> </td> <td> <a href="math/fma" title="c/numeric/math/fma"><code>fma</code></a> </td> <td> <a href="math/fma" title="c/numeric/math/fma"><code>fmal</code></a> </td>
+</tr> <tr> <th> fmax </th> <td> <a href="math/fmax" title="c/numeric/math/fmax"><code>fmaxf</code></a> </td> <td> <a href="math/fmax" title="c/numeric/math/fmax"><code>fmax</code></a> </td> <td> <a href="math/fmax" title="c/numeric/math/fmax"><code>fmaxl</code></a> </td>
+</tr> <tr> <th> fmin </th> <td> <a href="math/fmin" title="c/numeric/math/fmin"><code>fminf</code></a> </td> <td> <a href="math/fmin" title="c/numeric/math/fmin"><code>fmin</code></a> </td> <td> <a href="math/fmin" title="c/numeric/math/fmin"><code>fminl</code></a> </td>
+</tr> <tr> <th> fmod </th> <td> <a href="math/fmod" title="c/numeric/math/fmod"><code>fmodf</code></a> </td> <td> <a href="math/fmod" title="c/numeric/math/fmod"><code>fmod</code></a> </td> <td> <a href="math/fmod" title="c/numeric/math/fmod"><code>fmodl</code></a> </td>
+</tr> <tr> <th> frexp </th> <td> <a href="math/frexp" title="c/numeric/math/frexp"><code>frexpf</code></a> </td> <td> <a href="math/frexp" title="c/numeric/math/frexp"><code>frexp</code></a> </td> <td> <a href="math/frexp" title="c/numeric/math/frexp"><code>frexpl</code></a> </td>
+</tr> <tr> <th> hypot </th> <td> <a href="math/hypot" title="c/numeric/math/hypot"><code>hypotf</code></a> </td> <td> <a href="math/hypot" title="c/numeric/math/hypot"><code>hypot</code></a> </td> <td> <a href="math/hypot" title="c/numeric/math/hypot"><code>hypotl</code></a> </td>
+</tr> <tr> <th> ilogb </th> <td> <a href="math/ilogb" title="c/numeric/math/ilogb"><code>ilogbf</code></a> </td> <td> <a href="math/ilogb" title="c/numeric/math/ilogb"><code>ilogb</code></a> </td> <td> <a href="math/ilogb" title="c/numeric/math/ilogb"><code>ilogbl</code></a> </td>
+</tr> <tr> <th> ldexp </th> <td> <a href="math/ldexp" title="c/numeric/math/ldexp"><code>ldexpf</code></a> </td> <td> <a href="math/ldexp" title="c/numeric/math/ldexp"><code>ldexp</code></a> </td> <td> <a href="math/ldexp" title="c/numeric/math/ldexp"><code>ldexpl</code></a> </td>
+</tr> <tr> <th> lgamma </th> <td> <a href="math/lgamma" title="c/numeric/math/lgamma"><code>lgammaf</code></a> </td> <td> <a href="math/lgamma" title="c/numeric/math/lgamma"><code>lgamma</code></a> </td> <td> <a href="math/lgamma" title="c/numeric/math/lgamma"><code>lgammal</code></a> </td>
+</tr> <tr> <th> llrint </th> <td> <a href="math/rint" title="c/numeric/math/rint"><code>llrintf</code></a> </td> <td> <a href="math/rint" title="c/numeric/math/rint"><code>llrint</code></a> </td> <td> <a href="math/rint" title="c/numeric/math/rint"><code>llrintl</code></a> </td>
+</tr> <tr> <th> llround </th> <td> <a href="math/round" title="c/numeric/math/round"><code>llroundf</code></a> </td> <td> <a href="math/round" title="c/numeric/math/round"><code>llround</code></a> </td> <td> <a href="math/round" title="c/numeric/math/round"><code>llroundl</code></a> </td>
+</tr> <tr> <th> log10 </th> <td> <a href="math/log10" title="c/numeric/math/log10"><code>log10f</code></a> </td> <td> <a href="math/log10" title="c/numeric/math/log10"><code>log10</code></a> </td> <td> <a href="math/log10" title="c/numeric/math/log10"><code>log10l</code></a> </td>
+</tr> <tr> <th> log1p </th> <td> <a href="math/log1p" title="c/numeric/math/log1p"><code>log1pf</code></a> </td> <td> <a href="math/log1p" title="c/numeric/math/log1p"><code>log1p</code></a> </td> <td> <a href="math/log1p" title="c/numeric/math/log1p"><code>log1pl</code></a> </td>
+</tr> <tr> <th> log2 </th> <td> <a href="math/log2" title="c/numeric/math/log2"><code>log2f</code></a> </td> <td> <a href="math/log2" title="c/numeric/math/log2"><code>log2</code></a> </td> <td> <a href="math/log2" title="c/numeric/math/log2"><code>log2l</code></a> </td>
+</tr> <tr> <th> logb </th> <td> <a href="math/logb" title="c/numeric/math/logb"><code>logbf</code></a> </td> <td> <a href="math/logb" title="c/numeric/math/logb"><code>logb</code></a> </td> <td> <a href="math/logb" title="c/numeric/math/logb"><code>logbl</code></a> </td>
+</tr> <tr> <th> lrint </th> <td> <a href="math/rint" title="c/numeric/math/rint"><code>lrintf</code></a> </td> <td> <a href="math/rint" title="c/numeric/math/rint"><code>lrint</code></a> </td> <td> <a href="math/rint" title="c/numeric/math/rint"><code>lrintl</code></a> </td>
+</tr> <tr> <th> lround </th> <td> <a href="math/round" title="c/numeric/math/round"><code>lroundf</code></a> </td> <td> <a href="math/round" title="c/numeric/math/round"><code>lround</code></a> </td> <td> <a href="math/round" title="c/numeric/math/round"><code>lroundl</code></a> </td>
+</tr> <tr> <th> nearbyint </th> <td> <a href="math/nearbyint" title="c/numeric/math/nearbyint"><code>nearbyintf</code></a> </td> <td> <a href="math/nearbyint" title="c/numeric/math/nearbyint"><code>nearbyint</code></a> </td> <td> <a href="math/nearbyint" title="c/numeric/math/nearbyint"><code>nearbyintl</code></a> </td>
+</tr> <tr> <th> nextafter </th> <td> <a href="math/nextafter" title="c/numeric/math/nextafter"><code>nextafterf</code></a> </td> <td> <a href="math/nextafter" title="c/numeric/math/nextafter"><code>nextafter</code></a> </td> <td> <a href="math/nextafter" title="c/numeric/math/nextafter"><code>nextafterl</code></a> </td>
+</tr> <tr> <th> nexttoward </th> <td> <a href="math/nextafter" title="c/numeric/math/nextafter"><code>nexttowardf</code></a> </td> <td> <a href="math/nextafter" title="c/numeric/math/nextafter"><code>nexttoward</code></a> </td> <td> <a href="math/nextafter" title="c/numeric/math/nextafter"><code>nexttowardl</code></a> </td>
+</tr> <tr> <th> remainder </th> <td> <a href="math/remainder" title="c/numeric/math/remainder"><code>remainderf</code></a> </td> <td> <a href="math/remainder" title="c/numeric/math/remainder"><code>remainder</code></a> </td> <td> <a href="math/remainder" title="c/numeric/math/remainder"><code>remainderl</code></a> </td>
+</tr> <tr> <th> remquo </th> <td> <a href="math/remquo" title="c/numeric/math/remquo"><code>remquof</code></a> </td> <td> <a href="math/remquo" title="c/numeric/math/remquo"><code>remquo</code></a> </td> <td> <a href="math/remquo" title="c/numeric/math/remquo"><code>remquol</code></a> </td>
+</tr> <tr> <th> rint </th> <td> <a href="math/rint" title="c/numeric/math/rint"><code>rintf</code></a> </td> <td> <a href="math/rint" title="c/numeric/math/rint"><code>rint</code></a> </td> <td> <a href="math/rint" title="c/numeric/math/rint"><code>rintl</code></a> </td>
+</tr> <tr> <th> round </th> <td> <a href="math/round" title="c/numeric/math/round"><code>roundf</code></a> </td> <td> <a href="math/round" title="c/numeric/math/round"><code>round</code></a> </td> <td> <a href="math/round" title="c/numeric/math/round"><code>roundl</code></a> </td>
+</tr> <tr> <th> scalbln </th> <td> <a href="math/scalbn" title="c/numeric/math/scalbn"><code>scalblnf</code></a> </td> <td> <a href="math/scalbn" title="c/numeric/math/scalbn"><code>scalbln</code></a> </td> <td> <a href="math/scalbn" title="c/numeric/math/scalbn"><code>scalblnl</code></a> </td>
+</tr> <tr> <th> scalbn </th> <td> <a href="math/scalbn" title="c/numeric/math/scalbn"><code>scalbnf</code></a> </td> <td> <a href="math/scalbn" title="c/numeric/math/scalbn"><code>scalbn</code></a> </td> <td> <a href="math/scalbn" title="c/numeric/math/scalbn"><code>scalbnl</code></a> </td>
+</tr> <tr> <th> tgamma </th> <td> <a href="math/tgamma" title="c/numeric/math/tgamma"><code>tgammaf</code></a> </td> <td> <a href="math/tgamma" title="c/numeric/math/tgamma"><code>tgamma</code></a> </td> <td> <a href="math/tgamma" title="c/numeric/math/tgamma"><code>tgammal</code></a> </td>
+</tr> <tr> <th> trunc </th> <td> <a href="math/trunc" title="c/numeric/math/trunc"><code>truncf</code></a> </td> <td> <a href="math/trunc" title="c/numeric/math/trunc"><code>trunc</code></a> </td> <td> <a href="math/trunc" title="c/numeric/math/trunc"><code>truncl</code></a> </td>
+</tr>
+</table> <h3 id="Complex-only_functions"> Complex-only functions</h3> <p>For all complex number functions that do not have real counterparts, a type-generic macro <code>cXXX</code> exists, which calls either of the variants of a complex function:</p>
+<ul>
+<li> <code><span class="kw4">float</span> <a href="http://en.cppreference.com/w/c/numeric/complex/complex"><span class="kw743">complex</span></a></code> variant <code>cXXXf</code> </li>
+<li> <code><span class="kw4">double</span> <a href="http://en.cppreference.com/w/c/numeric/complex/complex"><span class="kw743">complex</span></a></code> variant <code>cXXX</code> </li>
+<li> <code><span class="kw4">long</span> <span class="kw4">double</span> <a href="http://en.cppreference.com/w/c/numeric/complex/complex"><span class="kw743">complex</span></a></code> variant <code>cXXXl</code> </li>
+</ul> <p>The function to call is determined as follows:</p>
+<ul><li> If any of the arguments for the generic parameters is real, complex, or imaginary, then the appropriate complex function is called. </li></ul> <table class="wikitable"> <tr> <th> Type-generic macro </th> <th colspan="3"> Complex function <br> variants </th>
+</tr> <tr> <th> </th> <th> <div><code>float</code></div> </th> <th> <div><code>double</code></div> </th> <th> <div><code>long double</code></div> </th>
+</tr> <tr> <th> carg </th> <td> <a href="complex/carg" title="c/numeric/complex/carg"><code>cargf</code></a> </td> <td> <a href="complex/carg" title="c/numeric/complex/carg"><code>carg</code></a> </td> <td> <a href="complex/carg" title="c/numeric/complex/carg"><code>cargl</code></a> </td>
+</tr> <tr> <th> conj </th> <td> <a href="complex/conj" title="c/numeric/complex/conj"><code>conjf</code></a> </td> <td> <a href="complex/conj" title="c/numeric/complex/conj"><code>conj</code></a> </td> <td> <a href="complex/conj" title="c/numeric/complex/conj"><code>conjl</code></a> </td>
+</tr> <tr> <th> creal </th> <td> <a href="complex/creal" title="c/numeric/complex/creal"><code>crealf</code></a> </td> <td> <a href="complex/creal" title="c/numeric/complex/creal"><code>creal</code></a> </td> <td> <a href="complex/creal" title="c/numeric/complex/creal"><code>creall</code></a> </td>
+</tr> <tr> <th> cimag </th> <td> <a href="complex/cimag" title="c/numeric/complex/cimag"><code>cimagf</code></a> </td> <td> <a href="complex/cimag" title="c/numeric/complex/cimag"><code>cimag</code></a> </td> <td> <a href="complex/cimag" title="c/numeric/complex/cimag"><code>cimagl</code></a> </td>
+</tr> <tr> <th> cproj </th> <td> <a href="complex/cproj" title="c/numeric/complex/cproj"><code>cprojf</code></a> </td> <td> <a href="complex/cproj" title="c/numeric/complex/cproj"><code>cproj</code></a> </td> <td> <a href="complex/cproj" title="c/numeric/complex/cproj"><code>cprojl</code></a> </td>
+</tr>
+</table> <h3 id="Example"> Example </h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include &lt;stdio.h&gt;
+#include &lt;tgmath.h&gt;
+
+int main(void)
+{
+ int i = 2;
+ printf("sqrt(2) = %f\n", sqrt(i)); // argument type is int, calls sqrt
+
+ float f = 0.5;
+ printf("sin(0.5f) = %f\n", sin(f)); // argument type is float, calls sinf
+
+ float complex dc = 1 + 0.5*I;
+ float complex z = sqrt(dc); // argument type is float complex, calls csqrtf
+ printf("sqrt(1 + 0.5i) = %f+%fi\n",
+ creal(z), // argument type is float complex, calls crealf
+ cimag(z)); // argument type is float complex, calls cimagf
+}</pre></div> <p>Output:</p>
+<div class="text source-text"><pre data-language="c">sqrt(2) = 1.414214
+sin(0.5f) = 0.479426
+sqrt(1 + 0.5i) = 1.029086+0.242934i</pre></div> </div> <h3 id="References"> References</h3> <ul>
+<li> C17 standard (ISO/IEC 9899:2018): </li>
+<ul><li> 7.25 Type-generic math &lt;tgmath.h&gt; (p: 272-273) </li></ul>
+<li> C11 standard (ISO/IEC 9899:2011): </li>
+<ul><li> 7.25 Type-generic math &lt;tgmath.h&gt; (p: 373-375) </li></ul>
+<li> C99 standard (ISO/IEC 9899:1999): </li>
+<ul><li> 7.22 Type-generic math &lt;tgmath.h&gt; (p: 335-337) </li></ul>
+</ul> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
+ <a href="https://en.cppreference.com/w/c/numeric/tgmath" class="_attribution-link">https://en.cppreference.com/w/c/numeric/tgmath</a>
+ </p>
+</div>