forked from mirh/opemu-linux
-
Notifications
You must be signed in to change notification settings - Fork 1
/
opemu_math.h
79 lines (70 loc) · 1.51 KB
/
opemu_math.h
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
/* Needed unions */
typedef union
{
float value;
uint32_t word;
} ieee_float_shape_type;
typedef union
{
double value;
struct
{
uint32_t lsw;
uint32_t msw;
} parts;
} ieee_double_shape_type;
typedef union
{
long double value;
struct
{
uint64_t lsw;
uint64_t msw;
} parts;
} ieee_long_double_shape_type;
/* 32-bit (float) */
#define GET_FLOAT_WORD(i,d) \
do { \
ieee_float_shape_type gf_u; \
gf_u.value = (d); \
(i) = gf_u.word; \
} while (0)
#define SET_FLOAT_WORD(d,i) \
do { \
ieee_float_shape_type sf_u; \
sf_u.word = (i); \
(d) = sf_u.value; \
} while (0)
/* 64-bit (double) */
#define EXTRACT_WORDS(ix0,ix1,d) \
do { \
ieee_double_shape_type ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
} while (0)
#define INSERT_WORDS(d,ix0,ix1) \
do { \
ieee_double_shape_type iw_u; \
iw_u.parts.msw = (ix0); \
iw_u.parts.lsw = (ix1); \
(d) = iw_u.value; \
} while (0)
/* 128-bit (long double) */
#define GET_LDOUBLE_WORDS(ix0,ix1,d) \
do { \
ieee_long_double_shape_type qw_u; \
qw_u.value = (d); \
(ix0) = qw_u.parts.msw; \
(ix1) = qw_u.parts.lsw; \
} while (0)
#define SET_LDOUBLE_WORDS(d,ix0,ix1) \
do { \
ieee_long_double_shape_type qw_u; \
qw_u.parts.msw = (ix0); \
qw_u.parts.lsw = (ix1); \
(d) = qw_u.value; \
} while (0)
float opemu_truncf(float x);
double opemu_trunc(double x);
long double opemu_truncl(long double x);