AVR Libc Home Page AVRs AVR Libc Development Pages
Main Page User Manual Library Reference FAQ Alphabetical Index Example Projects

<math.h>: 数学関数


Defines

#define M_PI   3.141592653589793238462643
#define M_SQRT2   1.4142135623730950488016887
#define NAN   __builtin_nan("")
#define INFINITY   __builtin_inf()

Functions

double cos (double __x)
double fabs (double __x)
double fmod (double __x, double __y)
double modf (double __x, double *__iptr)
double sin (double __x)
double sqrt (double __x)
double tan (double __x)
double floor (double __x)
double ceil (double __x)
double frexp (double __x, int *__pexp)
double ldexp (double __x, int __exp)
double exp (double __x)
double cosh (double __x)
double sinh (double __x)
double tanh (double __x)
double acos (double __x)
double asin (double __x)
double atan (double __x)
double atan2 (double __y, double __x)
double log (double __x)
double log10 (double __x)
double pow (double __x, double __y)
int isnan (double __x)
int isinf (double __x)
double square (double __x)
static double copysign (double __x, double __y)
double fdim (double __x, double __y)
double fma (double __x, double __y, double __z)
double fmax (double __x, double __y)
double fmin (double __x, double __y)
int signbit (double __x)
double trunc (double __x)
static int isfinite (double __x)
double hypot (double __x, double __y)
double round (double __x)
long lround (double __x)
long lrint (double __x)

Detailed Description

 #include <math.h> 

このヘッダファイルは基本的な数学定数と関数を提供します。

Notes:
  • ここに上げた関数を利用するには、ライブラリ libm.a をリンクするよう追加のリンク指定が必要です。 FAQ entryもご覧ください。
  • 数学関数は例外処理を立ち上げず、 errno 変数を変更しません。それ故に、これらの大部分は const 属性で宣言されています。これはGCCによるよりよい最適化のためです。
    Math functions do not raise exceptions and do not change the errno variable. Therefore the majority of them are declared with const attribute, for better optimization by GCC.

Define Documentation

#define INFINITY   __builtin_inf()

無限大を表す定数

#define M_PI   3.141592653589793238462643

円周率を表す定数

#define M_SQRT2   1.4142135623730950488016887

2の平方根 ( √2 )

#define NAN   __builtin_nan("")

NAN(非数) を表す定数


Function Documentation

double acos ( double  __x  ) 

x の arc cosine (cos-1(x)、cos(x)の逆関数) を提供する。返す値はラジアン単位で 0〜+π。引数が-1〜+1の範囲外だとドメインエラーが起こります。

double asin ( double  __x  ) 

x のarc sine (sin-1(x)、sin(x)の逆関数) を提供する。返す値はラジアン単位で -π/2〜+π/2。引数が-1〜+1の範囲外だとドメインエラーが起こります。

double atan ( double  __x  ) 

x の arc tangent (tan-1(x)、tan(x)の逆関数) を提供する。返す値はラジアン単位で -π/2〜+π/2。

double atan2 ( double  __y,
double  __x 
)

y/x の arc tangent (tan-1(y/x)、tan(y/x)の逆関数) を提供する。x , y の符号情報も使って、どの象限にあるかも判定する。
値域はラジアン単位で -π〜+π。

double ceil ( double  __x  ) 

x 以上の最小の整数を返します。引数 x は浮動小数点の数です。

static double copysign ( double  __x,
double  __y 
) [static]

関数 copysign() は絶対値が x に等しく、符号ビットが y に等しい値を返す。

double cos ( double  __x  ) 

ラジアン単位の数 x についてcos(x) を返します

double cosh ( double  __x  ) 

cosh(x) (hyperbolic cos,双曲線余弦) を返します。

double exp ( double  __x  ) 

xの自然指数 e^x を返します。

double fabs ( double  __x  ) 

浮動小数点値 x の絶対値を返します。

double fdim ( double  __x,
double  __y 
)

これらの関数は、二つの引き数間の正の差分 max(x-y,0) を返す。 どちらかの引数が NaNなら、NaNを返す。

double floor ( double  __x  ) 

浮動小数点値 x 以下で、最も大きい整数値を返します。

double fma ( double  __x,
double  __y,
double  __z 
)

fma() 関数は 浮動小数点の積和計算 (__x * __y) + __z を計算する。演算の中間結果が(浮動小数点演算で)丸められないため、演算精度の向上に寄与することがある。

double fmax ( double  __x,
double  __y 
)

__x__y どちらか大きい方の数値を返す。
片方が NaN なら有効な方を、両方NaNなら、NaNを返す。

double fmin ( double  __x,
double  __y 
)

__x__y どちらか小さい方の数値を返す。
片方が NaN なら有効な方を、両方NaNなら、NaNを返す。

double fmod ( double  __x,
double  __y 
)

x/y の結果の小数部を返します。

double frexp ( double  __x,
int *  __pexp 
)

浮動小数点をA×2^B となるような2数に分離する。(A は正規化小数で、0.5≦__x<1 となる整数、__pexp は整数)
frexp() はAを値として返し、Bはポインタint *__pexp が指し示す整数変数に保存する。

