cospi, cospif, cospil, cospid32, cospid64, cospid128
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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) |
π·arg
gemessen in Radiant, wodurch
arg
als Messung in Halbdrehungen betrachtet wird.
cospi
) wird aufgerufen.
|
Die Funktionen
(4-6)
werden genau dann deklariert, wenn die Implementierung
|
(seit C23) |
Inhaltsverzeichnis |
Parameter
| arg | - |
Fließkommawert, dessen Produkt mit
π
einen Winkel im Bogenmaß darstellt
|
Rückgabewert
Wenn keine Fehler auftreten, wird der Kosinus von
π·arg
(
cos(π×arg)
) im Bereich
[-1, +1]
zurückgegeben.
Fehlerbehandlung
Fehler werden gemeldet, wie in
math_errhandling
festgelegt.
Wenn die Implementierung IEEE-Gleitkommaarithmetik (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.
Beispiel
#include <errno.h> #include <fenv.h> #include <math.h> #include <stdio.h> #ifndef __GNUC__ #pragma STDC FENV_ACCESS ON #endif #if __STDC_VERSION__ < 202311L // Eine naive Implementierung einer Teilmenge der cospi-Familie double cospi(double arg) { return cos(arg * (double)3.1415926535897932384626433); } #endif int main(void) { const double pi = acos(-1); // Typische Verwendung 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)); // Spezielle Werte printf("cospi(+0) = %f\n", cospi(0.0)); printf("cospi(-0) = %f\n", cospi(-0.0)); // Fehlerbehandlung 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
Referenzen
- C23-Standard (ISO/IEC 9899:2024):
-
- 7.12.4.12 The cospi functions (p: 247)
-
- 7.27 Type generic math <tgmath.h> (p: 387)
Siehe auch
|
(C99)
(C99)
|
berechnet Kosinus (
\({\small\cos{x} }\)
cos(x)
)
(Funktion) |