acos、acosf、acosl
计算反余弦值。
double acos(
double x
);
float acos(
float x
); // C++ only
long double acos(
long double x
); // C++ only
float acosf(
float x
);
long double acosl(
long double x
);
参数
- x
当值在-1到1之间,可以计算反余弦值 (反余弦值)。
返回值
acos 函数返回反余弦 x 在范围 0 到π之间的弧度。
默认情况下,如果 x 小于–1 或大于 1,acos返回未定义值。
输入 |
SEH 异常 |
Matherr 异常 |
---|---|---|
± ∞ |
INVALID |
_DOMAIN |
± QNAN,IND |
无 |
_DOMAIN |
|x|>1 |
INVALID |
_DOMAIN |
备注
由于 C++ 允许重载,您可以调用acos 的重载,该重载采用和返回 float 和 long double 值. 在 C 程序中,acos 始终采用并返回 double。
要求
例程 |
必需的标头 |
可选标头 |
---|---|---|
acos, acosf, acosl |
<math.h> |
<errno.h> |
示例
此程序提示在 -1 到 1 范围内的值。 在此范围之外的输入值导致_DOMAIN错误消息。 如果输入有效值,程序打印反正弦和该值反余弦值。
// crt_asincos.c
// arguments: 0
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int main( int ac, char* av[] )
{
double x,
y;
errno_t err;
// argument checking
if (ac != 2)
{
fprintf_s( stderr, "Usage: %s <number between -1 and 1>\n",
av[0]);
return 1;
}
// Convert argument into a double value
if ((err = sscanf_s( av[1], "%lf", &x )) != 1)
{
fprintf_s( stderr, "Error converting argument into ",
"double value.\n");
return 1;
}
// Arcsine of X
y = asin( x );
printf_s( "Arcsine of %f = %f\n", x, y );
// Arccosine of X
y = acos( x );
printf_s( "Arccosine of %f = %f\n", x, y );
}
.NET Framework 等效项
请参见
参考
atan、atanf、atanl、atan2、atan2f、atan2l
cos、cosf、cosl、cosh、coshf、coshl