cospi, cospif, cospil, cospid32, cospid64, cospid128
Von cppreference.com
| Definiert in Header <math.h> |
||
| float cospif( float arg ); |
(1) | (seit C23) |
| double cospi( double arg ); |
(2) | (seit C23) |
| long double cospil( long double arg ); |
(3) | (seit C23) |
| _Decimal32 cospid32( _Decimal32 arg ); |
(4) | (seit C23) |
| _Decimal64 cospid64( _Decimal64 arg ); |
(5) | (seit C23) |
| _Decimal128 cospid128( _Decimal128 arg ); |
(6) | (seit C23) |
| Definiert in Header <tgmath.h> |
||
| #define cospi( arg ) |
(7) | (seit C23) |
1-6) Berechnet den Kosinus von
π·arg, gemessen in Radiant, und betrachtet somit arg als Messung in halben Umdrehungen.7) Typ-generische Makrofunktion: Ruft die passende Funktion basierend auf dem Typ von arg auf. Wenn das Argument einen ganzzahligen Typ hat, wird (2) (
cospi) aufgerufen.|
Die Funktionen (4-6) werden nur dann deklariert, wenn die Implementierung |
(seit C23) |
Inhalt |
[edit] Parameter
| arg | - | Gleitkommazahl, deren Produkt mit π einen Winkel in Radiant darstellt |
[edit] Rückgabewert
Wenn keine Fehler auftreten, wird der Kosinus von π·arg (cos(π×arg)) im Bereich [-1, +1] zurückgegeben.
[edit] Fehlerbehandlung
Fehler werden wie in math_errhandling angegeben gemeldet.
Wenn die Implementierung IEEE-Gleitkomma-Arithmetik (IEC 60559) unterstützt
- Wenn das Argument ±0 ist, ist das Ergebnis 1.0;
- wenn das Argument ±∞ ist, wird NaN zurückgegeben und FE_INVALID ausgelöst;
- Wenn das Argument NaN ist, wird NaN zurückgegeben.
[edit] Beispiel
Führen Sie diesen Code aus
#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"); }
Mögliche Ausgabe
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[edit] Referenzen
- C23-Standard (ISO/IEC 9899:2024)
- 7.12.4.12 Die cospi-Funktionen (S. 247)
- 7.27 Typ-generische Mathematik <tgmath.h> (S. 387)
[edit] Siehe auch
| (C99)(C99) |
berechnet Kosinus (cos(x)) (Funktion) |