seclan のほえほえルーム

| |

・プログラミング言語 C の新機能 Part LI: math.h: 関数: 逆双曲線/指数/対数/べき乗関数 (2000/03/08 [])
 math.h で定義されているほとんどの関数には double 型、float 型、long double 型を引数として受け取り、結果をその型として返す関数が追加されています。例えば、従来の sin 関数は double sin(double x); しか存在しなかったのが、今回からは、これに加え float sinf(float x);, long double sinl(long double x); のように float 型の関数 xxxxf、long double 型の関数 xxxxl が存在します。これに当てはまる math.h に従来から存在している関数は sin/cos/tan / asin/acos/atan/atan2 / sinh/cosh/tanh / exp/log/log10/pow/sqrt / fabs / ceil/floor / fmod/frexp/ldexp があります。今回は、これらの関数の説明は行いません。
 さて、これから新たに math.h に追加された関数を三回に分けてお送りします。今回は、逆双曲線関数/指数関数/対数関数/べき乗関数です。

逆双曲線関数(arc hyperbolic functions): asinh/acosh/atanh
名前 asinh
doubleasinh(double x);
floatasinhf(float x);
long doubleasinhl(long double x);
acosh
doubleacosh(double x);
floatacoshf(float x);
long doubleacoshl(long double x);
atanh
doubleatanh(double x);
floatatanhf(float x);
long doubleatanhl(long double x);
ヘッダmath.h
引数x: asinh/acosh/atanh の演算に対する引数
  acosh:x が 1 未満の値で domain error
  atanh:[-1,+1]以外だと domain error。x が -1 か +1 の時は range error がおこるかも。
戻値演算結果
  acosh: [0, +∞]の範囲
解説 x で示される値を関数の引数として、それぞれ arc hyperbolic sine/arc hyperbolic cosine/arc hyperbolic tangent の演算を行います。


指数/対数関数(exponential/logarithmic functions)
名前プロトタイプ解説
exp2
doubleexp2(double x);
floatexp2f(float x);
long doubleexp2l(long double x);
2x を計算します。x があまりに大きいと range error の可能性あり。
expm1
doubleexpm1(double x);
floatexpm1f(float x);
long doubleexpm1l(long double x);
ex-1 を計算します。x があまりに大きいと range error の可能性あり。
log2
doublelog2(double x);
floatlog2f(float x);
long doublelog2l(long double x);
log2 x を計算します。x が 0 未満の場合 domain error。x が 0 だと range error の可能性あり。
log1p
doublelog1p(double x);
floatlog1pf(float x);
long doublelog1pl(long double x);
loge (x+1) を計算します。x が -1 未満の場合 domain error。x が -1 だと range error の可能性あり。
logb
doublelogb(double x);
floatlogbf(float x);
long doublelogbl(long double x);
x のべき指数を、浮動小数点形式の符号付き整数として取り出します。x が 0 の場合 domain error の可能性あり。
ilogb
intilogb(double x);
intilogbf(float x);
intilogbl(long double x);
x のべき指数を符号付き int として取り出します。x が 0 だと range error の可能性あり。
x戻り値
0FP_ILOGB0
INT_MAX
NaNFP_ILOGBNAN
(int)logb(x)
scalbn

scalbln
doublescalbn(double x, int n);
floatscalbnf(float x, int n);
long doublescalbnl(long double x, int n);

doublescalbln(double x, long n);
floatscalblnf(float x, long n);
long doublescalblnl(long double x, long n);
x × FLT_RADIXn を計算します。range error の可能性があります。
scalbn は int 型の引数を、scalbln は long int 型の引数を取る点が違います。


べき乗関数(power functions)
名前プロトタイプ解説
cbrt
doublecbrt(double x);
floatcbrtf(float x);
long doublecbrtl(long double x);
3√x を計算します。
hypot
doublehypot(double x, double y);
floathypotf(float x, float y);
long doublehypotl(long double x, long double y);
過度のアンダーフローやオーバーフローなしに、原点からの距離 √(x2+y2) を計算します。range error の可能性あり。



by seclan


| |

 

配信

5.21 msec