Funkcja acos () w C ++ zwraca odwrotny cosinus liczby (argumentu) w radianach.
Ta funkcja jest zdefiniowana w pliku nagłówkowym.
(Matematyka) cos -1 x = acos (x) (W programowaniu w C ++);
acos () prototyp (w standardzie C ++ 11)
podwójne acos (podwójne x); float acos (float x); długie podwójne acos (długie podwójne x); podwójne acos (T x); // Dla typu całkowitego
acos () Parametry
Funkcja acos () przyjmuje jeden obowiązkowy argument z zakresu (-1, 1) . Dzieje się tak, ponieważ wartość cosinusa mieści się w przedziale od 1 do -1.
acos () Wartość zwracana
Biorąc pod uwagę, że argument należy do zakresu (-1, 1) , funkcja acos () zwraca wartość z zakresu (0, π).
Jeśli argument jest większy niż 1 lub mniejszy niż -1, acos () zwraca NaN
tj. Nie jest liczbą.
Parametr (x) | Wartość zwracana |
---|---|
x = (-1, 1) | (0, π) w radianach |
-1> x lub x> 1 | NaN (nie jest liczbą) |
Przykład 1: Jak działa acos ()?
#include #include using namespace std; int main() ( double x = 0.0, result; result = acos(x); cout << "acos(x) = " << result << " radians" << endl; // result in degrees cout << "acos(x) = " << result*180/3.1415 << " degrees" << endl; return 0; )
Po uruchomieniu programu wynik będzie następujący:
acos (x) = 1,5708 radianów acos (x) = 90,0027 stopni
Przykład 2: funkcja acos () z typem całkowitym
#include #include using namespace std; int main() ( int x = -1; double result; result = acos(x); cout << "acos(x) = " << result << " radians" << endl; // Converting result to degrees cout << "acos(x) = " << result*180/3.1415 << " degrees"; return 0; )
Po uruchomieniu programu wynik będzie następujący:
acos (x) = 3,14159 radianów acos (x) = 180,005 stopni