標準/拡張機能 | C/C++ | 依存項目 |
---|---|---|
ISO C |
両方 |
#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 の範囲で計算します。
C/370™ の特殊な動作: x が -1 よりも小さいかまたは 1 よりも大きい場合、この関数は errno に EDOM を設定し、0 を戻します。正しい値がアンダーフローの原因になった場合には、ゼロが戻され、ERANGE の値が errno に保管されます。
XPG4.2 の特殊な動作: 正常に実行された場合、関数は、[0,pi] ラジアンの範囲で、x の逆余弦を戻します。
IEEE の特殊な動作: 正常に実行された場合、関数は引数 x の逆余弦を戻します。
x が -1 よりも小さい、または 1 よりも大きい場合、 関数は errno に EDOM を設定し、NaNQ (Not a Number Quiet) を戻します。 その他のエラーは発生しません。
⁄* 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 );
}
}
出力
Enter x
acos( 0.400000 ) = 1.159279