Merge from mainline
[official-gcc.git] / libgcc-math / include / ieee754.h
blob30b1ac50c2d69a4681a911723e349d20911bda30
1 /* Copyright (C) 1992, 1995, 1996, 1999, 2006 Free Software Foundation, Inc.
3 This file is part of GCC.
5 GCC is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version.
10 In addition to the permissions in the GNU General Public License, the
11 Free Software Foundation gives you unlimited permission to link the
12 compiled version of this file into combinations with other programs,
13 and to distribute those combinations without any restriction coming
14 from the use of this file. (The General Public License restrictions
15 do apply in other respects; for example, they cover modification of
16 the file, and distribution when not linked into a combine
17 executable.)
19 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
20 WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
24 You should have received a copy of the GNU General Public License
25 along with GCC; see the file COPYING. If not, write to the Free
26 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
27 02110-1301, USA. */
29 #ifndef _IEEE754_H
31 #define _IEEE754_H 1
32 #include <endian.h>
34 union ieee754_float
36 float f;
38 /* This is the IEEE 754 single-precision format. */
39 struct
41 #if __BYTE_ORDER == __BIG_ENDIAN
42 unsigned int negative:1;
43 unsigned int exponent:8;
44 unsigned int mantissa:23;
45 #endif /* Big endian. */
46 #if __BYTE_ORDER == __LITTLE_ENDIAN
47 unsigned int mantissa:23;
48 unsigned int exponent:8;
49 unsigned int negative:1;
50 #endif /* Little endian. */
51 } ieee;
53 /* This format makes it easier to see if a NaN is a signalling NaN. */
54 struct
56 #if __BYTE_ORDER == __BIG_ENDIAN
57 unsigned int negative:1;
58 unsigned int exponent:8;
59 unsigned int quiet_nan:1;
60 unsigned int mantissa:22;
61 #endif /* Big endian. */
62 #if __BYTE_ORDER == __LITTLE_ENDIAN
63 unsigned int mantissa:22;
64 unsigned int quiet_nan:1;
65 unsigned int exponent:8;
66 unsigned int negative:1;
67 #endif /* Little endian. */
68 } ieee_nan;
71 #define IEEE754_FLOAT_BIAS 0x7f /* Added to exponent. */
74 union ieee754_double
76 double d;
78 /* This is the IEEE 754 double-precision format. */
79 struct
81 #if __BYTE_ORDER == __BIG_ENDIAN
82 unsigned int negative:1;
83 unsigned int exponent:11;
84 /* Together these comprise the mantissa. */
85 unsigned int mantissa0:20;
86 unsigned int mantissa1:32;
87 #endif /* Big endian. */
88 #if __BYTE_ORDER == __LITTLE_ENDIAN
89 # if __FLOAT_WORD_ORDER == BIG_ENDIAN
90 unsigned int mantissa0:20;
91 unsigned int exponent:11;
92 unsigned int negative:1;
93 unsigned int mantissa1:32;
94 # else
95 /* Together these comprise the mantissa. */
96 unsigned int mantissa1:32;
97 unsigned int mantissa0:20;
98 unsigned int exponent:11;
99 unsigned int negative:1;
100 # endif
101 #endif /* Little endian. */
102 } ieee;
104 /* This format makes it easier to see if a NaN is a signalling NaN. */
105 struct
107 #if __BYTE_ORDER == __BIG_ENDIAN
108 unsigned int negative:1;
109 unsigned int exponent:11;
110 unsigned int quiet_nan:1;
111 /* Together these comprise the mantissa. */
112 unsigned int mantissa0:19;
113 unsigned int mantissa1:32;
114 #else
115 # if __FLOAT_WORD_ORDER == BIG_ENDIAN
116 unsigned int mantissa0:19;
117 unsigned int quiet_nan:1;
118 unsigned int exponent:11;
119 unsigned int negative:1;
120 unsigned int mantissa1:32;
121 # else
122 /* Together these comprise the mantissa. */
123 unsigned int mantissa1:32;
124 unsigned int mantissa0:19;
125 unsigned int quiet_nan:1;
126 unsigned int exponent:11;
127 unsigned int negative:1;
128 # endif
129 #endif
130 } ieee_nan;
133 #define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */
136 #endif /* ieee754.h */