diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/numeric%2Fmath%2Fmodf.html | |
new repository
Diffstat (limited to 'devdocs/c/numeric%2Fmath%2Fmodf.html')
| -rw-r--r-- | devdocs/c/numeric%2Fmath%2Fmodf.html | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/devdocs/c/numeric%2Fmath%2Fmodf.html b/devdocs/c/numeric%2Fmath%2Fmodf.html new file mode 100644 index 00000000..7ee360cd --- /dev/null +++ b/devdocs/c/numeric%2Fmath%2Fmodf.html @@ -0,0 +1,78 @@ + <h1 id="firstHeading" class="firstHeading">modf, modff, modfl</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><math.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">float modff( float arg, float* iptr );</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 modf( double arg, double* iptr );</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 modfl( long double arg, long double* iptr );</pre> +</td> <td> (3) </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> Decomposes given floating point value <code>arg</code> into integral and fractional parts, each having the same type and sign as <code>arg</code>. The integral part (in floating-point format) is stored in the object pointed to by <code>iptr</code>.</div> <h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> arg </td> <td> - </td> <td> floating point value </td> +</tr> <tr class="t-par"> <td> iptr </td> <td> - </td> <td> pointer to floating point value to store the integral part to </td> +</tr> +</table> <h3 id="Return_value"> Return value</h3> <p>If no errors occur, returns the fractional part of <code>x</code> with the same sign as <code>x</code>. The integral part is put into the value pointed to by <code>iptr</code>.</p> +<p>The sum of the returned value and the value stored in <code>*iptr</code> gives <code>arg</code> (allowing for rounding).</p> +<h3 id="Error_handling"> Error handling</h3> <p>This function is not subject to any errors specified in <a href="math_errhandling" title="c/numeric/math/math errhandling">math_errhandling</a>.</p> +<p>If the implementation supports IEEE floating-point arithmetic (IEC 60559),</p> +<ul> +<li> If <code>arg</code> is ±0, ±0 is returned, and ±0 is stored in <code>*iptr</code>. </li> +<li> If <code>arg</code> is ±∞, ±0 is returned, and ±∞ is stored in <code>*iptr</code>. </li> +<li> If <code>arg</code> is NaN, NaN is returned, and NaN is stored in <code>*iptr</code>. </li> +<li> The returned value is exact, <a href="../fenv/fe_round" title="c/numeric/fenv/FE round">the current rounding mode</a> is ignored </li> +</ul> <h3 id="Notes"> Notes</h3> <p>This function behaves as if implemented as follows:</p> +<div class="c source-c"><pre data-language="c">double modf(double value, double *iptr) +{ +#pragma STDC FENV_ACCESS ON + int save_round = fegetround(); + fesetround(FE_TOWARDZERO); + *iptr = std::nearbyint(value); + fesetround(save_round); + return copysign(isinf(value) ? 0.0 : value - (*iptr), value); +}</pre></div> <h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdio.h> +#include <math.h> +#include <float.h> + +int main(void) +{ + double f = 123.45; + printf("Given the number %.2f or %a in hex,\n", f, f); + + double f3; + double f2 = modf(f, &f3); + printf("modf() makes %.2f + %.2f\n", f3, f2); + + int i; + f2 = frexp(f, &i); + printf("frexp() makes %f * 2^%d\n", f2, i); + + i = ilogb(f); + printf("logb()/ilogb() make %f * %d^%d\n", f/scalbn(1.0, i), FLT_RADIX, i); + + // special values + f2 = modf(-0.0, &f3); + printf("modf(-0) makes %.2f + %.2f\n", f3, f2); + f2 = modf(-INFINITY, &f3); + printf("modf(-Inf) makes %.2f + %.2f\n", f3, f2); +}</pre></div> <p>Possible output:</p> +<div class="text source-text"><pre data-language="c">Given the number 123.45 or 0x1.edccccccccccdp+6 in hex, +modf() makes 123.00 + 0.45 +frexp() makes 0.964453 * 2^7 +logb()/ilogb() make 1.92891 * 2^6 +modf(-0) makes -0.00 + -0.00 +modf(-Inf) makes -INF + -0.00</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul> +<li> 7.12.6.12 The modf functions (p: 246-247) </li> +<li> F.10.3.12 The modf functions (p: 523) </li> +</ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul> +<li> 7.12.6.12 The modf functions (p: 227) </li> +<li> F.9.3.12 The modf functions (p: 460) </li> +</ul> +<li> C89/C90 standard (ISO/IEC 9899:1990): </li> +<ul><li> 4.5.4.6 The modf function </li></ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="trunc" title="c/numeric/math/trunc"> <span class="t-lines"><span>trunc</span><span>truncf</span><span>truncl</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> rounds to nearest integer not greater in magnitude than the given value <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/modf" title="cpp/numeric/math/modf">C++ documentation</a></span> for <code>modf</code> </td> +</tr> </table> <div class="_attribution"> + <p class="_attribution-p"> + © 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/modf" class="_attribution-link">https://en.cppreference.com/w/c/numeric/math/modf</a> + </p> +</div> |
