mirror of https://github.com/mkerrisk/man-pages
Fixed to point out that that frexp() returns a number whose
*absolute* value is >= 0.5 and < 1. Amended the example program to demonstrate this.
This commit is contained in:
parent
1bc4359dcb
commit
a2af275c39
37
man3/frexp.3
37
man3/frexp.3
|
@ -48,9 +48,10 @@ Link with \-lm.
|
|||
The \fBfrexp\fP() function is used to split the number \fIx\fP into a
|
||||
normalized fraction and an exponent which is stored in \fIexp\fP.
|
||||
.SH "RETURN VALUE"
|
||||
The \fBfrexp\fP() function returns the normalized fraction. If the
|
||||
argument \fIx\fP is not zero, the normalized fraction is \fIx\fP
|
||||
times a power of two, and is always in the range 1/2 (inclusive) to
|
||||
The \fBfrexp\fP() function returns the normalized fraction.
|
||||
If the argument \fIx\fP is not zero,
|
||||
the normalized fraction is \fIx\fP times a power of two,
|
||||
and its absolute value is always in the range 1/2 (inclusive) to
|
||||
1 (exclusive). If \fIx\fP is zero, then the normalized fraction is
|
||||
zero and zero is stored in \fIexp\fP.
|
||||
.SH "CONFORMING TO"
|
||||
|
@ -58,23 +59,33 @@ SVID 3, POSIX, 4.3BSD, ISO 9899.
|
|||
The float and the long double variants are C99 requirements.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
int main () {
|
||||
double d = 2560;
|
||||
int e;
|
||||
double f = frexp(d, &e);
|
||||
printf("frexp(%g, &e) = %g: %g * %d^%d = %g\en",
|
||||
d, f, f, FLT_RADIX, e, d);
|
||||
return 0;
|
||||
}
|
||||
#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 */
|
||||
.fi
|
||||
.sp
|
||||
This program prints
|
||||
This program produces results such as the following:
|
||||
.sp
|
||||
.in +5
|
||||
$ ./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
|
||||
.in
|
||||
.SH "SEE ALSO"
|
||||
.BR ldexp (3),
|
||||
|
|
Loading…
Reference in New Issue