acos、 、 acosfacosl

計算反餘弦值。

語法

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 none _DOMAIN
|x| > 1 INVALID _DOMAIN

備註

因為 C++ 允許多載,所以您可以呼叫採用並傳回 acosfloat 類型的 long double 的多載。 在 C 程式中,除非您使用 <tgmath.h> 巨集來呼叫此函式, acos 否則一律接受 並傳 double回 。

如果您使用的acos<tgmath.h>巨集,自變數的類型會決定選取的函式版本。 如需詳細資料,請參閱型別泛型數學

根據預設,此函式的全域狀態會限定於應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態

需求

常式 必要的標頭 選擇性標頭
acos、 、 acosfacosl <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

另請參閱

數學與浮點支援
asin、 、 asinfasinl
atan、、atanfatanlatan2、、atan2fatan2l
cos、 、 cosfcosl
_matherr
sin、 、 sinfsinl
tan、 、 tanftanl