home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / LIBC / LIBC-4.6 / LIBC-4 / libc-linux / sysdeps / linux / i386 / math / frexpl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-26  |  961 b   |  80 lines

  1. #include "mathl.h"
  2.  
  3. #define IBMPC 1
  4. #define DENORMAL 1
  5.  
  6. #ifdef IBMPC
  7. #define EXPMSK 0x800f
  8. #define MEXP 0x7ff
  9. #define NBITS 64
  10. #endif
  11.  
  12. #ifdef MIEEE
  13. #define EXPMSK 0x800f
  14. #define MEXP 0x7ff
  15. #define NBITS 64
  16. #endif
  17.  
  18. extern double MAXNUML;
  19.  
  20.  
  21. long double frexpl( x, pw2 )
  22. long double x;
  23. int *pw2;
  24. {
  25. union
  26.   {
  27.     long double y;
  28.     unsigned short sh[6];
  29.   } u;
  30. int i, k;
  31. short *q;
  32.  
  33. u.y = x;
  34.  
  35. #ifdef UNK
  36. mtherr( "frexp", DOMAIN );
  37. return(0.0L);
  38. #endif
  39.  
  40. /* find the exponent (power of 2) */
  41. #ifdef IBMPC
  42. q = (short *)&u.sh[4];
  43. i  = *q & 0x7fff;
  44. #endif
  45.  
  46. #ifdef MIEEE
  47. q = (short *)&u.sh[0];
  48. i  = *q & 0x7fff;
  49. #endif
  50.  
  51.  
  52. if( i == 0 )
  53.     {
  54.     if( u.y == 0.0L )
  55.         {
  56.         *pw2 = 0;
  57.         return(0.0L);
  58.         }
  59. /* Number is denormal or zero */
  60. #ifdef DENORMAL
  61. /* Handle denormal number. */
  62. do
  63.     {
  64.     u.y *= 2.0L;
  65.     i -= 1;
  66.     k  = *q & 0x7fff;
  67.     }
  68. while( (k == 0) && (i > -66) );
  69. i = i + k;
  70. #else
  71.     *pw2 = 0;
  72.     return(0.0L);
  73. #endif /* DENORMAL */
  74.     }
  75.  
  76. *pw2 = i - 0x3ffe;
  77. *q = 0x3ffe;
  78. return( u.y );
  79. }
  80.