s_ceilf.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* s_ceilf.c -- float version of s_ceil.c.
  2. * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  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 "cdefs-compat.h"
  15. //__FBSDID("$FreeBSD: src/lib/msun/src/s_ceilf.c,v 1.8 2008/02/22 02:30:35 das Exp $");
  16. #include <openlibm_math.h>
  17. #include "math_private.h"
  18. static const float huge = 1.0e30;
  19. OLM_DLLEXPORT float
  20. ceilf(float x)
  21. {
  22. int32_t i0,j0;
  23. u_int32_t i;
  24. GET_FLOAT_WORD(i0,x);
  25. j0 = ((i0>>23)&0xff)-0x7f;
  26. if(j0<23) {
  27. if(j0<0) { /* raise inexact if x != 0 */
  28. if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */
  29. if(i0<0) {i0=0x80000000;}
  30. else if(i0!=0) { i0=0x3f800000;}
  31. }
  32. } else {
  33. i = (0x007fffff)>>j0;
  34. if((i0&i)==0) return x; /* x is integral */
  35. if(huge+x>(float)0.0) { /* raise inexact flag */
  36. if(i0>0) i0 += (0x00800000)>>j0;
  37. i0 &= (~i);
  38. }
  39. }
  40. } else {
  41. if(j0==0x80) return x+x; /* inf or NaN */
  42. else return x; /* x is integral */
  43. }
  44. SET_FLOAT_WORD(x,i0);
  45. return x;
  46. }