共用方式為


acos acosf

計算反餘弦函式。

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

參數

  • x
    計算 -1 和 1 之間的值的反餘弦函式

傳回值

acos 函式傳回 0 到 π 弧度之間的 x 的反餘弦函式值。

如果 x 小於 -1 或大於 1 , acos 函式的回傳結果預設是未定義的。

輸入

SEH 例外狀況

Matherr 例外狀況。

± ∞

INVALID

_DOMAIN

± QNAN 、 IND

_DOMAIN

|x|>1

INVALID

_DOMAIN

備註

C++ 允許多載,因此您可以呼叫 acos 不同版本的多載。 在 C 程式裏 acos 一律接受並傳回雙精度浮點數。

需求

程序

必要的標頭檔

選擇性的標頭檔

acos, acosf

<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 對等用法

System::Math::Acos

請參閱

參考

浮點支援

asin asinf

atan、 atanf、 atan2、 atan2f

cos,cosf,cosh、 coshf

_matherr

sin、 sinf、 sinh、 sinhf

tan、 tanf、 tanh、 tanhf