home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / gen_library / rcs / frexp.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  943 b   |  75 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. @#if defined(LIBC_SCCS) && !defined(lint)
  26. static char sccsid[] = "@@(#)frexp.c    5.2 (Berkeley) 3/9/86";
  27. #endif LIBC_SCCS and not lint
  28.  
  29. #define KERNEL
  30. #include "ixemul.h"
  31.  
  32. /*
  33.  *    the call
  34.  *        x = frexp(arg,&exp);
  35.  *    must return a double fp quantity x which is <1.0
  36.  *    and the corresponding binary exponent "exp".
  37.  *    such that
  38.  *        arg = x*2^exp
  39.  *    if the argument is 0.0, return 0.0 mantissa and 0 exponent.
  40.  */
  41.  
  42. double
  43. frexp(double x, int *i)
  44. {
  45.   int neg;
  46.   int j;
  47.  
  48.   j = 0;
  49.   neg = 0;
  50.  
  51.   if (x < 0)
  52.     {
  53.       x = -x;
  54.       neg = 1;
  55.     }
  56.  
  57.   if (x >= 1.0)
  58.     while(x >= 1.0)
  59.       {
  60.     j = j+1;
  61.     x = x/2;
  62.       }
  63.   else if(x < 0.5 && x != 0.0)
  64.     while(x < 0.5)
  65.       {
  66.     j = j-1;
  67.     x = 2*x;
  68.       }
  69.  
  70.   *i = j;
  71.   if (neg) x = -x;
  72.   return x;
  73. }
  74. @
  75.