Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libm / common / sf_llround.c
blobfe2b4bd23b01cb50922b2d8e47b4850998815cde
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.
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 * ====================================================
13 #include "fdlibm.h"
15 long long int
16 llroundf(float x)
18 __int32_t exponent_less_127;
19 __uint32_t w;
20 long long int result;
21 __int32_t sign;
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;
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);
35 else
37 w += 0x400000 >> exponent_less_127;
38 result = w >> (23 - exponent_less_127);
41 else
42 return (long long int) x;
44 return sign * result;
47 #ifdef _DOUBLE_IS_32BITS
49 long long int
50 llround(double x)
52 return llroundf((float) x);
55 #endif /* defined(_DOUBLE_IS_32BITS) */