home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / JPLC2.ZIP / CHRSTC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-07-22  |  1.2 KB  |  55 lines

  1. /* 1.1  06-27-85                        (chrstc.c) 
  2.  ************************************************************************
  3.  *            Robert C. Tausworthe                *
  4.  *            Jet Propulsion Laboratory            *
  5.  *            Pasadena, CA 91009        1984        *
  6.  ************************************************************************/
  7.  
  8. #include "defs.h"
  9. #include "stdtyp.h"
  10. #include "errno.h"
  11. #include "mathcons.h"
  12.  
  13. /************************************************************************/
  14.     int
  15. chrstc(x)        /* return the characteristic (2's exponent) of
  16.                double x. Mantissa is in (.5, 1).        */
  17. /*----------------------------------------------------------------------*/
  18. double x;
  19. {
  20.     char *xp;
  21.     int n, norm;
  22.  
  23.     if (x IS 0.0)
  24.     {    errno = EDOM;
  25.         return -INFINITY;
  26.     }
  27.     xp = (char *) &x;
  28.  
  29. #ifdef ECOSOFT
  30.     return (((int) *xp) - 0x80);
  31. #endif
  32.  
  33. #ifdef AZTEC
  34.     n = (((int) (*xp++ & 0x7f)) - 0x40) * 8;
  35.     norm = *xp;
  36.     while (NOT(norm & 0x80))
  37.     {    n--;
  38.         norm = (norm << 1) | 1; 
  39.     }
  40.     return n;
  41. #endif
  42.  
  43. #ifdef CPM86
  44.     return (((int) (((xp[7] << 4) + (xp[6] >> 4)) & 0x7ff)) - 0x3fe);
  45. #endif
  46.  
  47. #ifdef UNIVERSE
  48.     return (((int)(((*xp << 1) + (xp[1] & 0x80 ? 1 : 0)) & 0xff)) - 0x80);
  49. #endif
  50.  
  51. #ifdef SUN
  52.     return (int)(((*xp & 0x7f) << 4) + ((xp[1] >> 4) & 0xf) - 0x3fe);
  53. #endif
  54. }
  55.