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 
lroundf(float x)14 long int lroundf(float x)
15 {
16   __int32_t exponent_less_127;
17   __uint32_t w;
18   long int result;
19   __int32_t sign;
20 
21   GET_FLOAT_WORD (w, x);
22   exponent_less_127 = ((w & 0x7f800000) >> 23) - 127;
23   sign = (w & 0x80000000) != 0 ? -1 : 1;
24   w &= 0x7fffff;
25   w |= 0x800000;
26 
27   if (exponent_less_127 < (int)((8 * sizeof (long int)) - 1))
28     {
29       if (exponent_less_127 < 0)
30         return exponent_less_127 < -1 ? 0 : sign;
31       else if (exponent_less_127 >= 23)
32         result = (long int) w << (exponent_less_127 - 23);
33       else
34         {
35           w += 0x400000 >> exponent_less_127;
36           result = w >> (23 - exponent_less_127);
37         }
38     }
39   else
40       return (long int) x;
41 
42   return sign * result;
43 }
44 
45 _MATH_ALIAS_j_f(lround)
46