函式
<cmath> <ctgmath>

acos

double acos (double x);
     double acos  (double x);      float acosf (float x);long double acosl (long double x);
     double acos (double x);      float acos (float x);long double acos (long double x);
     double acos (double x);      float acos (float x);long double acos (long double x);     double acos (T x);          // additional overloads for integral types
計算反餘弦
返回 x 的反餘弦主值,以弧度表示。

在三角學中,反餘弦餘弦的逆運算。

標頭檔案 <tgmath.h> 提供了此函式的型別通用宏版本。
此函式在 <valarray> 中被過載(參見 valarray acos)。
此標頭檔案 (<cmath>) 中為整數型別提供了額外的過載:這些過載在計算前有效地將 x 轉換為 double(為任意整數型別 T 定義)。

此函式也在 <complex><valarray> 中被過載(參見 complex acosvalarray acos)。

引數

x
計算其反餘弦的值,區間為 [-1,+1]
如果引數超出此區間,則會發生定義域錯誤

返回值

x 的反餘弦主值,在區間 [0,pi] 弧度內。
弧度等於 180/PI

如果發生定義域錯誤,全域性變數 errno 會被設定為 EDOM
如果發生定義域錯誤
- 並且 math_errhandling 設定了 MATH_ERRNO:全域性變數 errno 會被設定為 EDOM
- 並且 math_errhandling 設定了 MATH_ERREXCEPT:將引發 FE_INVALID

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* acos example */
#include <stdio.h>      /* printf */
#include <math.h>       /* acos */

#define PI 3.14159265

int main ()
{
  double param, result;
  param = 0.5;
  result = acos (param) * 180.0 / PI;
  printf ("The arc cosine of %f is %f degrees.\n", param, result);
  return 0;
}

輸出

The arc cosine of 0.500000 is 60.000000 degrees.


另見