acos() — 逆余弦の計算

フォーマット

#include <math.h>
double acos(double x);

言語レベル

ANSI

スレッド・セーフ

はい

説明

acos() 関数は x の逆余弦 (ラジアン表記) を、0 から π の範囲で計算します。

戻り値

acos() 関数は x の逆余弦を戻します。x の値は -1 と 1 の間 (両端を含む) でなければなりません。x が -1 よりも小さい、または 1 よりも大きい場合、acos()errnoEDOM を設定し、0 を戻します。

次の例は x の値を要求するプロンプトを出します。x が 1 よりも大きいか -1 よりも小さい場合はエラー・メッセージを出力します。それ以外の場合は x の逆余弦を y に割り当てます。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
#define MAX  1.0
#define MIN -1.0
 
int main(void)
{
  double x, y;
 
  printf( "Enter x¥n" );
  scanf( "%lf", &x );
 
  /* Output error if not in range */
  if ( x > MAX )
    printf( "Error: %lf too large for acos¥n", x );
  else if ( x < MIN )
    printf( "Error: %lf too small for acos¥n", x );
  else {
    y = acos( x );
    printf( "acos( %lf ) = %lf¥n", x, y );
  }
}
 
/*******  Expected output if 0.4 is entered:  *********
 
Enter x
acos( 0.400000 ) = 1.159279
*/