1frexp(3)                   Library Functions Manual                   frexp(3)
2
3
4

NAME

6       frexp, frexpf, frexpl - convert floating-point number to fractional and
7       integral components
8

LIBRARY

10       Math library (libm, -lm)
11

SYNOPSIS

13       #include <math.h>
14
15       double frexp(double x, int *exp);
16       float frexpf(float x, int *exp);
17       long double frexpl(long double x, int *exp);
18
19   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21       frexpf(), frexpl():
22           _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
23               || /* Since glibc 2.19: */ _DEFAULT_SOURCE
24               || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
25

DESCRIPTION

27       These functions are used to split the number x into a normalized  frac‐
28       tion and an exponent which is stored in exp.
29

RETURN VALUE

31       These  functions  return the normalized fraction.  If the argument x is
32       not zero, the normalized fraction is x times a power of  two,  and  its
33       absolute value is always in the range 1/2 (inclusive) to 1 (exclusive),
34       that is, [0.5,1).
35
36       If x is zero, then the normalized fraction is zero and zero  is  stored
37       in exp.
38
39       If x is a NaN, a NaN is returned, and the value of *exp is unspecified.
40
41       If x is positive infinity (negative infinity), positive infinity (nega‐
42       tive infinity) is returned, and the value of *exp is unspecified.
43

ERRORS

45       No errors occur.
46

ATTRIBUTES

48       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
49       tributes(7).
50
51       ┌────────────────────────────────────────────┬───────────────┬─────────┐
52Interface                                   Attribute     Value   
53       ├────────────────────────────────────────────┼───────────────┼─────────┤
54frexp(), frexpf(), frexpl()                 │ Thread safety │ MT-Safe │
55       └────────────────────────────────────────────┴───────────────┴─────────┘
56

STANDARDS

58       C11, POSIX.1-2008.
59

HISTORY

61       C99, POSIX.1-2001.
62
63       The variant returning double also conforms to SVr4, 4.3BSD, C89.
64

EXAMPLES

66       The program below produces results such as the following:
67
68           $ ./a.out 2560
69           frexp(2560, &e) = 0.625: 0.625 * 2^12 = 2560
70           $ ./a.out -4
71           frexp(-4, &e) = -0.5: -0.5 * 2^3 = -4
72
73   Program source
74
75       #include <float.h>
76       #include <math.h>
77       #include <stdio.h>
78       #include <stdlib.h>
79
80       int
81       main(int argc, char *argv[])
82       {
83           double x, r;
84           int exp;
85
86           x = strtod(argv[1], NULL);
87           r = frexp(x, &exp);
88
89           printf("frexp(%g, &e) = %g: %g * %d^%d = %g\n",
90                  x, r, r, FLT_RADIX, exp, x);
91           exit(EXIT_SUCCESS);
92       }
93

SEE ALSO

95       ldexp(3), modf(3)
96
97
98
99Linux man-pages 6.05              2023-07-20                          frexp(3)
Impressum