1FREXP(3) Linux Programmer's Manual FREXP(3)
2
3
4
6 frexp, frexpf, frexpl - convert floating-point number to fractional and
7 integral components
8
10 #include <math.h>
11
12 double frexp(double x, int *exp);
13 float frexpf(float x, int *exp);
14 long double frexpl(long double x, int *exp);
15
16 Link with -lm.
17
19 The frexp() function is used to split the number x into a normalized
20 fraction and an exponent which is stored in exp.
21
23 The frexp() function returns the normalized fraction. If the argument
24 x is not zero, the normalized fraction is x times a power of two, and
25 its absolute value is always in the range 1/2 (inclusive) to 1 (exclu‐
26 sive). If x is zero, then the normalized fraction is zero and zero is
27 stored in exp.
28
30 SVr4, 4.3BSD, C89. The float and long double variants are C99 require‐
31 ments.
32
34 #include <math.h>
35 #include <float.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38
39 int
40 main(int argc, char *argv[])
41 {
42 double x, r;
43 int exp;
44
45 x = strtod(argv[1], NULL);
46 r = frexp(x, &exp);
47
48 printf("frexp(%g, &e) = %g: %g * %d^%d = %g\n",
49 x, r, r, FLT_RADIX, exp, x);
50 exit(EXIT_SUCCESS);
51 } /* main */
52
53 This program produces results such as the following:
54
55 $ ./a.out 2560 frexp(2560, &e) = 0.625: 0.625 * 2^12 = 2560 $
56 ./a.out -4 frexp(-4, &e) = -0.5: -0.5 * 2^3 = -4
57
59 ldexp(3), modf(3)
60
61
62
63 2002-07-27 FREXP(3)