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.

58 lines
1.4 KiB

  1. /* _FDscale function -- IEEE 754 version */
  2. #include "xmath.h"
  3. _STD_BEGIN
  4. _CRTIMP2 short __cdecl _FDscale(float *px, long lexp)
  5. { /* scale *px by 2^xexp with checking */
  6. unsigned short *ps = (unsigned short *)px;
  7. short xchar = (short)((ps[_F0] & _FMASK) >> _FOFF);
  8. if (xchar == _FMAX)
  9. return ((ps[_F0] & _FFRAC) != 0 || ps[_F1] != 0
  10. ? _NANCODE : _INFCODE);
  11. else if (xchar == 0 && 0 < (xchar = _FDnorm(ps)))
  12. return (0);
  13. lexp += xchar;
  14. if (_FMAX <= lexp)
  15. { /* overflow, return +/-INF */
  16. *px = ps[_F0] & _FSIGN ? -_FInf._Float : _FInf._Float;
  17. return (_INFCODE);
  18. }
  19. else if (0 < lexp)
  20. { /* finite result, repack */
  21. ps[_F0] = ps[_F0] & ~_FMASK | (short)lexp << _FOFF;
  22. return (_FINITE);
  23. }
  24. else
  25. { /* denormalized, scale */
  26. unsigned short sign = ps[_F0] & _FSIGN;
  27. ps[_F0] = (unsigned short)(1 << _FOFF
  28. | 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) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  53. * Consult your license regarding permissions and restrictions.
  54. V3.10:0009 */