Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C - <b>ldexp() convert mantissa and exponent to floating point</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
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");
         }

See Also: frexp() modf()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson