1 /*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4 *
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 * ====================================================
10 */
11
12 #include "fdlibm.h"
13
14 float
roundf(float x)15 roundf(float x)
16 {
17 __uint32_t w;
18 /* Most significant word, least significant word. */
19 int exponent_less_127;
20
21 GET_FLOAT_WORD(w, x);
22
23 /* Extract exponent field. */
24 exponent_less_127 = (int)((w & 0x7f800000) >> 23) - 127;
25
26 if (exponent_less_127 < 23)
27 {
28 if (exponent_less_127 < 0)
29 {
30 w &= 0x80000000;
31 if (exponent_less_127 == -1)
32 /* Result is +1.0 or -1.0. */
33 w |= ((__uint32_t)127 << 23);
34 }
35 else
36 {
37 __uint32_t exponent_mask = 0x007fffff >> exponent_less_127;
38 if ((w & exponent_mask) == 0)
39 /* x has an integral value. */
40 return x;
41
42 w += 0x00400000 >> exponent_less_127;
43 w &= ~exponent_mask;
44 }
45 }
46 else
47 {
48 if (exponent_less_127 == 128)
49 /* x is NaN or infinite. */
50 return x + x;
51 else
52 return x;
53 }
54 SET_FLOAT_WORD(x, w);
55 return x;
56 }
57
58 _MATH_ALIAS_f_f(round)
59