1 /* lroundf adapted to be llroundf for Newlib, 2009 by Craig Howland. */ 2 /* 3 * ==================================================== 4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 5 * 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 9 * is preserved. 10 * ==================================================== 11 */ 12 13 #include "fdlibm.h" 14 #include <limits.h> 15 16 long long int llroundf(float x)17llroundf(float x) 18 { 19 __int32_t exponent_less_127; 20 __uint32_t w; 21 long long int result; 22 __int32_t sign; 23 24 GET_FLOAT_WORD (w, x); 25 exponent_less_127 = ((w & 0x7f800000) >> 23) - 127; 26 sign = (w & 0x80000000) != 0 ? -1 : 1; 27 w &= 0x7fffff; 28 w |= 0x800000; 29 30 if (exponent_less_127 < (int)((8 * sizeof (long long int)) - 1)) 31 { 32 if (exponent_less_127 < 0) 33 return exponent_less_127 < -1 ? 0 : sign; 34 else if (exponent_less_127 >= 23) 35 result = (long long int) w << (exponent_less_127 - 23); 36 else 37 { 38 w += 0x400000 >> exponent_less_127; 39 result = w >> (23 - exponent_less_127); 40 } 41 } 42 else 43 { 44 /* Result other than LONG_MIN is too large to be represented by 45 * a long int. 46 */ 47 if (x != (float) LLONG_MIN) 48 __math_set_invalidf(); 49 return sign == 1 ? LLONG_MAX : LLONG_MIN; 50 } 51 52 return sign * result; 53 } 54 55 _MATH_ALIAS_k_f(llround) 56