diff options
Diffstat (limited to 'devdocs/c/numeric%2Fmath%2Fcospi.html')
| -rw-r--r-- | devdocs/c/numeric%2Fmath%2Fcospi.html | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/devdocs/c/numeric%2Fmath%2Fcospi.html b/devdocs/c/numeric%2Fmath%2Fcospi.html new file mode 100644 index 00000000..f260c5fb --- /dev/null +++ b/devdocs/c/numeric%2Fmath%2Fcospi.html @@ -0,0 +1,77 @@ + <h1 id="firstHeading" class="firstHeading">cospi, cospif, cospil, cospid32, cospid64, cospid128</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-c23"> <td> <pre data-language="c">float cospif( float arg );</pre> +</td> <td> (1) </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">double cospi( double arg );</pre> +</td> <td> (2) </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">long double cospil( long double arg );</pre> +</td> <td> (3) </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">_Decimal32 cospid32( _Decimal32 arg );</pre> +</td> <td> (4) </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">_Decimal64 cospid64( _Decimal64 arg );</pre> +</td> <td> (5) </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">_Decimal128 cospid128( _Decimal128 arg );</pre> +</td> <td> (6) </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> <tr class="t-dsc-header"> <th> Defined in header <code><tgmath.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">#define cospi( arg )</pre> +</td> <td> (7) </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> </table> <div class="t-li1"> +<span class="t-li">1-6)</span> Computes the cosine of <code>π·arg</code> measured in radians, thus regarding <code>arg</code> as a measurement in half-revolutions.</div> <div class="t-li1"> +<span class="t-li">7)</span> Type-generic macro: calls the correct function based on the type of <code>arg</code>. If the argument has integer type, <span class="t-v">(2)</span> (<code>cospi</code>) is called.</div> <table class="t-rev-begin"> <tr class="t-rev t-since-c23"> +<td> <p>The functions <span class="t-v">(4-6)</span> are declared if and only if the implementation predefines <code>__STDC_IEC_60559_DFP__</code> (i.e. the implementation supports decimal floating-point numbers).</p> +</td> <td><span class="t-mark-rev t-since-c23">(since C23)</span></td> +</tr> </table> <h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> arg </td> <td> - </td> <td> floating-point value whose product with <code>π</code> represents an angle in radians </td> +</tr> +</table> <h3 id="Return_value"> Return value</h3> <p>If no errors occur, the cosine of <code>π·arg</code> (cos(π×arg)) in the range [-1, +1], 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"><code>math_errhandling</code></a>.</p> +<p>If the implementation supports IEEE floating-point arithmetic (IEC 60559):</p> +<ul> +<li> if the argument is ±0, the result is <code>1.0</code>; </li> +<li> if the argument is ±∞, 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 the argument is NaN, NaN is returned. </li> +</ul> <h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <errno.h> +#include <fenv.h> +#include <math.h> +#include <stdio.h> + +#ifndef __GNUC__ +#pragma STDC FENV_ACCESS ON +#endif + +#if __STDC_VERSION__ < 202311L +// A naive implementation of a subset of cospi family +double cospi(double arg) +{ + return cos(arg * (double)3.1415926535897932384626433); +} +#endif + +int main(void) +{ + const double pi = acos(-1); + + // typical usage + printf("cospi(1) = %f, cos(pi) = %f\n", cospi(1), cos(pi)); + printf("cospi(0.5) = %f, cos(pi/2) = %f\n", cospi(0.5), cos(pi / 2)); + printf("cospi(-0.75) = %f, cos(-3*pi/4) = %f\n", cospi(-0.75), cos(-3 * pi / 4)); + + // special values + printf("cospi(+0) = %f\n", cospi(0.0)); + printf("cospi(-0) = %f\n", cospi(-0.0)); + + // error handling + feclearexcept(FE_ALL_EXCEPT); + printf("cospi(INFINITY) = %f\n", cospi(INFINITY)); + if (fetestexcept(FE_INVALID)) + puts(" FE_INVALID raised"); +}</pre></div> <p>Possible output:</p> +<div class="text source-text"><pre data-language="c">cospi(1) = -1.000000, cos(pi) = -1.000000 +cospi(0.5) = 0.000000, cos(pi/2) = 0.000000 +cospi(-0.75) = -0.707107, cos(-3*pi/4) = -0.707107 +cospi(+0) = 1.000000 +cospi(-0) = 1.000000 +cospi(INFINITY) = -nan + FE_INVALID raised</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C23 standard (ISO/IEC 9899:2023): </li> +<ul> +<li> 7.12.4.12 The cospi functions (p: 247) </li> +<li> 7.27 Type generic math <tgmath.h> (p: 387) </li> +</ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="cos" title="c/numeric/math/cos"> <span class="t-lines"><span>cos</span><span>cosf</span><span>cosl</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></div> </td> <td> computes cosine (\({\small\cos{x} }\)cos(x)) <br> <span class="t-mark">(function)</span> </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/cospi" class="_attribution-link">https://en.cppreference.com/w/c/numeric/math/cospi</a> + </p> +</div> |
