English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The acos() function returns the arccosine value represented by a number in radians.
The acos() function takes a single parameter (1≥x≥-1)and returns the arccosine value in radians.
The acos() function is included in the <math.h> header file.
double acos(double x);
To find the inverse cosine for types int, float, or long double, you can use the type cast operator to explicitly convert the type to double.
int x = 0; double result; result = acos(double(x));
Additionally, C99Two functions acosf() and acosl() were introduced in C
float acosf(float x); long double acosl(long double x);
The acos() function uses [-1,+1This is because the cosine value is1] range.-1to
Parameter | Description |
---|---|
double value | is required. A single parameter within-1and+1between the double precision values. |
The acos() function returns a value in the range [0.0, π] in radians units. If the parameter passed to the acos() function is less than-1or greater1If the parameter is less than or greater than
Parameter (x) | Return value |
---|---|
x = [-1, +1] | Radians are in the range [0, π] |
-1 > x or x > 1 | NaN (Not a Number) |
#include <stdio.h> #include <math.h> int main() { //Defined constant PI const double PI = 3.1415926; double x, result; x = -0.5; result = acos(x); printf("cos(%.2f) Inverse cosine value = %.2lf radians\n", x, result); //Convert radians to degrees result = acos(x)*180/PI; printf("cos(%.2f) Inverse cosine value = %.2lf degree\n", x, result); //Parameter is out of range x = 1.2; result = acos(x); printf("Inverse of cos(%.2f) = %.2lf", x, result); return 0; {}
Output Result
cos(-0.50) Inverse cosine value = 2.09 radians cos(-0.50) Inverse cosine value = 120.00 degrees cos(1.20) Inverse cosine value = nan
#include <stdio.h> #include <math.h> int main() { float fx, facosx; long double lx, ldacosx; //Floating point inverse cosine fx = -0.505405; facosx = acosf(fx); //Long double type inverse cosine lx = -0.50540593; ldacosx = acosf(lx); printf("acosf(x) = %f radians\n", facosx); printf("acosl(x) = %Lf radians", ldacosx); return 0; {}
Output Result
acosf(x) = 2.100648 radians acosl(x) = 2.100649 radians