acos()、acosf()、acosl() - 逆余弦の計算

標準

標準/拡張機能 C/C++ 依存項目

ISO C
POSIX.1
XPG4
XPG4.2
ISO/ANSI C++
C99
Single UNIX Specification、バージョン 3
C++ TR1 C99

両方  

形式

#include <math.h>

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

機能説明

x の逆余弦 (ラジアン表記) を、0 ~ pi の範囲で計算します。

x の値は、-1 と 1 の間 (両端を含む) になければなりません。
注: これらの関数は、IEEE 2 進数浮動小数点形式と 16 進浮動小数点形式の両方で機能します。 IEEE 2 進数浮動小数点の詳細は、IEEE 2 進数浮動小数点を参照してください。

戻り値

C/370™ の特殊な動作: x が -1 よりも小さいかまたは 1 よりも大きい場合、この関数は errno に EDOM を設定し、0 を戻します。正しい値がアンダーフローの原因になった場合には、ゼロが戻され、ERANGE の値が errno に保管されます。

XPG4.2 の特殊な動作: 正常に実行された場合、関数は、[0,pi] ラジアンの範囲で、x の逆余弦を戻します。

x の値が [-1,1] の範囲にない場合は、関数は 0.0 を戻して、errno に継ぎの値を設定します。その他のエラーは発生しません。
エラー・コード
説明
EDOM
x の値が [-1,1] の範囲にない。

IEEE の特殊な動作: 正常に実行された場合、関数は引数 x の逆余弦を戻します。

x が -1 よりも小さい、または 1 よりも大きい場合、 関数は errno に EDOM を設定し、NaNQ (Not a Number Quiet) を戻します。 その他のエラーは発生しません。

CELEBA04
⁄* CELEBA04  
                                    
   This example prompts for a value for x.                                      
   It prints an error message if x is greater than 1 or                         
   less than -1; otherwise, it assigns the arccosine of                         
   x to 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: %f too large for acos¥n", x );                              
  else if ( x < MIN )                                                           
    printf( "Error: %f too small for acos¥n", x );                              
  else {                                                                        
    y = acos( x );                                                              
    printf( "acos( %f ) = %f¥n", x, y );                                        
  }                                                                             
}                                                                               

出力

0.4 が入力された場合に予期される結果:
Enter x
acos( 0.400000 ) = 1.159279

関連情報