1 /* lroundf adapted to be llroundf for Newlib, 2009 by Craig Howland. */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
18 __int32_t exponent_less_127
;
23 GET_FLOAT_WORD (w
, x
);
24 exponent_less_127
= ((w
& 0x7f800000) >> 23) - 127;
25 sign
= (w
& 0x80000000) != 0 ? -1 : 1;
29 if (exponent_less_127
< (int)((8 * sizeof (long long int)) - 1))
31 if (exponent_less_127
< 0)
32 return exponent_less_127
< -1 ? 0 : sign
;
33 else if (exponent_less_127
>= 23)
34 result
= (long long int) w
<< (exponent_less_127
- 23);
37 w
+= 0x400000 >> exponent_less_127
;
38 result
= w
>> (23 - exponent_less_127
);
42 return (long long int) x
;
47 #ifdef _DOUBLE_IS_32BITS
52 return llroundf((float) x
);
55 #endif /* defined(_DOUBLE_IS_32BITS) */