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