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.

62 lines
1.5 KiB

  1. /* _FDscale function -- IEEE 754 version */
  2. #include "wctype.h"
  3. #include "xmath.h"
  4. _STD_BEGIN
  5. _CRTIMP2 short _FDscale(float *px, long lexp)
  6. { /* scale *px by 2^xexp with checking */
  7. unsigned short *ps = (unsigned short *)px;
  8. short xchar = (ps[_F0] & _FMASK) >> _FOFF;
  9. if (xchar == _FMAX)
  10. return ((ps[_F0] & _FFRAC) != 0 || ps[_F1] != 0
  11. ? NAN : INF);
  12. else if (xchar == 0 && 0 < (xchar = _FDnorm(ps)))
  13. return (0);
  14. lexp += xchar;
  15. if (_FMAX <= lexp)
  16. { /* overflow, return +/-INF */
  17. *px = ps[_F0] & _FSIGN ? -_FInf._F : _FInf._F;
  18. return (INF);
  19. }
  20. else if (0 < lexp)
  21. { /* finite result, repack */
  22. ps[_F0] = ps[_F0] & ~_FMASK | (short)lexp << _FOFF;
  23. return (FINITE);
  24. }
  25. else
  26. { /* denormalized, scale */
  27. unsigned short sign = ps[_F0] & _FSIGN;
  28. ps[_F0] = 1 << _FOFF | ps[_F0] & _FFRAC;
  29. if (--lexp < -(16+_FOFF))
  30. { /* underflow, return +/-0 */
  31. ps[_F0] = sign, ps[_F1] = 0;
  32. return (0);
  33. }
  34. else
  35. { /* nonzero, align fraction */
  36. short xexp = (short)lexp;
  37. if (xexp <= -16)
  38. ps[_F1] = ps[_F0], ps[_F0] = 0, xexp += 16;
  39. if ((xexp = -xexp) != 0)
  40. { /* scale by bits */
  41. ps[_F1] = ps[_F1] >> xexp
  42. | ps[_F0] << (16 - xexp);
  43. ps[_F0] >>= xexp;
  44. }
  45. ps[_F0] |= sign;
  46. return (FINITE);
  47. }
  48. }
  49. }
  50. _STD_END
  51. /*
  52. * Copyright (c) 1994 by P.J. Plauger. ALL RIGHTS RESERVED.
  53. * Consult your license regarding permissions and restrictions.
  54. */
  55. /*
  56. 941029 pjp: added _STD machinery
  57. */