Subversion Repositories Kolibri OS

Rev

Rev 8793 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
  2. #include <math.h>
  3.  
  4. double frexp(double x, int* exptr)
  5. {
  6.     union {
  7.         double d;
  8.         unsigned char c[8];
  9.     } u;
  10.  
  11.     u.d = x;
  12.     /*
  13.      * The format of the number is:
  14.      * Sign, 12 exponent bits, 51 mantissa bits
  15.      * The exponent is 1023 biased and there is an implicit zero.
  16.      * We get the exponent from the upper bits and set the exponent
  17.      * to 0x3fe (1022).
  18.      */
  19.     *exptr = (int)(((u.c[7] & 0x7f) << 4) | (u.c[6] >> 4)) - 1022;
  20.     u.c[7] &= 0x80;
  21.     u.c[7] |= 0x3f;
  22.     u.c[6] &= 0x0f;
  23.     u.c[6] |= 0xe0;
  24.     return u.d;
  25. }
  26.