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 #include <limits.h> 14 lroundf(float x)15long int lroundf(float x) 16 { 17 __int32_t exponent_less_127; 18 __uint32_t w; 19 long int result; 20 __int32_t sign; 21 22 GET_FLOAT_WORD (w, x); 23 exponent_less_127 = ((w & 0x7f800000) >> 23) - 127; 24 sign = (w & 0x80000000) != 0 ? -1 : 1; 25 w &= 0x7fffff; 26 w |= 0x800000; 27 28 if (exponent_less_127 < (__int32_t)((8 * sizeof (long int)) - 1)) 29 { 30 if (exponent_less_127 < 0) 31 return exponent_less_127 < -1 ? 0 : sign; 32 else if (exponent_less_127 >= 23) 33 result = (long int) w << (exponent_less_127 - 23); 34 else 35 { 36 w += 0x400000 >> exponent_less_127; 37 result = w >> (23 - exponent_less_127); 38 } 39 } 40 else 41 { 42 /* Result other than LONG_MIN is too large to be represented by 43 * a long int. 44 */ 45 if (x != (float) LONG_MIN) 46 __math_set_invalidf(); 47 return sign == 1 ? LONG_MAX : LONG_MIN; 48 } 49 50 return sign * result; 51 } 52 53 _MATH_ALIAS_j_f(lround) 54