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 * ====================================================
14 #ifndef _DOUBLE_IS_32BITS
17 double round(double x
)
23 /* Most significant word, least significant word. */
24 __int32_t msw
, exponent_less_1023
;
27 EXTRACT_WORDS(msw
, lsw
, x
);
29 /* Extract exponent field. */
30 exponent_less_1023
= ((msw
& 0x7ff00000) >> 20) - 1023;
32 if (exponent_less_1023
< 20)
34 if (exponent_less_1023
< 0)
37 if (exponent_less_1023
== -1)
38 /* Result is +1.0 or -1.0. */
44 __uint32_t exponent_mask
= 0x000fffff >> exponent_less_1023
;
45 if ((msw
& exponent_mask
) == 0 && lsw
== 0)
46 /* x in an integral value. */
49 msw
+= 0x00080000 >> exponent_less_1023
;
50 msw
&= ~exponent_mask
;
54 else if (exponent_less_1023
> 51)
56 if (exponent_less_1023
== 1024)
57 /* x is NaN or infinite. */
64 __uint32_t exponent_mask
= 0xffffffff >> (exponent_less_1023
- 20);
67 if ((lsw
& exponent_mask
) == 0)
68 /* x is an integral value. */
71 tmp
= lsw
+ (1 << (51 - exponent_less_1023
));
76 lsw
&= ~exponent_mask
;
78 INSERT_WORDS(x
, msw
, lsw
);
83 #endif /* _DOUBLE_IS_32BITS */