]>
Commit | Line | Data |
---|---|---|
91873684 | 1 | /* Copyright (C) 1992, 1995, 1996, 1999 Free Software Foundation, Inc. |
6d52618b | 2 | This file is part of the GNU C Library. |
28f540f4 | 3 | |
6d52618b | 4 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
28f540f4 | 8 | |
6d52618b UD |
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 | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
28f540f4 | 13 | |
41bdb6e2 AJ |
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. */ | |
28f540f4 | 18 | |
6bc31da0 UD |
19 | #ifndef _IEEE754_H |
20 | ||
21 | #define _IEEE754_H 1 | |
22 | #include <features.h> | |
23 | ||
28f540f4 RM |
24 | #include <endian.h> |
25 | ||
6bc31da0 UD |
26 | __BEGIN_DECLS |
27 | ||
28f540f4 RM |
28 | union ieee754_float |
29 | { | |
30 | float f; | |
069aa638 | 31 | |
28f540f4 RM |
32 | /* This is the IEEE 754 single-precision format. */ |
33 | struct | |
34 | { | |
35 | #if __BYTE_ORDER == __BIG_ENDIAN | |
36 | unsigned int negative:1; | |
37 | unsigned int exponent:8; | |
38 | unsigned int mantissa:23; | |
39 | #endif /* Big endian. */ | |
40 | #if __BYTE_ORDER == __LITTLE_ENDIAN | |
41 | unsigned int mantissa:23; | |
42 | unsigned int exponent:8; | |
43 | unsigned int negative:1; | |
44 | #endif /* Little endian. */ | |
45 | } ieee; | |
46 | ||
47 | /* This format makes it easier to see if a NaN is a signalling NaN. */ | |
48 | struct | |
49 | { | |
50 | #if __BYTE_ORDER == __BIG_ENDIAN | |
51 | unsigned int negative:1; | |
52 | unsigned int exponent:8; | |
53 | unsigned int quiet_nan:1; | |
54 | unsigned int mantissa:22; | |
55 | #endif /* Big endian. */ | |
56 | #if __BYTE_ORDER == __LITTLE_ENDIAN | |
57 | unsigned int mantissa:22; | |
58 | unsigned int quiet_nan:1; | |
59 | unsigned int exponent:8; | |
60 | unsigned int negative:1; | |
61 | #endif /* Little endian. */ | |
62 | } ieee_nan; | |
63 | }; | |
64 | ||
65 | #define IEEE754_FLOAT_BIAS 0x7f /* Added to exponent. */ | |
66 | ||
67 | ||
68 | union ieee754_double | |
69 | { | |
70 | double d; | |
069aa638 | 71 | |
28f540f4 RM |
72 | /* This is the IEEE 754 double-precision format. */ |
73 | struct | |
74 | { | |
75 | #if __BYTE_ORDER == __BIG_ENDIAN | |
76 | unsigned int negative:1; | |
77 | unsigned int exponent:11; | |
78 | /* Together these comprise the mantissa. */ | |
79 | unsigned int mantissa0:20; | |
80 | unsigned int mantissa1:32; | |
81 | #endif /* Big endian. */ | |
82 | #if __BYTE_ORDER == __LITTLE_ENDIAN | |
91873684 UD |
83 | # if __FLOAT_WORD_ORDER == BIG_ENDIAN |
84 | unsigned int mantissa0:20; | |
85 | unsigned int exponent:11; | |
86 | unsigned int negative:1; | |
87 | unsigned int mantissa1:32; | |
88 | # else | |
28f540f4 RM |
89 | /* Together these comprise the mantissa. */ |
90 | unsigned int mantissa1:32; | |
91 | unsigned int mantissa0:20; | |
92 | unsigned int exponent:11; | |
93 | unsigned int negative:1; | |
91873684 | 94 | # endif |
28f540f4 RM |
95 | #endif /* Little endian. */ |
96 | } ieee; | |
97 | ||
98 | /* This format makes it easier to see if a NaN is a signalling NaN. */ | |
99 | struct | |
100 | { | |
101 | #if __BYTE_ORDER == __BIG_ENDIAN | |
102 | unsigned int negative:1; | |
103 | unsigned int exponent:11; | |
104 | unsigned int quiet_nan:1; | |
6d52618b | 105 | /* Together these comprise the mantissa. */ |
28f540f4 RM |
106 | unsigned int mantissa0:19; |
107 | unsigned int mantissa1:32; | |
108 | #else | |
91873684 UD |
109 | # if __FLOAT_WORD_ORDER == BIG_ENDIAN |
110 | unsigned int mantissa0:19; | |
111 | unsigned int quiet_nan:1; | |
112 | unsigned int exponent:11; | |
113 | unsigned int negative:1; | |
114 | unsigned int mantissa1:32; | |
115 | # else | |
6d52618b | 116 | /* Together these comprise the mantissa. */ |
28f540f4 RM |
117 | unsigned int mantissa1:32; |
118 | unsigned int mantissa0:19; | |
119 | unsigned int quiet_nan:1; | |
120 | unsigned int exponent:11; | |
121 | unsigned int negative:1; | |
91873684 | 122 | # endif |
28f540f4 RM |
123 | #endif |
124 | } ieee_nan; | |
125 | }; | |
126 | ||
127 | #define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */ | |
128 | ||
129 | ||
130 | union ieee854_long_double | |
131 | { | |
132 | long double d; | |
069aa638 | 133 | |
28f540f4 RM |
134 | /* This is the IEEE 854 double-extended-precision format. */ |
135 | struct | |
136 | { | |
137 | #if __BYTE_ORDER == __BIG_ENDIAN | |
138 | unsigned int negative:1; | |
139 | unsigned int exponent:15; | |
140 | unsigned int empty:16; | |
141 | unsigned int mantissa0:32; | |
142 | unsigned int mantissa1:32; | |
143 | #endif | |
144 | #if __BYTE_ORDER == __LITTLE_ENDIAN | |
91873684 UD |
145 | # if __FLOAT_WORD_ORDER == BIG_ENDIAN |
146 | unsigned int exponent:15; | |
147 | unsigned int negative:1; | |
148 | unsigned int empty:16; | |
149 | unsigned int mantissa0:32; | |
150 | unsigned int mantissa1:32; | |
151 | # else | |
28f540f4 RM |
152 | unsigned int mantissa1:32; |
153 | unsigned int mantissa0:32; | |
154 | unsigned int exponent:15; | |
155 | unsigned int negative:1; | |
156 | unsigned int empty:16; | |
91873684 | 157 | # endif |
28f540f4 RM |
158 | #endif |
159 | } ieee; | |
069aa638 | 160 | |
28f540f4 RM |
161 | /* This is for NaNs in the IEEE 854 double-extended-precision format. */ |
162 | struct | |
163 | { | |
164 | #if __BYTE_ORDER == __BIG_ENDIAN | |
165 | unsigned int negative:1; | |
166 | unsigned int exponent:15; | |
167 | unsigned int empty:16; | |
7176f4e4 | 168 | unsigned int one:1; |
28f540f4 | 169 | unsigned int quiet_nan:1; |
7176f4e4 | 170 | unsigned int mantissa0:30; |
28f540f4 RM |
171 | unsigned int mantissa1:32; |
172 | #endif | |
173 | #if __BYTE_ORDER == __LITTLE_ENDIAN | |
91873684 UD |
174 | # if __FLOAT_WORD_ORDER == BIG_ENDIAN |
175 | unsigned int exponent:15; | |
176 | unsigned int negative:1; | |
177 | unsigned int empty:16; | |
178 | unsigned int mantissa0:30; | |
179 | unsigned int quiet_nan:1; | |
180 | unsigned int one:1; | |
181 | unsigned int mantissa1:32; | |
182 | # else | |
28f540f4 | 183 | unsigned int mantissa1:32; |
7176f4e4 | 184 | unsigned int mantissa0:30; |
28f540f4 | 185 | unsigned int quiet_nan:1; |
069aa638 | 186 | unsigned int one:1; |
28f540f4 RM |
187 | unsigned int exponent:15; |
188 | unsigned int negative:1; | |
189 | unsigned int empty:16; | |
91873684 | 190 | # endif |
28f540f4 RM |
191 | #endif |
192 | } ieee_nan; | |
193 | }; | |
194 | ||
195 | #define IEEE854_LONG_DOUBLE_BIAS 0x3fff | |
6bc31da0 UD |
196 | |
197 | __END_DECLS | |
198 | ||
199 | #endif /* ieee754.h */ |