Source code of Windows XP (NT5)
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.

43 lines
1.1 KiB

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