rintf.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* origin: FreeBSD /usr/src/lib/msun/src/s_rintf.c */
  2. /*
  3. * Conversion to float by Ian Lance Taylor, Cygnus Support, [email protected].
  4. */
  5. /*
  6. * ====================================================
  7. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  8. *
  9. * Developed at SunPro, a Sun Microsystems, Inc. business.
  10. * Permission to use, copy, modify, and distribute this
  11. * software is freely granted, provided that this notice
  12. * is preserved.
  13. * ====================================================
  14. */
  15. #include "libm.h"
  16. static const float
  17. TWO23[2] = {
  18. 8.3886080000e+06, /* 0x4b000000 */
  19. -8.3886080000e+06, /* 0xcb000000 */
  20. };
  21. float rintf(float x)
  22. {
  23. int32_t i0,j0,sx;
  24. float w,t;
  25. GET_FLOAT_WORD(i0, x);
  26. sx = (i0>>31) & 1;
  27. j0 = ((i0>>23)&0xff) - 0x7f;
  28. if (j0 < 23) {
  29. if (j0 < 0) {
  30. if ((i0&0x7fffffff) == 0)
  31. return x;
  32. STRICT_ASSIGN(float, w, TWO23[sx] + x);
  33. t = w - TWO23[sx];
  34. GET_FLOAT_WORD(i0, t);
  35. SET_FLOAT_WORD(t, (i0&0x7fffffff)|(sx<<31));
  36. return t;
  37. }
  38. STRICT_ASSIGN(float, w, TWO23[sx] + x);
  39. return w - TWO23[sx];
  40. }
  41. if (j0 == 0x80)
  42. return x+x; /* inf or NaN */
  43. return x; /* x is integral */
  44. }