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++ ではオーバーロードが可能であるため、acos 型および float 型を受け取って返す 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

関連項目

数学と浮動小数点のサポート
asin, asinf, asinl
atan, atanf, atanl, atan2, atan2f, atan2l
cos, cosf, cosl
_matherr
sin, sinf, sinl
tan, tanf, tanl