summaryrefslogtreecommitdiff
path: root/devdocs/c/numeric%2Fmath%2Ffmod.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/c/numeric%2Fmath%2Ffmod.html')
-rw-r--r--devdocs/c/numeric%2Fmath%2Ffmod.html95
1 files changed, 95 insertions, 0 deletions
diff --git a/devdocs/c/numeric%2Fmath%2Ffmod.html b/devdocs/c/numeric%2Fmath%2Ffmod.html
new file mode 100644
index 00000000..e43577a0
--- /dev/null
+++ b/devdocs/c/numeric%2Fmath%2Ffmod.html
@@ -0,0 +1,95 @@
+ <h1 id="firstHeading" class="firstHeading">fmod, fmodf, fmodl</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;math.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">float fmodf( float x, float y );</pre>
+</td> <td> (1) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dcl"> <td> <pre data-language="c">double fmod( double x, double y );</pre>
+</td> <td> (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">long double fmodl( long double x, long double y );</pre>
+</td> <td> (3) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;tgmath.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">#define fmod( x, y )</pre>
+</td> <td> (4) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> </table> <div class="t-li1">
+<span class="t-li">1-3)</span> Computes the floating-point remainder of the division operation <code>x/y</code>.</div> <div class="t-li1">
+<span class="t-li">4)</span> Type-generic macro: If any argument has type <code>long double</code>, <code>fmodl</code> is called. Otherwise, if any argument has integer type or has type <code>double</code>, <code>fmod</code> is called. Otherwise, <code>fmodf</code> is called.</div> <p>The floating-point remainder of the division operation <code>x/y</code> calculated by this function is exactly the value <code>x - n*y</code>, where <code>n</code> is <code>x/y</code> with its fractional part truncated.</p>
+<p>The returned value has the same sign as <code>x</code> and is less or equal to <code>y</code> in magnitude.</p>
+<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> x, y </td> <td> - </td> <td> floating point values </td>
+</tr>
+</table> <h3 id="Return_value"> Return value</h3> <p>If successful, returns the floating-point remainder of the division <code>x/y</code> as defined above.</p>
+<p>If a domain error occurs, an implementation-defined value is returned (NaN where supported).</p>
+<p>If a range error occurs due to underflow, the correct result (after rounding) is returned.</p>
+<h3 id="Error_handling"> Error handling</h3> <p>Errors are reported as specified in <a href="math_errhandling" title="c/numeric/math/math errhandling">math_errhandling</a>.</p>
+<p>Domain error may occur if <code>y</code> is zero.</p>
+<p>If the implementation supports IEEE floating-point arithmetic (IEC 60559),</p>
+<ul>
+<li> If <code>x</code> is ±0 and <code>y</code> is not zero, ±0 is returned </li>
+<li> If <code>x</code> is ±∞ and <code>y</code> is not NaN, NaN is returned and <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_INVALID</a></code> is raised </li>
+<li> If <code>y</code> is ±0 and <code>x</code> is not NaN, NaN is returned and <code><a href="../fenv/fe_exceptions" title="c/numeric/fenv/FE exceptions">FE_INVALID</a></code> is raised </li>
+<li> If <code>y</code> is ±∞ and <code>x</code> is finite, <code>x</code> is returned. </li>
+<li> If either argument is NaN, NaN is returned </li>
+</ul> <h3 id="Notes"> Notes</h3> <p><a rel="nofollow" class="external text" href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/fmod.html">POSIX requires</a> that a domain error occurs if <code>x</code> is infinite or <code>y</code> is zero.</p>
+<p><code>fmod</code>, but not <code><a href="remainder" title="c/numeric/math/remainder">remainder</a></code> is useful for doing silent wrapping of floating-point types to unsigned integer types: <code><span class="br0">(</span><span class="nu16">0.0</span> <span class="sy1">&lt;=</span> <span class="br0">(</span>y <span class="sy1">=</span> fmod<span class="br0">(</span><a href="http://en.cppreference.com/w/c/numeric/math/rint"><span class="kw692">rint</span></a><span class="br0">(</span>x<span class="br0">)</span>, <span class="nu16">65536.0</span> <span class="br0">)</span><span class="br0">)</span> <span class="sy4">?</span> y <span class="sy4">:</span> <span class="nu16">65536.0</span> <span class="sy2">+</span> y<span class="br0">)</span></code> is in the range <code>[-0.0 .. 65535.0]</code>, which corresponds to <code>unsigned short</code>, but <code><a href="http://en.cppreference.com/w/c/numeric/math/remainder"><span class="kw647">remainder</span></a><span class="br0">(</span><a href="http://en.cppreference.com/w/c/numeric/math/rint"><span class="kw692">rint</span></a><span class="br0">(</span>x<span class="br0">)</span>, <span class="nu16">65536.0</span><span class="br0">)</span></code> is in the range <code>[-32767.0, +32768.0]</code>, which is outside of the range of <code>signed short</code>.</p>
+<p>The <code>double</code> version of <code>fmod</code> behaves as if implemented as follows:</p>
+<div class="c source-c"><pre data-language="c">double fmod(double x, double y)
+{
+#pragma STDC FENV_ACCESS ON
+ double result = remainder(fabs(x), (y = fabs(y)));
+ if (signbit(result)) result += y;
+ return copysign(result, x);
+}</pre></div> <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;math.h&gt;
+#include &lt;fenv.h&gt;
+
+// #pragma STDC FENV_ACCESS ON
+int main(void)
+{
+ printf("fmod(+5.1, +3.0) = %.1f\n", fmod(5.1,3));
+ printf("fmod(-5.1, +3.0) = %.1f\n", fmod(-5.1,3));
+ printf("fmod(+5.1, -3.0) = %.1f\n", fmod(5.1,-3));
+ printf("fmod(-5.1, -3.0) = %.1f\n", fmod(-5.1,-3));
+
+ // special values
+ printf("fmod(+0.0, 1.0) = %.1f\n", fmod(0, 1));
+ printf("fmod(-0.0, 1.0) = %.1f\n", fmod(-0.0, 1));
+ printf("fmod(+5.1, Inf) = %.1f\n", fmod(5.1, INFINITY));
+
+ // error handling
+ feclearexcept(FE_ALL_EXCEPT);
+ printf("fmod(+5.1, 0) = %.1f\n", fmod(5.1, 0));
+ if(fetestexcept(FE_INVALID)) puts(" FE_INVALID raised");
+}</pre></div> <p>Possible output:</p>
+<div class="text source-text"><pre data-language="c">fmod(+5.1, +3.0) = 2.1
+fmod(-5.1, +3.0) = -2.1
+fmod(+5.1, -3.0) = 2.1
+fmod(-5.1, -3.0) = -2.1
+fmod(+0.0, 1.0) = 0.0
+fmod(-0.0, 1.0) = -0.0
+fmod(+5.1, Inf) = 5.1
+fmod(+5.1, 0) = nan
+ FE_INVALID raised</pre></div> </div> <h3 id="References"> References</h3> <ul>
+<li> C17 standard (ISO/IEC 9899:2018): </li>
+<ul>
+<li> 7.12.10.1 The fmod functions (p: 185) </li>
+<li> 7.25 Type-generic math &lt;tgmath.h&gt; (p: 274-275) </li>
+<li> F.10.7.1 The fmod functions (p: 385) </li>
+</ul>
+<li> C11 standard (ISO/IEC 9899:2011): </li>
+<ul>
+<li> 7.12.10.1 The fmod functions (p: 254) </li>
+<li> 7.25 Type-generic math &lt;tgmath.h&gt; (p: 373-375) </li>
+<li> F.10.7.1 The fmod functions (p: 528) </li>
+</ul>
+<li> C99 standard (ISO/IEC 9899:1999): </li>
+<ul>
+<li> 7.12.10.1 The fmod functions (p: 235) </li>
+<li> 7.22 Type-generic math &lt;tgmath.h&gt; (p: 335-337) </li>
+<li> F.9.7.1 The fmod functions (p: 465) </li>
+</ul>
+<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
+<ul><li> 4.5.6.4 The fmod function </li></ul>
+</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="div" title="c/numeric/math/div"> <span class="t-lines"><span>div</span><span>ldiv</span><span>lldiv</span></span></a></div>
+<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> computes quotient and remainder of integer division <br> <span class="t-mark">(function)</span> </td>
+</tr> <tr class="t-dsc"> <td> <div><a href="remainder" title="c/numeric/math/remainder"> <span class="t-lines"><span>remainder</span><span>remainderf</span><span>remainderl</span></span></a></div>
+<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> computes signed remainder of the floating-point division operation <br> <span class="t-mark">(function)</span> </td>
+</tr> <tr class="t-dsc"> <td> <div><a href="remquo" title="c/numeric/math/remquo"> <span class="t-lines"><span>remquo</span><span>remquof</span><span>remquol</span></span></a></div>
+<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> computes signed remainder as well as the three last bits of the division operation <br> <span class="t-mark">(function)</span> </td>
+</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/numeric/math/fmod" title="cpp/numeric/math/fmod">C++ documentation</a></span> for <code>fmod</code> </td>
+</tr> </table> <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/math/fmod" class="_attribution-link">https://en.cppreference.com/w/c/numeric/math/fmod</a>
+ </p>
+</div>