home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / xfdnorm.c < prev    next >
C/C++ Source or Header  |  1998-06-16  |  927b  |  41 lines

  1. /* _FDnorm function -- IEEE 754 version */
  2. #include "wctype.h"
  3. #include "xmath.h"
  4. _STD_BEGIN
  5.  
  6. _CRTIMP2 short _FDnorm(unsigned short *ps)
  7.     {    /* normalize float fraction */
  8.     short xchar;
  9.     unsigned short sign = ps[_F0] & _FSIGN;
  10.  
  11.     xchar = 1;
  12.     if ((ps[_F0] &= _FFRAC) != 0 || ps[_F1])
  13.         {    /* nonzero, scale */
  14.         if (ps[_F0] == 0)
  15.             ps[_F0] = ps[_F1], ps[_F1] = 0, xchar -= 16;
  16.         for (; ps[_F0] < 1<<_FOFF; --xchar)
  17.             {    /* shift left by 1 */
  18.             ps[_F0] = ps[_F0] << 1 | ps[_F1] >> 15;
  19.             ps[_F1] <<= 1;
  20.             }
  21.         for (; 1<<_FOFF+1 <= ps[_F0]; ++xchar)
  22.             {    /* shift right by 1 */
  23.             ps[_F1] = ps[_F1] >> 1 | ps[_F0] << 15;
  24.             ps[_F0] >>= 1;
  25.             }
  26.         ps[_F0] &= _FFRAC;
  27.         }
  28.     ps[_F0] |= sign;
  29.     return (xchar);
  30.     }
  31. _STD_END
  32.  
  33. /*
  34.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  35.  * Consult your license regarding permissions and restrictions.
  36.  */
  37.  
  38. /*
  39. 941029 pjp: added _STD machinery
  40.  */
  41.