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.

97 lines
2.6 KiB

  1. /* _LDnorm function -- IEEE 754 version */
  2. #include "wctype.h"
  3. #include "xmath.h"
  4. _STD_BEGIN
  5. #if !_DLONG
  6. /* not needed */
  7. #elif _LONG_DOUBLE_HAS_HIDDEN_BIT
  8. _CRTIMP2 short _LDnorm(unsigned short *ps)
  9. { /* normalize long double fraction -- SPARC */
  10. short xchar;
  11. unsigned short sign = ps[_L0];
  12. xchar = 1;
  13. if (ps[_L1] != 0 || ps[_L2] != 0 || ps[_L3] != 0
  14. || ps[_L4] != 0 || ps[_L5] != 0 || ps[_L6] != 0
  15. || ps[_L7] != 0)
  16. { /* nonzero, scale */
  17. for (ps[_L0] = 0; ps[_L0] == 0 && ps[_L1] < 0x100;
  18. xchar -= 16)
  19. { /* shift left by 16 */
  20. ps[_L0] = ps[_L1];
  21. ps[_L1] = ps[_L2], ps[_L2] = ps[_L3];
  22. ps[_L3] = ps[_L4], ps[_L4] = ps[_L5];
  23. ps[_L5] = ps[_L6], ps[_L6] = ps[_L7];
  24. ps[_L7] = 0;
  25. }
  26. for (; ps[_L0] == 0; --xchar)
  27. { /* shift left by 1 */
  28. ps[_L0] = ps[_L0] << 1 | ps[_L1] >> 15;
  29. ps[_L1] = ps[_L1] << 1 | ps[_L2] >> 15;
  30. ps[_L2] = ps[_L2] << 1 | ps[_L3] >> 15;
  31. ps[_L3] = ps[_L3] << 1 | ps[_L4] >> 15;
  32. ps[_L4] = ps[_L4] << 1 | ps[_L5] >> 15;
  33. ps[_L5] = ps[_L5] << 1 | ps[_L6] >> 15;
  34. ps[_L6] = ps[_L6] << 1 | ps[_L7] >> 15;
  35. ps[_L7] <<= 1;
  36. }
  37. for (; 1 < ps[_L0]; ++xchar)
  38. { /* shift right by 1 */
  39. ps[_L7] = ps[_L7] >> 1 | ps[_L6] << 15;
  40. ps[_L6] = ps[_L6] >> 1 | ps[_L5] << 15;
  41. ps[_L5] = ps[_L5] >> 1 | ps[_L4] << 15;
  42. ps[_L4] = ps[_L4] >> 1 | ps[_L3] << 15;
  43. ps[_L3] = ps[_L3] >> 1 | ps[_L2] << 15;
  44. ps[_L2] = ps[_L2] >> 1 | ps[_L1] << 15;
  45. ps[_L1] = ps[_L1] >> 1 | ps[_L0] << 15;
  46. ps[_L0] >>= 1;
  47. }
  48. }
  49. ps[_L0] = sign;
  50. return (xchar);
  51. }
  52. #else /* !_LONG_DOUBLE_HAS_HIDDEN_BIT */
  53. _CRTIMP2 short _LDnorm(unsigned short *ps)
  54. { /* normalize long double fraction */
  55. short xchar;
  56. unsigned short sign = ps[_L0];
  57. xchar = 0;
  58. for (ps[_L0] = 0; ps[_L0] == 0 && ps[_L1] < 0x100;
  59. xchar -= 16)
  60. { /* shift left by 16 */
  61. ps[_L0] = ps[_L1];
  62. ps[_L1] = ps[_L2], ps[_L2] = ps[_L3];
  63. ps[_L3] = ps[_L4], ps[_L4] = 0;
  64. }
  65. if (ps[_L0] == 0)
  66. for (; ps[_L1] < (1U << _LOFF); --xchar)
  67. { /* shift left by 1 */
  68. ps[_L1] = ps[_L1] << 1 | ps[_L2] >> 15;
  69. ps[_L2] = ps[_L2] << 1 | ps[_L3] >> 15;
  70. ps[_L3] = ps[_L3] << 1 | ps[_L4] >> 15;
  71. ps[_L4] <<= 1;
  72. }
  73. for (; ps[_L0] != 0; ++xchar)
  74. { /* shift right by 1 */
  75. ps[_L4] = ps[_L4] >> 1 | ps[_L3] << 15;
  76. ps[_L3] = ps[_L3] >> 1 | ps[_L2] << 15;
  77. ps[_L2] = ps[_L2] >> 1 | ps[_L1] << 15;
  78. ps[_L1] = ps[_L1] >> 1 | ps[_L0] << 15;
  79. ps[_L0] >>= 1;
  80. }
  81. ps[_L0] = sign;
  82. return (xchar);
  83. }
  84. #endif
  85. _STD_END
  86. /*
  87. * Copyright (c) 1994 by P.J. Plauger. ALL RIGHTS RESERVED.
  88. * Consult your license regarding permissions and restrictions.
  89. */
  90. /*
  91. 941029 pjp: added _STD machinery
  92. */