asin, asinf, asinl
From cppreference.net
Common mathematical functions
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<math.h>
|
||
|
float
asinf
(
float
arg
)
;
|
(1) | (C99 起) |
|
double
asin
(
double
arg
)
;
|
(2) | |
|
long
double
asinl
(
long
double
arg
)
;
|
(3) | (C99 起) |
|
_Decimal32 asind32
(
_Decimal32 arg
)
;
|
(4) | (C23 起) |
|
_Decimal64 asind64
(
_Decimal64 arg
)
;
|
(5) | (C23 起) |
|
_Decimal128 asind128
(
_Decimal128 arg
)
;
|
(6) | (C23 起) |
|
定义于头文件
<tgmath.h>
|
||
|
#define asin( arg )
|
(7) | (C99 起) |
1-6)
计算
arg
的反正弦主值。
7)
类型泛型宏:若参数类型为
long
double
,则调用
(3)
(
asinl
);否则,若参数为整数类型或
double
类型,则调用
(2)
(
asin
);否则调用
(1)
(
asinf
)。若参数为复数,则宏调用对应的复数函数(
casinf
、
casin
、
casinl
)。
|
当且仅当实现预定义了
|
(since C23) |
目录 |
参数
| arg | - | 浮点数值 |
返回值
If no errors occur, the arc sine of arg ( arcsin(arg) ) in the range [-| π |
| 2 |
| π |
| 2 |
如果发生定义域错误,则返回一个由实现定义的值(在支持 NaN 的情况下返回 NaN)。
如果由于下溢发生范围错误,将返回正确结果(舍入后)。
错误处理
错误报告方式遵循
math_errhandling
中的规范。
当
arg
超出
[-1.0; 1.0]
范围时会发生定义域错误。
如果实现支持 IEEE 浮点算术 (IEC 60559):
- 若参数为 ±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("asin( 1.0) = %+f, 2*asin( 1.0)=%+f\n", asin(1), 2 * asin(1)); printf("asin(-0.5) = %+f, 6*asin(-0.5)=%+f\n", asin(-0.5), 6 * asin(-0.5)); // 特殊值 printf("asin(0.0) = %1f, asin(-0.0)=%f\n", asin(+0.0), asin(-0.0)); // 错误处理 errno = 0; feclearexcept(FE_ALL_EXCEPT); printf("asin(1.1) = %f\n", asin(1.1)); if (errno == EDOM) perror(" errno == EDOM"); if (fetestexcept(FE_INVALID)) puts(" FE_INVALID raised"); }
可能的输出:
asin( 1.0) = +1.570796, 2*asin( 1.0)=+3.141593
asin(-0.5) = -0.523599, 6*asin(-0.5)=-3.141593
asin(0.0) = 0.000000, asin(-0.0)=-0.000000
asin(1.1) = nan
errno == EDOM: Numerical argument out of domain
FE_INVALID raised
参考文献
- C23 标准 (ISO/IEC 9899:2024):
-
- 7.12.4.2 asin 函数 (p: TBD)
-
- 7.25 类型泛型数学 <tgmath.h> (p: TBD)
-
- F.10.1.2 asin 函数 (p: TBD)
- C17 标准 (ISO/IEC 9899:2018):
-
- 7.12.4.2 asin 函数 (p: 174)
-
- 7.25 泛型数学 <tgmath.h> (p: 272-273)
-
- F.10.1.2 asin 函数 (p: 378)
- C11 标准 (ISO/IEC 9899:2011):
-
- 7.12.4.2 asin 函数 (p: 238)
-
- 7.25 泛型数学 <tgmath.h> (p: 373-375)
-
- F.10.1.2 asin 函数 (p: 518)
- C99标准(ISO/IEC 9899:1999):
-
- 7.12.4.2 asin函数(第219页)
-
- 7.22 泛型数学 <tgmath.h>(第335-337页)
-
- F.9.1.2 asin函数(第456页)
- C89/C90 标准 (ISO/IEC 9899:1990):
-
- 4.5.2.2 asin 函数
参见
|
(C99)
(C99)
|
计算反余弦(
\({\small\arccos{x} }\)
arccos(x)
)
(函数) |
|
(C99)
(C99)
|
计算反正切(
\({\small\arctan{x} }\)
arctan(x)
)
(函数) |
|
(C99)
(C99)
|
使用符号确定象限计算反正切
(函数) |
|
(C99)
(C99)
|
计算正弦(
\({\small\sin{x} }\)
sin(x)
)
(函数) |
|
(C99)
(C99)
(C99)
|
计算复数反正弦
(函数) |
|
C++ 文档
中关于
asin
的内容
|
|