Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libm / mathfp / sf_ldexp.c
blob9f05c43a04dff699c7c745249f6d18efe9a3c819
2 /* @(#)z_ldexpf.c 1.0 98/08/13 */
3 /******************************************************************
4 * ldexp
6 * Input:
7 * d - a floating point value
8 * e - an exponent value
10 * Output:
11 * A floating point value f such that f = d * 2 ^ e.
13 * Description:
14 * This function creates a floating point number f such that
15 * f = d * 2 ^ e.
17 *****************************************************************/
19 #include <float.h>
20 #include "fdlibm.h"
21 #include "zmath.h"
23 #define FLOAT_EXP_OFFS 127
25 float
26 ldexpf (float d,
27 int e)
29 int exp;
30 __int32_t wd;
32 GET_FLOAT_WORD (wd, d);
34 /* Check for special values and then scale d by e. */
35 switch (numtestf (wd))
37 case NAN:
38 errno = EDOM;
39 break;
41 case INF:
42 errno = ERANGE;
43 break;
45 case 0:
46 break;
48 default:
49 exp = (wd & 0x7f800000) >> 23;
50 exp += e;
52 if (exp > FLT_MAX_EXP + FLOAT_EXP_OFFS)
54 errno = ERANGE;
55 d = z_infinity_f.f;
57 else if (exp < FLT_MIN_EXP + FLOAT_EXP_OFFS)
59 errno = ERANGE;
60 d = -z_infinity_f.f;
62 else
64 wd &= 0x807fffff;
65 wd |= exp << 23;
66 SET_FLOAT_WORD (d, wd);
70 return (d);
73 #ifdef _DOUBLE_IS_32BITS
75 double ldexp (double x, int e)
77 return (double) ldexpf ((float) x, e);
80 #endif /* defined(_DOUBLE_IS_32BITS) */