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
18 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20 frexpf(), frexpl(): _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 600
21 || _ISOC99_SOURCE; or cc -std=c99
22
24 The frexp() function is used to split the number x into a normalized
25 fraction and an exponent which is stored in exp.
26
28 The frexp() function returns the normalized fraction. If the argument
29 x is not zero, the normalized fraction is x times a power of two, and
30 its absolute value is always in the range 1/2 (inclusive) to 1 (exclu‐
31 sive), that is, [0.5,1).
32
33 If x is zero, then the normalized fraction is zero and zero is stored
34 in exp.
35
36 If x is a NaN, a NaN is returned, and the value of *exp is unspecified.
37
38 If x is positive infinity (negative infinity), positive infinity (nega‐
39 tive infinity) is returned, and the value of *exp is unspecified.
40
42 No errors occur.
43
45 C99, POSIX.1-2001. The variant returning double also conforms to SVr4,
46 4.3BSD, C89.
47
49 The program below produces results such as the following:
50
51 $ ./a.out 2560
52 frexp(2560, &e) = 0.625: 0.625 * 2^12 = 2560
53 $ ./a.out -4
54 frexp(-4, &e) = -0.5: -0.5 * 2^3 = -4
55
56 Program source
57
58 #include <math.h>
59 #include <float.h>
60 #include <stdio.h>
61 #include <stdlib.h>
62
63 int
64 main(int argc, char *argv[])
65 {
66 double x, r;
67 int exp;
68
69 x = strtod(argv[1], NULL);
70 r = frexp(x, &exp);
71
72 printf("frexp(%g, &e) = %g: %g * %d^%d = %g\n",
73 x, r, r, FLT_RADIX, exp, x);
74 exit(EXIT_SUCCESS);
75 } /* main */
76
78 ldexp(3), modf(3)
79
81 This page is part of release 3.25 of the Linux man-pages project. A
82 description of the project, and information about reporting bugs, can
83 be found at http://www.kernel.org/doc/man-pages/.
84
85
86
87 2008-10-29 FREXP(3)