acos, acosf, acosl
来自cppreference.com
在标头 <math.h> 定义 | ||
float acosf(float arg ); | (1) | (C99 起) |
double acos(double arg ); | (2) | |
longdouble acosl(longdouble 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) 泛型宏:若实参拥有 longdouble 类型,则调用
acosl
。否则,若实参拥有整数类型或 double 类型,则调用 acos
。否则调用 acosf
。若实参为复数,则宏调用对应的复数函数(cacosf、cacos、cacosl)。仅当实现预定义了 | (C23 起) |
目录 |
[编辑]参数
arg | - | 浮点数 |
[编辑]返回值
若不出现错误,则返回 arg 于范围 [0 ; π] 中的弧(反)余弦(arccos(arg))。
若出现定义域错误,则返回实现定义值(受支持平台上为 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)); // 错误处理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 The acos functions (第 TBD 页)
- 7.25 Type-generic math <tgmath.h> (第 TBD 页)
- F.10.1.1 The acos functions (第 TBD 页)
- C17 标准(ISO/IEC 9899:2018):
- 7.12.4.1 The acos functions (第 173 页)
- 7.25 Type-generic math <tgmath.h> (第 272-273 页)
- F.10.1.1 The acos functions (第 378 页)
- C11 标准(ISO/IEC 9899:2011):
- 7.12.4.1 The acos functions (第 238 页)
- 7.25 Type-generic math <tgmath.h> (第 373-375 页)
- F.10.1.1 The acos functions (第 518 页)
- C99 标准(ISO/IEC 9899:1999):
- 7.12.4.1 The acos functions (第 218 页)
- 7.22 Type-generic math <tgmath.h> (第 335-337 页)
- F.9.1.1 The acos functions (第 455 页)
- C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.1 The acos function
[编辑]参阅
(C99)(C99) | 计算反正弦(arcsin(x)) (函数) |
(C99)(C99) | 计算反正切(arctan(x)) (函数) |
(C99)(C99) | 计算反正切,以符号确定象限 (函数) |
(C99)(C99) | 计算余弦(cos(x)) (函数) |
(C99)(C99)(C99) | 计算复数反余弦 (函数) |
acos 的 C++ 文档 |