名稱空間
變體
操作

acos、acosf、acosl

來自 cppreference.com
< c‎ | 數值‎ | 數學
 
 
 
常用數學函式
函式
基本操作
(C99)
(C99)
(C99)
(C99)(C99)(C99)(C23)
最大值/最小值操作
(C99)
(C99)
指數函式
(C23)
(C99)
(C99)
(C23)
(C23)

(C99)
(C99)(C23)
(C23)
(C23)
冪函式
(C99)
(C23)
(C23)

(C99)
(C23)
(C23)
三角函式和雙曲函式
acos
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
(C99)
(C99)
(C99)
最近整數浮點數
(C99)(C99)(C99)
(C99)

(C99)(C99)(C99)
(C23)(C23)(C23)(C23)
浮點數操作
(C99)(C99)
(C99)(C23)
(C99)
窄化操作
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
量子與量子指數
十進位制重新編碼函式
總序和載荷函式
分類
(C99)
(C99)
(C99)
(C23)
誤差函式和伽馬函式
(C99)
(C99)
(C99)
(C99)
型別
宏常量
特殊浮點值
(C99)(C23)
引數和返回值
錯誤處理
快速操作指示符
 
定義於標頭檔案 <math.h>
float       acosf( float arg );
(1) (C99 起)
double      acos( double arg );
(2)
long double acosl( long double arg );
(3) (C99 起)
_Decimal32  acosd32( _Decimal32 arg );
(4) (自 C23 起)
_Decimal64  acosd64( _Decimal64 arg );
(5) (自 C23 起)
_Decimal128 acosd128( _Decimal128 arg );
(6) (自 C23 起)
定義於標頭檔案 <tgmath.h>
#define acos( arg )
(7) (C99 起)
1-6) 計算 arg 的反餘弦主值。
7) 泛型宏:若實參型別為 long double,則呼叫 (3) (acosl)。否則,若實參為整數型別或型別為 double,則呼叫 (2) (acos)。否則,呼叫 (1) (acosf)。若實參為複數,則此宏呼叫對應的複數函式(cacosfcacoscacosl)。

函式 (4-6) 僅當實現預定義 __STDC_IEC_60559_DFP__(即實現支援十進位制浮點數)時才宣告。

(自 C23 起)

目錄

[編輯] 引數

arg - 浮點值

[編輯] 返回值

若無錯誤發生,返回 arg 的反餘弦(arccos(arg)),範圍為 [0 ; π]

如果發生域錯誤,則返回實現定義的值 (支援 NaN 時返回 NaN)。

如果因下溢發生範圍錯誤,則返回正確結果(舍入後)。

[編輯] 錯誤處理

錯誤按 math_errhandling 中指定的方式報告。

arg 在範圍 [-1.0; 1.0] 之外,則發生定義域錯誤。

如果實現支援 IEEE 浮點算術 (IEC 60559)

  • 若實參為 +1,返回 +0
  • |arg| > 1,發生定義域錯誤並返回 NaN;
  • 如果引數為 NaN,則返回 NaN。

[編輯] 示例

#include <errno.h>
#include <fenv.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
 
#ifndef __GNUC__
#pragma STDC FENV_ACCESS ON
#endif
 
int main(void)
{
    printf("acos(-1) = %f\n", acos(-1));
    printf("acos(0.0) = %f 2*acos(0.0) = %f\n", acos(0), 2 * acos(0));
    printf("acos(0.5) = %f 3*acos(0.5) = %f\n", acos(0.5), 3 * acos(0.5));
    printf("acos(1) = %f\n", acos(1));
 
    // error handling
    errno = 0; feclearexcept(FE_ALL_EXCEPT);
    printf("acos(1.1) = %f\n", acos(1.1));
    if (errno == EDOM)
        perror("    errno == EDOM");
    if (fetestexcept(FE_INVALID))
        puts("    FE_INVALID raised");
}

可能的輸出

acos(-1) = 3.141593
acos(0.0) = 1.570796 2*acos(0.0) = 3.141593
acos(0.5) = 1.047198 3*acos(0.5) = 3.141593
acos(1) = 0.000000
acos(1.1) = nan
    errno == EDOM: Numerical argument out of domain
    FE_INVALID raised

[編輯] 參考

  • C23 標準 (ISO/IEC 9899:2024)
  • 7.12.4.1 acos 函式 (p: TBD)
  • 7.25 型別通用數學 <tgmath.h> (p: TBD)
  • F.10.1.1 acos 函式 (p: TBD)
  • C17 標準 (ISO/IEC 9899:2018)
  • 7.12.4.1 acos 函式 (p: 173)
  • 7.25 型別通用數學 <tgmath.h> (p: 272-273)
  • F.10.1.1 acos 函式 (p: 378)
  • C11 標準 (ISO/IEC 9899:2011)
  • 7.12.4.1 acos 函式 (p: 238)
  • 7.25 型別通用數學 <tgmath.h> (p: 373-375)
  • F.10.1.1 acos 函式 (p: 518)
  • C99 標準 (ISO/IEC 9899:1999)
  • 7.12.4.1 acos 函式 (p: 218)
  • 7.22 型別通用數學 <tgmath.h> (p: 335-337)
  • F.9.1.1 acos 函式 (p: 455)
  • C89/C90 標準 (ISO/IEC 9899:1990)
  • 4.5.2.1 acos 函式

[編輯] 參閱

(C99)(C99)
計算反正弦 (arcsin(x))
(函式) [編輯]
(C99)(C99)
計算反正切 (arctan(x))
(函式) [編輯]
計算反正切,使用符號確定象限
(函式) [編輯]
(C99)(C99)
計算餘弦 (cos(x))
(函式) [編輯]
(C99)(C99)(C99)
計算復反餘弦
(函式) [編輯]
C++ 文件 for acos