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
9 * ====================================================
23 /* Most significant word, least significant word. */
24 int exponent_less_127;
28 /* Extract sign bit. */
29 signbit = w & 0x80000000;
31 /* Extract exponent field. */
32 exponent_less_127 = (int)((w & 0x7f800000) >> 23) - 127;
34 if (exponent_less_127 < 23)
36 if (exponent_less_127 < 0)
39 if (exponent_less_127 == -1)
40 /* Result is +1.0 or -1.0. */
45 unsigned int exponent_mask = 0x007fffff >> exponent_less_127;
46 if ((w & exponent_mask) == 0)
47 /* x has an integral value. */
50 w += 0x00400000 >> exponent_less_127;
56 if (exponent_less_127 == 128)
57 /* x is NaN or infinite. */
66 #ifdef _DOUBLE_IS_32BITS
69 double round(double x)
75 return (double) roundf((float) x);
78 #endif /* defined(_DOUBLE_IS_32BITS) */