-
Notifications
You must be signed in to change notification settings - Fork 13
/
ieee754.h
75 lines (61 loc) · 1.25 KB
/
ieee754.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
#ifndef IEEE754_H
#define IEEE754_H
#ifdef __linux
#include <ieee754.h>
#else
union ieee754_float {
float f;
struct {
#if BYTE_ORDER == BIG_ENDIAN
unsigned int negative:1;
unsigned int exponent:8;
unsigned int mantissa:23;
#endif
#if BYTE_ORDER == LITTLE_ENDIAN
unsigned int mantissa:23;
unsigned int exponent:8;
unsigned int negative:1;
#endif
} ieee;
};
#define IEEE754_FLOAT_BIAS 0x7f
union ieee754_double {
double d;
struct {
#if BYTE_ORDER == BIG_ENDIAN
unsigned int negative:1;
unsigned int exponent:11;
unsigned int mantissa0:20;
unsigned int mantissa1:32;
#endif
#if BYTE_ORDER == LITTLE_ENDIAN
unsigned int mantissa1:32;
unsigned int mantissa0:20;
unsigned int exponent:11;
unsigned int negative:1;
#endif
} ieee;
};
#define IEEE754_DOUBLE_BIAS 0x3ff
union ieee854_long_double {
long double d;
struct {
#if BYTE_ORDER == BIG_ENDIAN
unsigned int negative:1;
unsigned int exponent:15;
unsigned int empty:16;
unsigned int mantissa0:32;
unsigned int mantissa1:32;
#endif
#if BYTE_ORDER == LITTLE_ENDIAN
unsigned int mantissa1:32;
unsigned int mantissa0:32;
unsigned int exponent:15;
unsigned int negative:1;
unsigned int empty:16;
#endif
} ieee;
};
#define IEEE854_LONG_DOUBLE_BIAS 0x3fff
#endif
#endif