home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / stdlib / rcs / ldexp.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  1.6 KB  |  83 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.17.01.06;    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 KERNEL
  46. #include "ixemul.h"
  47.  
  48. #define MANT_MASK 0x800FFFFF    /* Mantissa extraction mask     */
  49. #define ZPOS_MASK 0x3FF00000    /* Positive # mask for exp = 0  */
  50. #define ZNEG_MASK 0x3FF00000    /* Negative # mask for exp = 0  */
  51.  
  52. #define EXP_MASK 0x7FF00000    /* Mask for exponent            */
  53. #define EXP_SHIFTS 20        /* Shifts to get into LSB's     */
  54. #define EXP_BIAS 1023        /* Exponent bias                */
  55.  
  56.  
  57. union dtol
  58. {
  59.   double dval;
  60.   int ival[2];
  61. };
  62.  
  63. double
  64. ldexp (double value, int exp)
  65. {
  66.   union dtol number;
  67.   int *iptr, cexp;
  68.  
  69.   if (value == 0.0)
  70.     return (0.0);
  71.   else
  72.     {
  73.       number.dval = value;
  74.       iptr = &number.ival[0];
  75.       cexp = (((*iptr) & EXP_MASK) >> EXP_SHIFTS) - EXP_BIAS;
  76.       *iptr &= ~EXP_MASK;
  77.       exp += EXP_BIAS;
  78.       *iptr |= ((exp + cexp) << EXP_SHIFTS) & EXP_MASK;
  79.       return (number.dval);
  80.     }
  81. }
  82. @
  83.