ceilf.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* origin: FreeBSD /usr/src/lib/msun/src/s_ceilf.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 huge = 1.0e30;
  17. float ceilf(float x)
  18. {
  19. int32_t i0,j0;
  20. uint32_t i;
  21. GET_FLOAT_WORD(i0, x);
  22. j0 = ((i0>>23)&0xff) - 0x7f;
  23. if (j0 < 23) {
  24. if (j0 < 0) {
  25. /* raise inexact if x != 0 */
  26. if (huge+x > 0.0f) {
  27. if (i0 < 0)
  28. i0 = 0x80000000;
  29. else if(i0 != 0)
  30. i0 = 0x3f800000;
  31. }
  32. } else {
  33. i = 0x007fffff>>j0;
  34. if ((i0&i) == 0)
  35. return x; /* x is integral */
  36. /* raise inexact flag */
  37. if (huge+x > 0.0f) {
  38. if (i0 > 0)
  39. i0 += 0x00800000>>j0;
  40. i0 &= ~i;
  41. }
  42. }
  43. } else {
  44. if (j0 == 0x80) /* inf or NaN */
  45. return x+x;
  46. return x; /* x is integral */
  47. }
  48. SET_FLOAT_WORD(x, i0);
  49. return x;
  50. }