#include <math.h> double frexp(double x, int *exp);
float frexpf(float x, int *exp);
long double frexpl(long double x, int *exp);
-lm でリンクする。
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
frexpf(), frexpl(): _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE; or cc -std=c99
x がゼロの場合、正規化小数はゼロになり *exp にはゼロが格納される。
x が NaN の場合、NaN が返される。 *exp の値は不定である。
x が正の無限大 (負の無限大) の場合、 正の無限大 (負の無限大) が返される。 *exp の値は不定である。
$ ./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
#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 */