2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\"
|
|
|
|
.\" References consulted:
|
|
|
|
.\" Linux libc source code
|
|
|
|
.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
|
|
|
|
.\" 386BSD man pages
|
|
|
|
.\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
|
|
|
|
.\" Modified 2002-07-27 by Walter Harms
|
|
|
|
.\" (walter.harms@informatik.uni-oldenburg.de)
|
|
|
|
.\"
|
|
|
|
.TH FREXP 3 2002-07-27 "" "Linux Programmer's Manual"
|
|
|
|
.SH NAME
|
|
|
|
frexp, frexpf, frexpl \- convert floating-point number to fractional
|
|
|
|
and integral components
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #include <math.h>
|
|
|
|
.sp
|
|
|
|
.BI "double frexp(double " x ", int *" exp );
|
2004-11-11 17:28:42 +00:00
|
|
|
.br
|
2004-11-03 13:51:07 +00:00
|
|
|
.BI "float frexpf(float " x ", int *" exp );
|
2004-11-11 17:28:42 +00:00
|
|
|
.br
|
2004-11-03 13:51:07 +00:00
|
|
|
.BI "long double frexpl(long double " x ", int *" exp );
|
|
|
|
.fi
|
|
|
|
.sp
|
2007-07-21 05:25:03 +00:00
|
|
|
Link with \fI\-lm\fP.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH DESCRIPTION
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR frexp ()
|
|
|
|
function is used to split the number \fIx\fP into a
|
2004-11-03 13:51:07 +00:00
|
|
|
normalized fraction and an exponent which is stored in \fIexp\fP.
|
|
|
|
.SH "RETURN VALUE"
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR frexp ()
|
|
|
|
function returns the normalized fraction.
|
2007-04-12 22:42:49 +00:00
|
|
|
If the argument \fIx\fP is not zero,
|
|
|
|
the normalized fraction is \fIx\fP times a power of two,
|
2005-11-14 14:19:52 +00:00
|
|
|
and its absolute value is always in the range 1/2 (inclusive) to
|
2007-04-12 22:42:49 +00:00
|
|
|
1 (exclusive).
|
|
|
|
If \fIx\fP is zero, then the normalized fraction is
|
2004-11-03 13:51:07 +00:00
|
|
|
zero and zero is stored in \fIexp\fP.
|
|
|
|
.SH "CONFORMING TO"
|
2006-08-03 13:57:30 +00:00
|
|
|
SVr4, 4.3BSD, C89.
|
2007-04-12 22:42:49 +00:00
|
|
|
The
|
2006-08-04 09:29:30 +00:00
|
|
|
.I float
|
|
|
|
and
|
|
|
|
.I "long double"
|
|
|
|
variants are C99 requirements.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH EXAMPLE
|
|
|
|
.nf
|
|
|
|
#include <math.h>
|
|
|
|
#include <float.h>
|
2005-11-14 14:19:52 +00:00
|
|
|
#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);
|
|
|
|
|
2006-12-16 06:12:03 +00:00
|
|
|
printf("frexp(%g, &e) = %g: %g * %d^%d = %g\\n",
|
2007-04-05 13:29:41 +00:00
|
|
|
x, r, r, FLT_RADIX, exp, x);
|
2005-11-14 14:19:52 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
} /* main */
|
2004-11-03 13:51:07 +00:00
|
|
|
.fi
|
|
|
|
.sp
|
2005-11-14 14:19:52 +00:00
|
|
|
This program produces results such as the following:
|
2004-11-03 13:51:07 +00:00
|
|
|
.sp
|
2007-12-19 06:57:44 +00:00
|
|
|
.in +4n
|
2005-11-14 14:19:52 +00:00
|
|
|
$ ./a.out 2560
|
2004-11-03 13:51:07 +00:00
|
|
|
frexp(2560, &e) = 0.625: 0.625 * 2^12 = 2560
|
2007-05-01 08:15:41 +00:00
|
|
|
$ ./a.out \-4
|
|
|
|
frexp(\-4, &e) = \-0.5: \-0.5 * 2^3 = -4
|
2004-11-03 13:51:07 +00:00
|
|
|
.in
|
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR ldexp (3),
|
|
|
|
.BR modf (3)
|