rintf.c 331 B

1234567891011121314151617181920
  1. #include <math.h>
  2. #include <stdint.h>
  3. float rintf(float x)
  4. {
  5. union {float f; uint32_t i;} u = {x};
  6. int e = u.i>>23 & 0xff;
  7. int s = u.i>>31;
  8. float_t y;
  9. if (e >= 0x7f+23)
  10. return x;
  11. if (s)
  12. y = (float)(x - 0x1p23f) + 0x1p23f;
  13. else
  14. y = (float)(x + 0x1p23f) - 0x1p23f;
  15. if (y == 0)
  16. return s ? -0.0f : 0.0f;
  17. return y;
  18. }