POK
ceilf.c
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Fri Jan 30 14:41:34 2009
15  */
16 
17 /* s_ceilf.c -- float version of s_ceil.c.
18  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
19  */
20 
21 /*
22  * ====================================================
23  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
24  *
25  * Developed at SunPro, a Sun Microsystems, Inc. business.
26  * Permission to use, copy, modify, and distribute this
27  * software is freely granted, provided that this notice
28  * is preserved.
29  * ====================================================
30  */
31 #ifdef POK_NEEDS_LIBMATH
32 #include <libm.h>
33 #include "math_private.h"
34 
35 static const float huge = 1.0e30;
36 
37 float
38 ceilf(float x)
39 {
40  int32_t i0,jj0;
41  uint32_t i;
42 
43  GET_FLOAT_WORD(i0,x);
44  jj0 = ((i0>>23)&0xff)-0x7f;
45  if(jj0<23) {
46  if(jj0<0) { /* raise inexact if x != 0 */
47  if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */
48  if(i0<0) {i0=0x80000000;}
49  else if(i0!=0) { i0=0x3f800000;}
50  }
51  } else {
52  i = (0x007fffff)>>jj0;
53  if((i0&i)==0) return x; /* x is integral */
54  if(huge+x>(float)0.0) { /* raise inexact flag */
55  if(i0>0) i0 += (0x00800000)>>jj0;
56  i0 &= (~i);
57  }
58  }
59  } else {
60  if(jj0==0x80) return x+x; /* inf or NaN */
61  else return x; /* x is integral */
62  }
63  SET_FLOAT_WORD(x,i0);
64  return x;
65 }
66 
67 #endif