1 | /* Copyright (C) 1992, 1995, 1996, 1999 Free Software Foundation, Inc.
|
---|
2 | This file is part of the GNU C Library.
|
---|
3 |
|
---|
4 | The GNU C Library is free software; you can redistribute it and/or
|
---|
5 | modify it under the terms of the GNU Lesser General Public
|
---|
6 | License as published by the Free Software Foundation; either
|
---|
7 | version 2.1 of the License, or (at your option) any later version.
|
---|
8 |
|
---|
9 | The GNU C Library is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
12 | Lesser General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU Lesser General Public
|
---|
15 | License along with the GNU C Library; if not, write to the Free
|
---|
16 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
---|
17 | 02111-1307 USA. */
|
---|
18 | /** @file
|
---|
19 | * GLIBC 2.3.x CVS
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef _IEEE754_H
|
---|
23 |
|
---|
24 | #define _IEEE754_H 1
|
---|
25 | #include <features.h>
|
---|
26 |
|
---|
27 | #include <endian.h>
|
---|
28 |
|
---|
29 | __BEGIN_DECLS
|
---|
30 |
|
---|
31 | union ieee754_float
|
---|
32 | {
|
---|
33 | float f;
|
---|
34 |
|
---|
35 | /* This is the IEEE 754 single-precision format. */
|
---|
36 | struct
|
---|
37 | {
|
---|
38 | #if __BYTE_ORDER == __BIG_ENDIAN
|
---|
39 | unsigned int negative:1;
|
---|
40 | unsigned int exponent:8;
|
---|
41 | unsigned int mantissa:23;
|
---|
42 | #endif /* Big endian. */
|
---|
43 | #if __BYTE_ORDER == __LITTLE_ENDIAN
|
---|
44 | unsigned int mantissa:23;
|
---|
45 | unsigned int exponent:8;
|
---|
46 | unsigned int negative:1;
|
---|
47 | #endif /* Little endian. */
|
---|
48 | } ieee;
|
---|
49 |
|
---|
50 | /* This format makes it easier to see if a NaN is a signalling NaN. */
|
---|
51 | struct
|
---|
52 | {
|
---|
53 | #if __BYTE_ORDER == __BIG_ENDIAN
|
---|
54 | unsigned int negative:1;
|
---|
55 | unsigned int exponent:8;
|
---|
56 | unsigned int quiet_nan:1;
|
---|
57 | unsigned int mantissa:22;
|
---|
58 | #endif /* Big endian. */
|
---|
59 | #if __BYTE_ORDER == __LITTLE_ENDIAN
|
---|
60 | unsigned int mantissa:22;
|
---|
61 | unsigned int quiet_nan:1;
|
---|
62 | unsigned int exponent:8;
|
---|
63 | unsigned int negative:1;
|
---|
64 | #endif /* Little endian. */
|
---|
65 | } ieee_nan;
|
---|
66 | };
|
---|
67 |
|
---|
68 | #define IEEE754_FLOAT_BIAS 0x7f /* Added to exponent. */
|
---|
69 |
|
---|
70 |
|
---|
71 | union ieee754_double
|
---|
72 | {
|
---|
73 | double d;
|
---|
74 |
|
---|
75 | /* This is the IEEE 754 double-precision format. */
|
---|
76 | struct
|
---|
77 | {
|
---|
78 | #if __BYTE_ORDER == __BIG_ENDIAN
|
---|
79 | unsigned int negative:1;
|
---|
80 | unsigned int exponent:11;
|
---|
81 | /* Together these comprise the mantissa. */
|
---|
82 | unsigned int mantissa0:20;
|
---|
83 | unsigned int mantissa1:32;
|
---|
84 | #endif /* Big endian. */
|
---|
85 | #if __BYTE_ORDER == __LITTLE_ENDIAN
|
---|
86 | # if __FLOAT_WORD_ORDER == BIG_ENDIAN
|
---|
87 | unsigned int mantissa0:20;
|
---|
88 | unsigned int exponent:11;
|
---|
89 | unsigned int negative:1;
|
---|
90 | unsigned int mantissa1:32;
|
---|
91 | # else
|
---|
92 | /* Together these comprise the mantissa. */
|
---|
93 | unsigned int mantissa1:32;
|
---|
94 | unsigned int mantissa0:20;
|
---|
95 | unsigned int exponent:11;
|
---|
96 | unsigned int negative:1;
|
---|
97 | # endif
|
---|
98 | #endif /* Little endian. */
|
---|
99 | } ieee;
|
---|
100 |
|
---|
101 | /* This format makes it easier to see if a NaN is a signalling NaN. */
|
---|
102 | struct
|
---|
103 | {
|
---|
104 | #if __BYTE_ORDER == __BIG_ENDIAN
|
---|
105 | unsigned int negative:1;
|
---|
106 | unsigned int exponent:11;
|
---|
107 | unsigned int quiet_nan:1;
|
---|
108 | /* Together these comprise the mantissa. */
|
---|
109 | unsigned int mantissa0:19;
|
---|
110 | unsigned int mantissa1:32;
|
---|
111 | #else
|
---|
112 | # if __FLOAT_WORD_ORDER == BIG_ENDIAN
|
---|
113 | unsigned int mantissa0:19;
|
---|
114 | unsigned int quiet_nan:1;
|
---|
115 | unsigned int exponent:11;
|
---|
116 | unsigned int negative:1;
|
---|
117 | unsigned int mantissa1:32;
|
---|
118 | # else
|
---|
119 | /* Together these comprise the mantissa. */
|
---|
120 | unsigned int mantissa1:32;
|
---|
121 | unsigned int mantissa0:19;
|
---|
122 | unsigned int quiet_nan:1;
|
---|
123 | unsigned int exponent:11;
|
---|
124 | unsigned int negative:1;
|
---|
125 | # endif
|
---|
126 | #endif
|
---|
127 | } ieee_nan;
|
---|
128 | };
|
---|
129 |
|
---|
130 | #define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */
|
---|
131 |
|
---|
132 |
|
---|
133 | union ieee854_long_double
|
---|
134 | {
|
---|
135 | long double d;
|
---|
136 |
|
---|
137 | /* This is the IEEE 854 double-extended-precision format. */
|
---|
138 | struct
|
---|
139 | {
|
---|
140 | #if __BYTE_ORDER == __BIG_ENDIAN
|
---|
141 | unsigned int negative:1;
|
---|
142 | unsigned int exponent:15;
|
---|
143 | unsigned int empty:16;
|
---|
144 | unsigned int mantissa0:32;
|
---|
145 | unsigned int mantissa1:32;
|
---|
146 | #endif
|
---|
147 | #if __BYTE_ORDER == __LITTLE_ENDIAN
|
---|
148 | # if __FLOAT_WORD_ORDER == BIG_ENDIAN
|
---|
149 | unsigned int exponent:15;
|
---|
150 | unsigned int negative:1;
|
---|
151 | unsigned int empty:16;
|
---|
152 | unsigned int mantissa0:32;
|
---|
153 | unsigned int mantissa1:32;
|
---|
154 | # else
|
---|
155 | unsigned int mantissa1:32;
|
---|
156 | unsigned int mantissa0:32;
|
---|
157 | unsigned int exponent:15;
|
---|
158 | unsigned int negative:1;
|
---|
159 | unsigned int empty:16;
|
---|
160 | # endif
|
---|
161 | #endif
|
---|
162 | } ieee;
|
---|
163 |
|
---|
164 | /* This is for NaNs in the IEEE 854 double-extended-precision format. */
|
---|
165 | struct
|
---|
166 | {
|
---|
167 | #if __BYTE_ORDER == __BIG_ENDIAN
|
---|
168 | unsigned int negative:1;
|
---|
169 | unsigned int exponent:15;
|
---|
170 | unsigned int empty:16;
|
---|
171 | unsigned int one:1;
|
---|
172 | unsigned int quiet_nan:1;
|
---|
173 | unsigned int mantissa0:30;
|
---|
174 | unsigned int mantissa1:32;
|
---|
175 | #endif
|
---|
176 | #if __BYTE_ORDER == __LITTLE_ENDIAN
|
---|
177 | # if __FLOAT_WORD_ORDER == BIG_ENDIAN
|
---|
178 | unsigned int exponent:15;
|
---|
179 | unsigned int negative:1;
|
---|
180 | unsigned int empty:16;
|
---|
181 | unsigned int mantissa0:30;
|
---|
182 | unsigned int quiet_nan:1;
|
---|
183 | unsigned int one:1;
|
---|
184 | unsigned int mantissa1:32;
|
---|
185 | # else
|
---|
186 | unsigned int mantissa1:32;
|
---|
187 | unsigned int mantissa0:30;
|
---|
188 | unsigned int quiet_nan:1;
|
---|
189 | unsigned int one:1;
|
---|
190 | unsigned int exponent:15;
|
---|
191 | unsigned int negative:1;
|
---|
192 | unsigned int empty:16;
|
---|
193 | # endif
|
---|
194 | #endif
|
---|
195 | } ieee_nan;
|
---|
196 | };
|
---|
197 |
|
---|
198 | #define IEEE854_LONG_DOUBLE_BIAS 0x3fff
|
---|
199 |
|
---|
200 | __END_DECLS
|
---|
201 |
|
---|
202 | #endif /* ieee754.h */
|
---|