Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libm / common / sf_trunc.c
blob8eb0554d88a4072de0b5d86ca1be261dea2b4a5c
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 truncf(float x)
16 #else
17 float truncf(x)
18 float x;
19 #endif
21 __int32_t signbit, w, exponent_less_127;
23 GET_FLOAT_WORD(w,x);
25 /* Extract sign bit. */
26 signbit = w & 0x80000000;
28 /* Extract exponent field. */
29 exponent_less_127 = ((w & 0x7f800000) >> 23) - 127;
31 if (exponent_less_127 < 23)
33 if (exponent_less_127 < 0)
35 /* -1 < x < 1, so result is +0 or -0. */
36 SET_FLOAT_WORD(x, signbit);
38 else
40 SET_FLOAT_WORD(x, signbit | (w & ~(0x007fffff >> exponent_less_127)));
43 else
45 if (exponent_less_127 == 128)
46 /* x is NaN or infinite. */
47 return x + x;
49 /* All bits in the fraction field are relevant. */
51 return x;
54 #ifdef _DOUBLE_IS_32BITS
56 #ifdef __STDC__
57 double trunc(double x)
58 #else
59 double trunc(x)
60 double x;
61 #endif
63 return (double) truncf((float) x);
66 #endif /* defined(_DOUBLE_IS_32BITS) */