Update copyright notices with scripts/update-copyrights.
[jlayton/glibc.git] / sysdeps / ieee754 / ldbl-128ibm / ieee754.h
1 /* Copyright (C) 1992-2013 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, see
16    <http://www.gnu.org/licenses/>.  */
17
18 #ifndef _IEEE754_H
19
20 #define _IEEE754_H 1
21 #include <features.h>
22
23 #include <endian.h>
24
25 __BEGIN_DECLS
26
27 union ieee754_float
28   {
29     float f;
30
31     /* This is the IEEE 754 single-precision format.  */
32     struct
33       {
34 #if     __BYTE_ORDER == __BIG_ENDIAN
35         unsigned int negative:1;
36         unsigned int exponent:8;
37         unsigned int mantissa:23;
38 #endif                          /* Big endian.  */
39 #if     __BYTE_ORDER == __LITTLE_ENDIAN
40         unsigned int mantissa:23;
41         unsigned int exponent:8;
42         unsigned int negative:1;
43 #endif                          /* Little endian.  */
44       } ieee;
45
46     /* This format makes it easier to see if a NaN is a signalling NaN.  */
47     struct
48       {
49 #if     __BYTE_ORDER == __BIG_ENDIAN
50         unsigned int negative:1;
51         unsigned int exponent:8;
52         unsigned int quiet_nan:1;
53         unsigned int mantissa:22;
54 #endif                          /* Big endian.  */
55 #if     __BYTE_ORDER == __LITTLE_ENDIAN
56         unsigned int mantissa:22;
57         unsigned int quiet_nan:1;
58         unsigned int exponent:8;
59         unsigned int negative:1;
60 #endif                          /* Little endian.  */
61       } ieee_nan;
62   };
63
64 #define IEEE754_FLOAT_BIAS      0x7f /* Added to exponent.  */
65
66
67 union ieee754_double
68   {
69     double d;
70
71     /* This is the IEEE 754 double-precision format.  */
72     struct
73       {
74 #if     __BYTE_ORDER == __BIG_ENDIAN
75         unsigned int negative:1;
76         unsigned int exponent:11;
77         /* Together these comprise the mantissa.  */
78         unsigned int mantissa0:20;
79         unsigned int mantissa1:32;
80 #endif                          /* Big endian.  */
81 #if     __BYTE_ORDER == __LITTLE_ENDIAN
82         /* Together these comprise the mantissa.  */
83         unsigned int mantissa1:32;
84         unsigned int mantissa0:20;
85         unsigned int exponent:11;
86         unsigned int negative:1;
87 #endif                          /* Little endian.  */
88       } ieee;
89
90     /* This format makes it easier to see if a NaN is a signalling NaN.  */
91     struct
92       {
93 #if     __BYTE_ORDER == __BIG_ENDIAN
94         unsigned int negative:1;
95         unsigned int exponent:11;
96         unsigned int quiet_nan:1;
97         /* Together these comprise the mantissa.  */
98         unsigned int mantissa0:19;
99         unsigned int mantissa1:32;
100 #else
101         /* Together these comprise the mantissa.  */
102         unsigned int mantissa1:32;
103         unsigned int mantissa0:19;
104         unsigned int quiet_nan:1;
105         unsigned int exponent:11;
106         unsigned int negative:1;
107 #endif
108       } ieee_nan;
109   };
110
111 #define IEEE754_DOUBLE_BIAS     0x3ff /* Added to exponent.  */
112
113
114 union ieee854_long_double
115   {
116     long double d;
117
118     /* This is the IEEE 854 quad-precision format.  */
119     struct
120       {
121 #if     __BYTE_ORDER == __BIG_ENDIAN
122         unsigned int negative:1;
123         unsigned int exponent:15;
124         /* Together these comprise the mantissa.  */
125         unsigned int mantissa0:16;
126         unsigned int mantissa1:32;
127         unsigned int mantissa2:32;
128         unsigned int mantissa3:32;
129 #endif                          /* Big endian.  */
130 #if     __BYTE_ORDER == __LITTLE_ENDIAN
131         /* Together these comprise the mantissa.  */
132         unsigned int mantissa3:32;
133         unsigned int mantissa2:32;
134         unsigned int mantissa1:32;
135         unsigned int mantissa0:16;
136         unsigned int exponent:15;
137         unsigned int negative:1;
138 #endif                          /* Little endian.  */
139       } ieee;
140
141     /* This format makes it easier to see if a NaN is a signalling NaN.  */
142     struct
143       {
144 #if     __BYTE_ORDER == __BIG_ENDIAN
145         unsigned int negative:1;
146         unsigned int exponent:15;
147         unsigned int quiet_nan:1;
148         /* Together these comprise the mantissa.  */
149         unsigned int mantissa0:15;
150         unsigned int mantissa1:32;
151         unsigned int mantissa2:32;
152         unsigned int mantissa3:32;
153 #else
154         /* Together these comprise the mantissa.  */
155         unsigned int mantissa3:32;
156         unsigned int mantissa2:32;
157         unsigned int mantissa1:32;
158         unsigned int mantissa0:15;
159         unsigned int quiet_nan:1;
160         unsigned int exponent:15;
161         unsigned int negative:1;
162 #endif
163       } ieee_nan;
164   };
165
166 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff /* Added to exponent.  */
167
168
169 /* IBM extended format for long double.
170
171    Each long double is made up of two IEEE doubles.  The value of the
172    long double is the sum of the values of the two parts.  The most
173    significant part is required to be the value of the long double
174    rounded to the nearest double, as specified by IEEE.  For Inf
175    values, the least significant part is required to be one of +0.0 or
176    -0.0.  No other requirements are made; so, for example, 1.0 may be
177    represented as (1.0, +0.0) or (1.0, -0.0), and the low part of a
178    NaN is don't-care.  */
179
180 union ibm_extended_long_double
181   {
182     long double d;
183     double dd[2];
184
185     /* This is the IBM extended format long double.  */
186     struct
187       { /* Big endian.  There is no other.  */
188
189         unsigned int negative:1;
190         unsigned int exponent:11;
191         /* Together Mantissa0-3 comprise the mantissa.  */
192         unsigned int mantissa0:20;
193         unsigned int mantissa1:32;
194
195         unsigned int negative2:1;
196         unsigned int exponent2:11;
197         /* There is an implied 1 here?  */
198         /* Together these comprise the mantissa.  */
199         unsigned int mantissa2:20;
200         unsigned int mantissa3:32;
201       } ieee;
202    };
203
204 #define IBM_EXTENDED_LONG_DOUBLE_BIAS 0x3ff /* Added to exponent.  */
205
206 __END_DECLS
207
208 #endif /* ieee754.h */