s_ceilf.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #if defined(LIBM_SCCS) && !defined(lint)
  15. static char rcsid[] = "$NetBSD: s_ceilf.c,v 1.4 1995/05/10 20:46:55 jtc Exp $";
  16. #endif
  17. #include "math.h"
  18. #include "math_private.h"
  19. #ifdef __STDC__
  20. static const float huge = 1.0e30;
  21. #else
  22. static float huge = 1.0e30;
  23. #endif
  24. #ifdef __STDC__
  25. float __ceilf(float x)
  26. #else
  27. float __ceilf(x)
  28. float x;
  29. #endif
  30. {
  31. int32_t i0,j0;
  32. u_int32_t i;
  33. GET_FLOAT_WORD(i0,x);
  34. j0 = ((i0>>23)&0xff)-0x7f;
  35. if(j0<23) {
  36. if(j0<0) { /* raise inexact if x != 0 */
  37. if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */
  38. if(i0<0) {i0=0x80000000;}
  39. else if(i0!=0) { i0=0x3f800000;}
  40. }
  41. } else {
  42. i = (0x007fffff)>>j0;
  43. if((i0&i)==0) return x; /* x is integral */
  44. if(huge+x>(float)0.0) { /* raise inexact flag */
  45. if(i0>0) i0 += (0x00800000)>>j0;
  46. i0 &= (~i);
  47. }
  48. }
  49. } else {
  50. if(j0==0x80) return x+x; /* inf or NaN */
  51. else return x; /* x is integral */
  52. }
  53. SET_FLOAT_WORD(x,i0);
  54. return x;
  55. }
  56. weak_alias (__ceilf, ceilf)