frexp

Autres langues

Langue: ja

Autres versions - même langue

Version: 2002-07-27 (fedora - 25/11/07)

Section: 3 (Bibliothèques de fonctions)

名前

frexp, frexpf, frexpl - 浮動小数点実数を小数成分と整数成分に変換する

書式

 #include <math.h>
 
 double frexp(double x, int *exp);
 
float frexpf(float x, int *exp);
long double frexpl(long double x, int *exp);

-lm でリンクする。

説明

frexp() 関数は浮動小数点実数 x を正規化小数と指数に分解し、 指数を *exp に格納する。

返り値

frexp() 関数は正規化小数を返す。 引数 x がゼロでない場合、この正規化小数は x に 2 の累乗を乗じたものであり、その絶対値は 常に 1/2 以上 1 未満の値である。 x がゼロの場合、正規化小数はゼロになり *exp にはゼロが格納される。

準拠

SVr4, 4.3BSD, C89. float 版と long double 版は C99 の要求仕様である。

 #include <math.h>
 #include <float.h>
 #include <stdio.h>
 #include <stdlib.h>
 
 int
 main(int argc, char *argv[])
 {
     double x, r;
     int exp;
 
     x = strtod(argv[1], NULL);
     r = frexp(x, &exp);
 
     printf("frexp(%g, &e) = %g: %g * %d^%d = %g\n",
            x, r, r, FLT_RADIX, exp, x);
     exit(EXIT_SUCCESS);
 } /* main */
 

このプログラムを実行すると以下のような結果となる:

 $ ./a.out 2560
 frexp(2560, &e) = 0.625: 0.625 * 2^12 = 2560
 $ ./a.out -4
 frexp(-4, &e) = -0.5: -0.5 * 2^3 = -4
 

関連項目

ldexp(3), modf(3)