s_ceilf.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* s_ceilf.c -- float version of s_ceil.c.
  2. * Conversion to float by Ian Lance Taylor, Cygnus Support, [email protected].
  3. */
  4. /*
  5. * ====================================================
  6. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  7. *
  8. * Developed at SunPro, a Sun Microsystems, Inc. business.
  9. * Permission to use, copy, modify, and distribute this
  10. * software is freely granted, provided that this notice
  11. * is preserved.
  12. * ====================================================
  13. */
  14. #include <math.h>
  15. #include "math_private.h"
  16. static const float huge = 1.0e30;
  17. float
  18. ceilf(float x)
  19. {
  20. int32_t i0,j0;
  21. uint32_t i;
  22. GET_FLOAT_WORD(i0,x);
  23. j0 = ((i0>>23)&0xff)-0x7f;
  24. if(j0<23) {
  25. if(j0<0) { /* raise inexact if x != 0 */
  26. if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */
  27. if(i0<0) {i0=0x80000000;}
  28. else if(i0!=0) { i0=0x3f800000;}
  29. }
  30. } else {
  31. i = (0x007fffff)>>j0;
  32. if((i0&i)==0) return x; /* x is integral */
  33. if(huge+x>(float)0.0) { /* raise inexact flag */
  34. if(i0>0) i0 += (0x00800000)>>j0;
  35. i0 &= (~i);
  36. }
  37. }
  38. } else {
  39. if(j0==0x80) return x+x; /* inf or NaN */
  40. else return x; /* x is integral */
  41. }
  42. SET_FLOAT_WORD(x,i0);
  43. return x;
  44. }