Die Funktion acos () gibt den Bogenkosinus (inversen Kosinus) einer Zahl im Bogenmaß zurück.
Die acos()
Funktion verwendet ein einzelnes Argument (1 ≧ x ≧ -1) und gibt den Bogenkosinus im Bogenmaß zurück.
Die acos()
Funktion ist in der Header-Datei enthalten.
acos () Prototyp
Doppel-Acos (Doppel-x);
Um Cosinus des Typs zu finden Bogen int
, float
oder long double
können Sie explizit den Typ konvertieren double
mit Cast - Operator.
int x = 0; doppeltes Ergebnis; Ergebnis = acos (doppelt (x));
Auch zwei Funktionen acosf () und acosl () wurden in C99 eingeführt spezifisch mit Typ zu arbeiten float
und long double
jeweils.
float acosf (float x); langes doppeltes Acosl (langes doppeltes x);
acos () Parameter
Die acos()
Funktion akzeptiert ein einzelnes Argument im Bereich von (-1, +1). Dies liegt daran, dass der Cosinuswert im Bereich von 1 bis -1 liegt.
Parameter | Beschreibung |
---|---|
doppelter Wert | Erforderlich. Ein doppelter Wert zwischen - 1 und +1 einschließlich. |
acos () Rückgabewert
Die acos()
Funktionen geben den Wert im Bereich von (0.0, π) im Bogenmaß zurück. Wenn der an die acos()
Funktion übergebene Parameter kleiner als -1 oder größer als 1 ist, gibt die Funktion NaN (keine Zahl) zurück.
Parameter (x) | Rückgabewert |
---|---|
x = (-1, +1) | (0, π) im Bogenmaß |
-1> x oder x> 1 | NaN (keine Zahl) |
Beispiel 1: acos () -Funktion mit verschiedenen Parametern
#include #include int main() ( // constant PI is defined const double PI = 3.1415926; double x, result; x = -0.5; result = acos(x); printf("Inverse of cos(%.2f) = %.2lf in radians", x, result); // converting radians to degree result = acos(x)*180/PI; printf("Inverse of cos(%.2f) = %.2lf in degrees", x, result); // paramter not in range x = 1.2; result = acos(x); printf("Inverse of cos(%.2f) = %.2lf", x, result); return 0; )
Ausgabe
Inverse von cos (-0,50) = 2,09 im Bogenmaß Inverse von cos (-0,50) = 120,00 in Grad Inverse von cos (1,20) = nan
Beispiel 2: acosf () und acosl () Funktion
#include #include int main() ( float fx, facosx; long double lx, ldacosx; // arc cosine of type float fx = -0.505405; facosx = acosf(fx); // arc cosine of type long double lx = -0.50540593; ldacosx = acosf(lx); printf("acosf(x) = %f in radians", facosx); printf("acosl(x) = %Lf in radians", ldacosx); return 0; )
Ausgabe
acosf (x) = 2.100648 im Bogenmaß acosl (x) = 2.100649 im Bogenmaß