fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libm / math / sf_floor.c
blob9264d81e9f2e59c1179d16366251382db6435f92
1 /* sf_floor.c -- float version of s_floor.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
5 /*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
12 * is preserved.
13 * ====================================================
17 * floorf(x)
18 * Return x rounded toward -inf to integral value
19 * Method:
20 * Bit twiddling.
21 * Exception:
22 * Inexact flag raised if x not equal to floorf(x).
25 #include "fdlibm.h"
27 #ifdef __STDC__
28 static const float huge = 1.0e30;
29 #else
30 static float huge = 1.0e30;
31 #endif
33 #ifdef __STDC__
34 float floorf(float x)
35 #else
36 float floorf(x)
37 float x;
38 #endif
40 __int32_t i0,j0;
41 __uint32_t i,ix;
42 GET_FLOAT_WORD(i0,x);
43 ix = (i0&0x7fffffff);
44 j0 = (ix>>23)-0x7f;
45 if(j0<23) {
46 if(j0<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=0;}
49 else if(!FLT_UWORD_IS_ZERO(ix))
50 { i0=0xbf800000;}
52 } else {
53 i = (0x007fffff)>>j0;
54 if((i0&i)==0) return x; /* x is integral */
55 if(huge+x>(float)0.0) { /* raise inexact flag */
56 if(i0<0) i0 += (0x00800000)>>j0;
57 i0 &= (~i);
60 } else {
61 if(!FLT_UWORD_IS_FINITE(ix)) return x+x; /* inf or NaN */
62 else return x; /* x is integral */
64 SET_FLOAT_WORD(x,i0);
65 return x;
68 #ifdef _DOUBLE_IS_32BITS
70 #ifdef __STDC__
71 double floor(double x)
72 #else
73 double floor(x)
74 double x;
75 #endif
77 return (double) floorf((float) x);
80 #endif /* defined(_DOUBLE_IS_32BITS) */