Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libm / common / sf_round.c
blobc8f1d7733e05aa11ccb353884d1a8d77f32530c7
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 float roundf(float x)
16 #else
17 float roundf(x)
18 float x;
19 #endif
21 __uint32_t w;
22 /* Most significant word, least significant word. */
23 int exponent_less_127;
25 GET_FLOAT_WORD(w, x);
27 /* Extract exponent field. */
28 exponent_less_127 = (int)((w & 0x7f800000) >> 23) - 127;
30 if (exponent_less_127 < 23)
32 if (exponent_less_127 < 0)
34 w &= 0x80000000;
35 if (exponent_less_127 == -1)
36 /* Result is +1.0 or -1.0. */
37 w |= ((__uint32_t)127 << 23);
39 else
41 unsigned int exponent_mask = 0x007fffff >> exponent_less_127;
42 if ((w & exponent_mask) == 0)
43 /* x has an integral value. */
44 return x;
46 w += 0x00400000 >> exponent_less_127;
47 w &= ~exponent_mask;
50 else
52 if (exponent_less_127 == 128)
53 /* x is NaN or infinite. */
54 return x + x;
55 else
56 return x;
58 SET_FLOAT_WORD(x, w);
59 return x;
62 #ifdef _DOUBLE_IS_32BITS
64 #ifdef __STDC__
65 double round(double x)
66 #else
67 double round(x)
68 double x;
69 #endif
71 return (double) roundf((float) x);
74 #endif /* defined(_DOUBLE_IS_32BITS) */