acos, acosf, acosl

计算反余弦值。

语法

double acos( double x );
float acosf( float x );
long double acosl( long double x );
#define acos(X) // Requires C11 or higher

float acos( float x );   // C++ only
long double acos( long double x );   // C++ only

参数

x
-1 到 1 之间的值,将为其计算反余弦值。

返回值

acos 函数返回 0 到 π 弧度范围内的 x 的反余弦值。

默认情况下,如果 x 小于 -1 或大于 1,acos 将返回无穷大。

输入 SEH 异常 _matherr 异常
± INF INVALID _DOMAIN
± QNaN、IND _DOMAIN
|x| > 1 INVALID _DOMAIN

备注

由于 C++ 支持重载,您可以调用采用并返回 acosfloat 类型的 long double 的重载。 在 C 程序中,除非你使用 <tgmath.h> 宏来调用此函数,否则 acos 始终采用并返回 double

如果使用 <tgmath.h> 中的 acos 宏,自变量的类型将确定选择哪个版本的函数。 有关详细信息,请参阅泛型类型数学

默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态

要求

例程 必需的标头 可选标头
acos, acosf, acosl <math.h> <errno.h>
acos <tgmath.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 );
}
Arcsine of 0.000000 = 0.000000
Arccosine of 0.000000 = 1.570796

另请参阅

数学和浮点支持
asinasinfasinl
atanatanfatanlatan2atan2fatan2l
coscosfcosl
_matherr
sinsinfsinl
tantanftanl