fixed more binutils issues (newer gcc/libc)
[zpugcc/jano.git] / toolchain / gcc / newlib / libm / common / sf_round.c
blob75a72fe750ba3390aaaca3fb3acf68c88a010378
1 /*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
8 * is preserved.
9 * ====================================================
12 #include "fdlibm.h"
14 #ifdef __STDC__
15 float roundf(float x)
16 #else
17 float roundf(x)
18 float x;
19 #endif
21 int signbit;
22 int w;
23 /* Most significant word, least significant word. */
24 int exponent_less_127;
26 GET_FLOAT_WORD(w, x);
28 /* Extract sign bit. */
29 signbit = w & 0x80000000;
31 /* Extract exponent field. */
32 exponent_less_127 = ((w & 0x7f800000) >> 23) - 127;
34 if (exponent_less_127 < 23)
36 if (exponent_less_127 < 0)
38 w &= 0x80000000;
39 if (exponent_less_127 == -1)
40 /* Result is +1.0 or -1.0. */
41 w |= (127 << 23);
43 else
45 unsigned int exponent_mask = 0x007fffff >> exponent_less_127;
46 if ((w & exponent_mask) == 0)
47 /* x has an integral value. */
48 return x;
50 w += 0x00400000 >> exponent_less_127;
51 w &= ~exponent_mask;
54 else
56 if (exponent_less_127 == 128)
57 /* x is NaN or infinite. */
58 return x + x;
59 else
60 return x;
62 SET_FLOAT_WORD(x, w);
63 return x;
66 #ifdef _DOUBLE_IS_32BITS
68 #ifdef __STDC__
69 double round(double x)
70 #else
71 double round(x)
72 double x;
73 #endif
75 return (double) roundf((float) x);
78 #endif /* defined(_DOUBLE_IS_32BITS) */