Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo C - <b>frexp() get mantissa and exponent of floating-point value</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
frexp()                  Get Mantissa and Exponent of Floating-Point Value

 #include   <math.h>

 double     frexp(x,expptr);
 double     x;                           Floating-point value
 int        *expptr;                     Pointer to stored integer exponent


    frexp() separates 'x' into a mantissa (m) and an exponent (n). The
    absolute value of (m) will be greater than or equal to 0.5 and less
    than 1.0: (n) will be the power of 2 exponent, and the following
    expression will be true:

                        ('x' == (m) * 2^(n))

    where ^ means "raised to the power of".  'expptr' is set to the
    exponent (n), and the mantissa (m) is returned.

    Returns:    The mantissa of 'x'.  If 'x' is 0.0, then '*expptr' is
                set to 0 and 0.0 is returned as the mantissa.

      Notes:    ldexp() performs the reverse function of frexp().

  -------------------------------- Example ---------------------------------

    The following statements calculate the mantissa and exponent for
    several floating-point values:

         #include <math.h>      /* Required for function definition only */

         main()
         {
             double a, b, c, d;
             int aexp, bexp, cexp, dexp;

             a = frexp(8.0, &aexp);     /* a =  0.5000, aexp =   4 */
             b = frexp(0.0, &bexp);     /* b =  0.0000, bexp =   0 */
             c = frexp(-32.5, &cexp);   /* c = -0.5078, cexp =   6 */
             d = frexp(1.0e-9, &dexp);  /* d =  0.5369, dexp = -29 */
         }

See Also: ldexp() modf()

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