]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
2 | .\" | |
3 | .\" Permission is granted to make and distribute verbatim copies of this | |
4 | .\" manual provided the copyright notice and this permission notice are | |
5 | .\" preserved on all copies. | |
6 | .\" | |
7 | .\" Permission is granted to copy and distribute modified versions of this | |
8 | .\" manual under the conditions for verbatim copying, provided that the | |
9 | .\" entire resulting derived work is distributed under the terms of a | |
10 | .\" permission notice identical to this one. | |
c13182ef | 11 | .\" |
fea681da MK |
12 | .\" Since the Linux kernel and libraries are constantly changing, this |
13 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
14 | .\" responsibility for errors or omissions, or for damages resulting from | |
15 | .\" the use of the information contained herein. The author(s) may not | |
16 | .\" have taken the same level of care in the production of this manual, | |
17 | .\" which is licensed free of charge, as they might when working | |
18 | .\" professionally. | |
c13182ef | 19 | .\" |
fea681da MK |
20 | .\" Formatted or processed versions of this manual, if unaccompanied by |
21 | .\" the source, must acknowledge the copyright and authors of this work. | |
22 | .\" | |
23 | .\" References consulted: | |
24 | .\" Linux libc source code | |
25 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
26 | .\" 386BSD man pages | |
27 | .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu) | |
28 | .\" Modified 2002-07-27 by Walter Harms | |
29 | .\" (walter.harms@informatik.uni-oldenburg.de) | |
30 | .\" | |
08c9b488 | 31 | .TH FREXP 3 2008-10-29 "" "Linux Programmer's Manual" |
fea681da MK |
32 | .SH NAME |
33 | frexp, frexpf, frexpl \- convert floating-point number to fractional | |
34 | and integral components | |
35 | .SH SYNOPSIS | |
36 | .nf | |
37 | .B #include <math.h> | |
38 | .sp | |
39 | .BI "double frexp(double " x ", int *" exp ); | |
d39541ec | 40 | .br |
fea681da | 41 | .BI "float frexpf(float " x ", int *" exp ); |
d39541ec | 42 | .br |
fea681da MK |
43 | .BI "long double frexpl(long double " x ", int *" exp ); |
44 | .fi | |
45 | .sp | |
20c58d70 | 46 | Link with \fI\-lm\fP. |
6717c6ea MK |
47 | .sp |
48 | .in -4n | |
49 | Feature Test Macro Requirements for glibc (see | |
50 | .BR feature_test_macros (7)): | |
51 | .in | |
52 | .sp | |
53 | .ad l | |
54 | .BR frexpf (), | |
55 | .BR frexpl (): | |
56 | _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 600 || _ISOC99_SOURCE; or | |
57 | .I cc\ -std=c99 | |
58 | .ad b | |
fea681da | 59 | .SH DESCRIPTION |
60a90ecd MK |
60 | The |
61 | .BR frexp () | |
62 | function is used to split the number \fIx\fP into a | |
fea681da MK |
63 | normalized fraction and an exponent which is stored in \fIexp\fP. |
64 | .SH "RETURN VALUE" | |
60a90ecd MK |
65 | The |
66 | .BR frexp () | |
67 | function returns the normalized fraction. | |
c13182ef MK |
68 | If the argument \fIx\fP is not zero, |
69 | the normalized fraction is \fIx\fP times a power of two, | |
a2af275c | 70 | and its absolute value is always in the range 1/2 (inclusive) to |
6717c6ea MK |
71 | 1 (exclusive), that is, [0.5,1). |
72 | ||
c13182ef | 73 | If \fIx\fP is zero, then the normalized fraction is |
fea681da | 74 | zero and zero is stored in \fIexp\fP. |
6717c6ea MK |
75 | |
76 | If | |
77 | .I x | |
78 | is a NaN, | |
79 | a NaN is returned, and the value of | |
80 | .I *exp | |
81 | is unspecified. | |
82 | ||
83 | If | |
84 | .I x | |
85 | is positive infinity (negative infinity), | |
86 | positive infinity (negative infinity) is returned, and the value of | |
87 | .I *exp | |
88 | is unspecified. | |
89 | .SH ERRORS | |
90 | No errors occur. | |
fea681da | 91 | .SH "CONFORMING TO" |
6717c6ea MK |
92 | C99, POSIX.1-2001. |
93 | The variant returning | |
94 | .I double | |
95 | also conforms to | |
96 | SVr4, 4.3BSD, C89. | |
fea681da | 97 | .SH EXAMPLE |
a831ef97 MK |
98 | The program below produces results such as the following: |
99 | .sp | |
100 | .nf | |
101 | .in +4n | |
102 | .RB "$" " ./a.out 2560" | |
103 | frexp(2560, &e) = 0.625: 0.625 * 2^12 = 2560 | |
104 | .RB "$" " ./a.out \-4" | |
105 | frexp(\-4, &e) = \-0.5: \-0.5 * 2^3 = -4 | |
106 | .in | |
107 | .fi | |
108 | .SS Program source | |
109 | .R " " | |
fea681da | 110 | .nf |
fea681da MK |
111 | #include <math.h> |
112 | #include <float.h> | |
a2af275c MK |
113 | #include <stdio.h> |
114 | #include <stdlib.h> | |
115 | ||
116 | int | |
117 | main(int argc, char *argv[]) | |
118 | { | |
119 | double x, r; | |
120 | int exp; | |
121 | ||
122 | x = strtod(argv[1], NULL); | |
123 | r = frexp(x, &exp); | |
124 | ||
39ad75ab | 125 | printf("frexp(%g, &e) = %g: %g * %d^%d = %g\\n", |
7295b7ed | 126 | x, r, r, FLT_RADIX, exp, x); |
a2af275c MK |
127 | exit(EXIT_SUCCESS); |
128 | } /* main */ | |
fea681da | 129 | .fi |
fea681da MK |
130 | .SH "SEE ALSO" |
131 | .BR ldexp (3), | |
132 | .BR modf (3) |