source: trunk/libs/newlib/src/newlib/libm/mathfp/sf_ldexp.c @ 471

Last change on this file since 471 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.4 KB
Line 
1
2/* @(#)z_ldexpf.c 1.0 98/08/13 */
3/******************************************************************
4 * ldexp
5 *
6 * Input:
7 *   d - a floating point value
8 *   e - an exponent value
9 *
10 * Output:
11 *   A floating point value f such that f = d * 2 ^ e.
12 *
13 * Description:
14 *   This function creates a floating point number f such that
15 *   f = d * 2 ^ e.
16 *
17 *****************************************************************/
18
19#include <float.h>
20#include "fdlibm.h"
21#include "zmath.h"
22
23#define FLOAT_EXP_OFFS 127
24
25float
26ldexpf (float d,
27        int e)
28{
29  int exp;
30  __int32_t wd;
31
32  GET_FLOAT_WORD (wd, d);
33
34  /* Check for special values and then scale d by e. */
35  switch (numtestf (wd))
36    {
37      case NAN:
38        errno = EDOM;
39        break;
40
41      case INF:
42        errno = ERANGE;
43        break;
44
45      case 0:
46        break;
47
48      default:
49        exp = (wd & 0x7f800000) >> 23;
50        exp += e;
51
52        if (exp > FLT_MAX_EXP + FLOAT_EXP_OFFS)
53         {
54           errno = ERANGE;
55           d = z_infinity_f.f;
56         }
57        else if (exp < FLT_MIN_EXP + FLOAT_EXP_OFFS)
58         {
59           errno = ERANGE;
60           d = -z_infinity_f.f;
61         }
62        else
63         {
64           wd &= 0x807fffff;
65           wd |= exp << 23;
66           SET_FLOAT_WORD (d, wd);
67         }
68    }
69
70    return (d);
71}
72
73#ifdef _DOUBLE_IS_32BITS
74
75double ldexp (double x, int e)
76{
77  return (double) ldexpf ((float) x, e);
78}
79
80#endif /* defined(_DOUBLE_IS_32BITS) */
Note: See TracBrowser for help on using the repository browser.