ldexp() Convert Mantissa and Exponent to Floating Point
#include <math.h>
double ldexp(m,exp);
double m; Floating-point value
int exp; Integer exponent
ldexp() returns the result of the calculation:
'm' * 2^ 'exp'
where ^ means "raised to the power of".
Returns: 'm' * 2^ 'exp'. On overflow, 'errno' (defined in
<stdlib.h>) is set to ERANGE (defined in <math.h>), and
the value HUGE (+ or -, depending on the sign of 'm') is
returned. (HUGE is defined in math.h.) On underflow 0.0
is returned ('errno' is not set on underflow).
Notes: frexp() breaks a floating-point value into mantissa and
exponent.
ldexp() does not call matherr() on error.
-------------------------------- Example ---------------------------------
The following statements calculate the values of 1.0 * 2^24, 6.5 *
2^-10, -2.0 * 2^0, and 9.9e99 * 2^999 (the last calculation
produces an OVERFLOW error):
#include <math.h> /* for ldexp() and ERANGE */
#include <stdio.h> /* for printf() */
#include <stdlib.h> /* for errno */
main()
{
double a, b, c, d;
a = ldexp(1.0, 24); /* a = 16777216.0 */
b = ldexp(6.5, -10); /* b = 0.0063477 */
c = ldexp(-2.0, 0); /* c = -2.0 */
errno = 0;
d = ldexp(9.9e99, 999); /* d = HUGE, causes an OVERFLOW error */
if (errno == ERANGE)
printf("OVERFLOW error in ldexp()\n");
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster