Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libm / common / sf_lround.c
blobe1f2fa1008a19f12d97e893a42d8ca80d536e289
1 /*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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 * ====================================================
12 #include "fdlibm.h"
14 #ifdef __STDC__
15 long int lroundf(float x)
16 #else
17 long int lroundf(x)
18 float x;
19 #endif
21 __int32_t exponent_less_127;
22 __uint32_t w;
23 long int result;
24 __int32_t sign;
26 GET_FLOAT_WORD (w, x);
27 exponent_less_127 = ((w & 0x7f800000) >> 23) - 127;
28 sign = (w & 0x80000000) != 0 ? -1 : 1;
29 w &= 0x7fffff;
30 w |= 0x800000;
32 if (exponent_less_127 < (int)((8 * sizeof (long int)) - 1))
34 if (exponent_less_127 < 0)
35 return exponent_less_127 < -1 ? 0 : sign;
36 else if (exponent_less_127 >= 23)
37 result = (long int) w << (exponent_less_127 - 23);
38 else
40 w += 0x400000 >> exponent_less_127;
41 result = w >> (23 - exponent_less_127);
44 else
45 return (long int) x;
47 return sign * result;
50 #ifdef _DOUBLE_IS_32BITS
52 #ifdef __STDC__
53 long int lround(double x)
54 #else
55 long int lround(x)
56 double x;
57 #endif
59 return lroundf((float) x);
62 #endif /* defined(_DOUBLE_IS_32BITS) */