引数 __x が通常の浮動小数点数の場合、 関数frexp() は0.5≦v <1 となるような正規化小数値 v もしくは 0 を返す。
__x = v * 2^__pexp になるような数 __pexp が算出される。__x がゼロの場合は、vも__pexpもゼロとなる。
__x が有限の値では無い(NaNやINFINITEなど)場合、frexp()は __x の値をそのまま返し、__pexp には0を返す

Note:
この実装では指数部の保存を省略するために、ゼロポインタ( zero pointer)を使うことを許容しています??
※NULLなのか0番地へのポインタなのかよく分かりません・・・

double hypot ( double  __x,
double  __y 
)

hypot() 関数は sqrt(__x*__x+__y*__y) の値を返す。これは直角を挟む 2 辺の長さが __x__y である直角三角形の斜辺の長さ、もしくは原点と点 (__x,__y) との距離である。
引数が小さい値の場合でもアンダーフローがなく、結果が(浮動小数点表現可能な?)範囲内なら、オーバーフローも起こしません。

static int isfinite ( double  __x  )  [static]

isfinite() 関数は、有限な値(±無限大やNaNでない) __x に対しゼロでない値を返します。※±無限大やNaNには0を返す

int isinf ( double  __x  ) 

isinf() 関数は、引数 __x が+∞なら値 1 を、引数 __x が-∞なら値 -1を、どちらでもないなら 0 を返します。

Note:
GCC 4.3 はこの関数をインラインコードに展開しますが、±∞双方に対し1を返すバグがあります (gcc bug #35509).

int isnan ( double  __x  ) 

引数 x が有効な数値でなければ(NaNならば) 1 、そうでなければ 0 を返します。

double ldexp ( double  __x,
int  __exp 
)

 __x * 2^__exp を返します。frexp()関数の逆を行う。

double log ( double  __x  ) 

x の自然対数を返します。

double log10 ( double  __x  ) 

10を底とする対数を返します。

long lrint ( double  __x  ) 

lrint() 関数は __x を最も近い整数値に丸めます。ちょうど整数と整数の間の数(1.5など)については、偶数の値になるように丸めます。
(0.5→0、1.5→2、2.5→2、3.5→4、4.5→4・・・・)
この関数は rint() 関数と似ていますが、返す値の方が異なり、オーバーフローが可能(下記参照)です。

Returns:
丸めた long 型整数値を返します。 __x が有限数でない場合や、オーバーフローが起こった場合は、 LONG_MIN (0x80000000) 値を返します。

long lround ( double  __x  ) 

lround() 関数は __x を最も近い整数値に丸めます。ちょうど整数と整数の間の数(1.5など)については、0から遠ざかる方の値になるようにします(絶対値が切り上げになる方向)。
この関数は round() 関数と似ていますが、返す値の方が異なり、オーバーフローが可能(下記参照)です。

Returns:
丸めた long 型整数値を返します。 __x が有限数でない場合や、オーバーフローが起こった場合は、 LONG_MIN (0x80000000) 値を返します。

double modf ( double  __x,
double *  __iptr 
)

modf() 関数は、引数 __x を整数部と小数部に分離します。各々は同じ正負符号を持ちます(-1.234→-1と-0.234)。
modf() 関数は符号付きで __x の小数部を返します。
整数部は __iptr が指し示すアドレス先に doubleで保存されます。

Note:
この実装では、ゼロポインタへの書き込みはスキップされます。
しかしながら、 (※本来の?)GCC 4.3 ではこの関数を、NULLアドレス指定で保存しないように指定できるような仕様のインラインコードに置き換えることができます。??
However, the GCC 4.3 can replace this function with inline code that does not permit to use NULL address for the avoiding of storing.

double pow ( double  __x,
double  __y 
)

pow()は、 __x__y 乗 ( __x ^__y ) の値を返す

double round ( double  __x  ) 

round() は、 __x を最も近い整数値に丸めます。中間の値(1.5など)については、(切り捨てでゼロから近づくのと異なり)ゼロから遠ざかる方向に丸めます。 オーバーフローは許容されません。

Returns:
上記の丸め結果を返します。 __x が integral?? または無限大値なら、__x 自身が返されます。 __xNaN 値なら、 NaN が返されます。

int signbit ( double  __x  ) 

signbit() は、値 __x がsign bit set を持つ場合は 0 でない値を返します。
これは `__x < 0.0' と同じ意味ではありません。
IEEE 754 浮動小数点フォーマットは、ゼロ値にも符号が付けられるからです。
`-0.0 < 0.0' は偽になるのですが、 `signbit (-0.0)' はゼロでない値を返し、真になります。
※マイナス無限小という概念?

double sin ( double  __x  ) 

sin ( __x ) を返します。引数はラジアン単位です。

double sinh ( double  __x  ) 

双曲線正弦 (ハイパボリックサイン) を返します。
※sinh(x) = (exp(x) - exp(-x)) / 2

double sqrt ( double  __x  ) 

負でない数の平方根を返します。

double square ( double  __x  ) 

__x * __x ( x^2) を返します。.

Note:
この関数はCの標準関数には属していません。

double tan ( double  __x  ) 

tan(x) ( __x の正接) を返します。__x はラジアン単位。

double tanh ( double  __x  ) 

hyperbolic-tangent(x) ( x の双曲線正接)を返します。

double trunc ( double  __x  ) 

__x に最も近い整数で絶対値は上回らない整数を返します。(絶対値で切り捨てになる方向)