Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2 KiB

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