≫ ホーム ≫ C言語ヘッダファイル別一覧 | C言語アルファベット別一覧 ≫ math.h ≫ logb, logbf, logbl
浮動小数点形式における符号付き整数の値として引数の指数を抽出します.
#include <math.h>
double logb( double x );
logb 関数は x の指数を抽出し,double 型で返します.
#include <math.h>
float logbf( float x );
logbf 関数は x の指数を抽出し,float 型で返します.
#include <math.h>
long double logbl( long double x );
logbl 関数は x の指数を抽出し,long double 型で返します.
logb,logbf,logbl 関数は,x が非正規化数の場合には正規化されているものとして処理します.また,x が 0 の場合に値域エラー (range error) が発生することがあります.
以下にlogb 関数を使用したサンプルプログラムを示します.
/* header files */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* main */
int main(void) {
double x, y;
x = pow(2.0, 3.0);
y = logb(x);
printf("logb(%.3f) = %.2f\n", x, y);
x = pow(2.0, 2.0);
y = logb(x);
printf("logb(%.3f) = %.2f\n", x, y);
x = pow(2.0, 1.0);
y = logb(x);
printf("logb(%.3f) = %.2f\n", x, y);
x = pow(2.0, -1.0);
y = logb(x);
printf("logb(%.3f) = %.2f\n", x, y);
x = pow(2.0, -2.0);
y = logb(x);
printf("logb(%.3f) = %.2f\n", x, y);
x = pow(2.0, -3.0);
y = logb(x);
printf("logb(%.3f) = %.2f\n", x, y);
return EXIT_SUCCESS;
}
サンプルプログラムの実行結果は以下のようになります.
logb(8.000) = 3.00 logb(4.000) = 2.00 logb(2.000) = 1.00 logb(0.500) = -1.00 logb(0.250) = -2.00 logb(0.125) = -3.00