pthread-cond: Fix compilation error on native Windows.
[gnulib.git] / lib / ieee754.in.h
blob4dd0ff55d293b9f3e6c8cf561f718aec3bbd38a4
1 /* Copyright (C) 1992-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #ifndef _IEEE754_H
19 #define _IEEE754_H 1
21 #ifndef _GL_GNULIB_HEADER
22 /* Ordinary glibc usage. */
23 # include <features.h>
24 # include <bits/endian.h>
25 # define _IEEE754_BYTE_ORDER __BYTE_ORDER
26 # define _IEEE754_BIG_ENDIAN __BIG_ENDIAN
27 # define _IEEE754_LITTLE_ENDIAN __LITTLE_ENDIAN
28 # define _IEEE754_FLOAT_WORD_ORDER __FLOAT_WORD_ORDER
29 #else
30 /* Gnulib usage. */
31 # include <endian.h>
32 # define _IEEE754_BYTE_ORDER BYTE_ORDER
33 # define _IEEE754_BIG_ENDIAN BIG_ENDIAN
34 # define _IEEE754_LITTLE_ENDIAN LITTLE_ENDIAN
35 # define _IEEE754_FLOAT_WORD_ORDER BYTE_ORDER
36 #endif
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
42 union ieee754_float
44 float f;
46 /* This is the IEEE 754 single-precision format. */
47 struct
49 #if _IEEE754_BYTE_ORDER == _IEEE754_BIG_ENDIAN
50 unsigned int negative:1;
51 unsigned int exponent:8;
52 unsigned int mantissa:23;
53 #endif /* Big endian. */
54 #if _IEEE754_BYTE_ORDER == _IEEE754_LITTLE_ENDIAN
55 unsigned int mantissa:23;
56 unsigned int exponent:8;
57 unsigned int negative:1;
58 #endif /* Little endian. */
59 } ieee;
61 /* This format makes it easier to see if a NaN is a signalling NaN. */
62 struct
64 #if _IEEE754_BYTE_ORDER == _IEEE754_BIG_ENDIAN
65 unsigned int negative:1;
66 unsigned int exponent:8;
67 unsigned int quiet_nan:1;
68 unsigned int mantissa:22;
69 #endif /* Big endian. */
70 #if _IEEE754_BYTE_ORDER == _IEEE754_LITTLE_ENDIAN
71 unsigned int mantissa:22;
72 unsigned int quiet_nan:1;
73 unsigned int exponent:8;
74 unsigned int negative:1;
75 #endif /* Little endian. */
76 } ieee_nan;
79 #define IEEE754_FLOAT_BIAS 0x7f /* Added to exponent. */
82 union ieee754_double
84 double d;
86 /* This is the IEEE 754 double-precision format. */
87 struct
89 #if _IEEE754_BYTE_ORDER == _IEEE754_BIG_ENDIAN
90 unsigned int negative:1;
91 unsigned int exponent:11;
92 /* Together these comprise the mantissa. */
93 unsigned int mantissa0:20;
94 unsigned int mantissa1:32;
95 #endif /* Big endian. */
96 #if _IEEE754_BYTE_ORDER == _IEEE754_LITTLE_ENDIAN
97 # if _IEEE754_FLOAT_WORD_ORDER == _IEEE754_BIG_ENDIAN
98 unsigned int mantissa0:20;
99 unsigned int exponent:11;
100 unsigned int negative:1;
101 unsigned int mantissa1:32;
102 # else
103 /* Together these comprise the mantissa. */
104 unsigned int mantissa1:32;
105 unsigned int mantissa0:20;
106 unsigned int exponent:11;
107 unsigned int negative:1;
108 # endif
109 #endif /* Little endian. */
110 } ieee;
112 /* This format makes it easier to see if a NaN is a signalling NaN. */
113 struct
115 #if _IEEE754_BYTE_ORDER == _IEEE754_BIG_ENDIAN
116 unsigned int negative:1;
117 unsigned int exponent:11;
118 unsigned int quiet_nan:1;
119 /* Together these comprise the mantissa. */
120 unsigned int mantissa0:19;
121 unsigned int mantissa1:32;
122 #else
123 # if _IEEE754_FLOAT_WORD_ORDER == _IEEE754_BIG_ENDIAN
124 unsigned int mantissa0:19;
125 unsigned int quiet_nan:1;
126 unsigned int exponent:11;
127 unsigned int negative:1;
128 unsigned int mantissa1:32;
129 # else
130 /* Together these comprise the mantissa. */
131 unsigned int mantissa1:32;
132 unsigned int mantissa0:19;
133 unsigned int quiet_nan:1;
134 unsigned int exponent:11;
135 unsigned int negative:1;
136 # endif
137 #endif
138 } ieee_nan;
141 #define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */
144 union ieee854_long_double
146 long double d;
148 /* This is the IEEE 854 double-extended-precision format. */
149 struct
151 #if _IEEE754_BYTE_ORDER == _IEEE754_BIG_ENDIAN
152 unsigned int negative:1;
153 unsigned int exponent:15;
154 unsigned int empty:16;
155 unsigned int mantissa0:32;
156 unsigned int mantissa1:32;
157 #endif
158 #if _IEEE754_BYTE_ORDER == _IEEE754_LITTLE_ENDIAN
159 # if _IEEE754_FLOAT_WORD_ORDER == _IEEE754_BIG_ENDIAN
160 unsigned int exponent:15;
161 unsigned int negative:1;
162 unsigned int empty:16;
163 unsigned int mantissa0:32;
164 unsigned int mantissa1:32;
165 # else
166 unsigned int mantissa1:32;
167 unsigned int mantissa0:32;
168 unsigned int exponent:15;
169 unsigned int negative:1;
170 unsigned int empty:16;
171 # endif
172 #endif
173 } ieee;
175 /* This is for NaNs in the IEEE 854 double-extended-precision format. */
176 struct
178 #if _IEEE754_BYTE_ORDER == _IEEE754_BIG_ENDIAN
179 unsigned int negative:1;
180 unsigned int exponent:15;
181 unsigned int empty:16;
182 unsigned int one:1;
183 unsigned int quiet_nan:1;
184 unsigned int mantissa0:30;
185 unsigned int mantissa1:32;
186 #endif
187 #if _IEEE754_BYTE_ORDER == _IEEE754_LITTLE_ENDIAN
188 # if _IEEE754_FLOAT_WORD_ORDER == _IEEE754_BIG_ENDIAN
189 unsigned int exponent:15;
190 unsigned int negative:1;
191 unsigned int empty:16;
192 unsigned int mantissa0:30;
193 unsigned int quiet_nan:1;
194 unsigned int one:1;
195 unsigned int mantissa1:32;
196 # else
197 unsigned int mantissa1:32;
198 unsigned int mantissa0:30;
199 unsigned int quiet_nan:1;
200 unsigned int one:1;
201 unsigned int exponent:15;
202 unsigned int negative:1;
203 unsigned int empty:16;
204 # endif
205 #endif
206 } ieee_nan;
209 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff
211 #ifdef __cplusplus
213 #endif
215 #endif /* ieee754.h */