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