home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / gen_library / rcs / ldexp.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  1.6 KB  |  82 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.1
  10. date    92.06.08.18.31.20;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @initial checkin
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*
  26.  * ldexp returns the quanity "value" * 2 ^ "exp"
  27.  *
  28.  * For the mc68000 using IEEE format the double precision word format is:
  29.  *
  30.  * WORD N   =>    SEEEEEEEEEEEMMMM
  31.  * WORD N+1 =>    MMMMMMMMMMMMMMMM
  32.  * WORD N+2 =>    MMMMMMMMMMMMMMMM
  33.  * WORD N+3 =>    MMMMMMMMMMMMMMMM
  34.  *
  35.  * Where:          S  =>   Sign bit
  36.  *                 E  =>   Exponent
  37.  *                 X  =>   Ignored (set to 0)
  38.  *                 M  =>   Mantissa bit
  39.  *
  40.  * NOTE:  Beware of 0.0; on some machines which use excess 128 notation for the
  41.  * exponent, if the mantissa is zero the exponent is also.
  42.  *
  43.  */
  44.  
  45. #define MANT_MASK 0x800FFFFF    /* Mantissa extraction mask     */
  46. #define ZPOS_MASK 0x3FF00000    /* Positive # mask for exp = 0  */
  47. #define ZNEG_MASK 0x3FF00000    /* Negative # mask for exp = 0  */
  48.  
  49. #define EXP_MASK 0x7FF00000    /* Mask for exponent            */
  50. #define EXP_SHIFTS 20        /* Shifts to get into LSB's     */
  51. #define EXP_BIAS 1023        /* Exponent bias                */
  52.  
  53.  
  54. union dtol
  55. {
  56.   double dval;
  57.   int ival[2];
  58. };
  59.  
  60. double
  61. ldexp (value, exp)
  62.      double value;
  63.      int exp;
  64. {
  65.   union dtol number;
  66.   int *iptr, cexp;
  67.  
  68.   if (value == 0.0)
  69.     return (0.0);
  70.   else
  71.     {
  72.       number.dval = value;
  73.       iptr = &number.ival[0];
  74.       cexp = (((*iptr) & EXP_MASK) >> EXP_SHIFTS) - EXP_BIAS;
  75.       *iptr &= ~EXP_MASK;
  76.       exp += EXP_BIAS;
  77.       *iptr |= ((exp + cexp) << EXP_SHIFTS) & EXP_MASK;
  78.       return (number.dval);
  79.     }
  80. }
  81. @
  82.