13a8617a8SJordan K. Hubbard /* s_ceilf.c -- float version of s_ceil.c.
23a8617a8SJordan K. Hubbard * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
33a8617a8SJordan K. Hubbard */
43a8617a8SJordan K. Hubbard
53a8617a8SJordan K. Hubbard /*
63a8617a8SJordan K. Hubbard * ====================================================
73a8617a8SJordan K. Hubbard * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
83a8617a8SJordan K. Hubbard *
93a8617a8SJordan K. Hubbard * Developed at SunPro, a Sun Microsystems, Inc. business.
103a8617a8SJordan K. Hubbard * Permission to use, copy, modify, and distribute this
113a8617a8SJordan K. Hubbard * software is freely granted, provided that this notice
123a8617a8SJordan K. Hubbard * is preserved.
133a8617a8SJordan K. Hubbard * ====================================================
143a8617a8SJordan K. Hubbard */
153a8617a8SJordan K. Hubbard
163a8617a8SJordan K. Hubbard #include "math.h"
173a8617a8SJordan K. Hubbard #include "math_private.h"
183a8617a8SJordan K. Hubbard
193a8617a8SJordan K. Hubbard static const float huge = 1.0e30;
203a8617a8SJordan K. Hubbard
2159b19ff1SAlfred Perlstein float
ceilf(float x)2259b19ff1SAlfred Perlstein ceilf(float x)
233a8617a8SJordan K. Hubbard {
243a8617a8SJordan K. Hubbard int32_t i0,j0;
253a8617a8SJordan K. Hubbard u_int32_t i;
263a8617a8SJordan K. Hubbard
273a8617a8SJordan K. Hubbard GET_FLOAT_WORD(i0,x);
283a8617a8SJordan K. Hubbard j0 = ((i0>>23)&0xff)-0x7f;
293a8617a8SJordan K. Hubbard if(j0<23) {
303a8617a8SJordan K. Hubbard if(j0<0) { /* raise inexact if x != 0 */
313a8617a8SJordan K. Hubbard if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */
323a8617a8SJordan K. Hubbard if(i0<0) {i0=0x80000000;}
333a8617a8SJordan K. Hubbard else if(i0!=0) { i0=0x3f800000;}
343a8617a8SJordan K. Hubbard }
353a8617a8SJordan K. Hubbard } else {
363a8617a8SJordan K. Hubbard i = (0x007fffff)>>j0;
373a8617a8SJordan K. Hubbard if((i0&i)==0) return x; /* x is integral */
383a8617a8SJordan K. Hubbard if(huge+x>(float)0.0) { /* raise inexact flag */
393a8617a8SJordan K. Hubbard if(i0>0) i0 += (0x00800000)>>j0;
403a8617a8SJordan K. Hubbard i0 &= (~i);
413a8617a8SJordan K. Hubbard }
423a8617a8SJordan K. Hubbard }
433a8617a8SJordan K. Hubbard } else {
443a8617a8SJordan K. Hubbard if(j0==0x80) return x+x; /* inf or NaN */
453a8617a8SJordan K. Hubbard else return x; /* x is integral */
463a8617a8SJordan K. Hubbard }
473a8617a8SJordan K. Hubbard SET_FLOAT_WORD(x,i0);
483a8617a8SJordan K. Hubbard return x;
493a8617a8SJordan K. Hubbard }
50