| xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | /* Copyright (C) 1992-2016 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 | # if	__FLOAT_WORD_ORDER == __BIG_ENDIAN | 
|  | 83 | unsigned int mantissa0:20; | 
|  | 84 | unsigned int exponent:11; | 
|  | 85 | unsigned int negative:1; | 
|  | 86 | unsigned int mantissa1:32; | 
|  | 87 | # else | 
|  | 88 | /* Together these comprise the mantissa.  */ | 
|  | 89 | unsigned int mantissa1:32; | 
|  | 90 | unsigned int mantissa0:20; | 
|  | 91 | unsigned int exponent:11; | 
|  | 92 | unsigned int negative:1; | 
|  | 93 | # endif | 
|  | 94 | #endif				/* Little endian.  */ | 
|  | 95 | } ieee; | 
|  | 96 |  | 
|  | 97 | /* This format makes it easier to see if a NaN is a signalling NaN.  */ | 
|  | 98 | struct | 
|  | 99 | { | 
|  | 100 | #if	__BYTE_ORDER == __BIG_ENDIAN | 
|  | 101 | unsigned int negative:1; | 
|  | 102 | unsigned int exponent:11; | 
|  | 103 | unsigned int quiet_nan:1; | 
|  | 104 | /* Together these comprise the mantissa.  */ | 
|  | 105 | unsigned int mantissa0:19; | 
|  | 106 | unsigned int mantissa1:32; | 
|  | 107 | #else | 
|  | 108 | # if	__FLOAT_WORD_ORDER == __BIG_ENDIAN | 
|  | 109 | unsigned int mantissa0:19; | 
|  | 110 | unsigned int quiet_nan:1; | 
|  | 111 | unsigned int exponent:11; | 
|  | 112 | unsigned int negative:1; | 
|  | 113 | unsigned int mantissa1:32; | 
|  | 114 | # else | 
|  | 115 | /* Together these comprise the mantissa.  */ | 
|  | 116 | unsigned int mantissa1:32; | 
|  | 117 | unsigned int mantissa0:19; | 
|  | 118 | unsigned int quiet_nan:1; | 
|  | 119 | unsigned int exponent:11; | 
|  | 120 | unsigned int negative:1; | 
|  | 121 | # endif | 
|  | 122 | #endif | 
|  | 123 | } ieee_nan; | 
|  | 124 | }; | 
|  | 125 |  | 
|  | 126 | #define IEEE754_DOUBLE_BIAS	0x3ff /* Added to exponent.  */ | 
|  | 127 |  | 
|  | 128 |  | 
|  | 129 | union ieee854_long_double | 
|  | 130 | { | 
|  | 131 | long double d; | 
|  | 132 |  | 
|  | 133 | /* This is the IEEE 854 double-extended-precision format.  */ | 
|  | 134 | struct | 
|  | 135 | { | 
|  | 136 | #if	__BYTE_ORDER == __BIG_ENDIAN | 
|  | 137 | unsigned int negative:1; | 
|  | 138 | unsigned int exponent:15; | 
|  | 139 | unsigned int empty:16; | 
|  | 140 | unsigned int mantissa0:32; | 
|  | 141 | unsigned int mantissa1:32; | 
|  | 142 | #endif | 
|  | 143 | #if	__BYTE_ORDER == __LITTLE_ENDIAN | 
|  | 144 | # if	__FLOAT_WORD_ORDER == __BIG_ENDIAN | 
|  | 145 | unsigned int exponent:15; | 
|  | 146 | unsigned int negative:1; | 
|  | 147 | unsigned int empty:16; | 
|  | 148 | unsigned int mantissa0:32; | 
|  | 149 | unsigned int mantissa1:32; | 
|  | 150 | # else | 
|  | 151 | unsigned int mantissa1:32; | 
|  | 152 | unsigned int mantissa0:32; | 
|  | 153 | unsigned int exponent:15; | 
|  | 154 | unsigned int negative:1; | 
|  | 155 | unsigned int empty:16; | 
|  | 156 | # endif | 
|  | 157 | #endif | 
|  | 158 | } ieee; | 
|  | 159 |  | 
|  | 160 | /* This is for NaNs in the IEEE 854 double-extended-precision format.  */ | 
|  | 161 | struct | 
|  | 162 | { | 
|  | 163 | #if	__BYTE_ORDER == __BIG_ENDIAN | 
|  | 164 | unsigned int negative:1; | 
|  | 165 | unsigned int exponent:15; | 
|  | 166 | unsigned int empty:16; | 
|  | 167 | unsigned int one:1; | 
|  | 168 | unsigned int quiet_nan:1; | 
|  | 169 | unsigned int mantissa0:30; | 
|  | 170 | unsigned int mantissa1:32; | 
|  | 171 | #endif | 
|  | 172 | #if	__BYTE_ORDER == __LITTLE_ENDIAN | 
|  | 173 | # if	__FLOAT_WORD_ORDER == __BIG_ENDIAN | 
|  | 174 | unsigned int exponent:15; | 
|  | 175 | unsigned int negative:1; | 
|  | 176 | unsigned int empty:16; | 
|  | 177 | unsigned int mantissa0:30; | 
|  | 178 | unsigned int quiet_nan:1; | 
|  | 179 | unsigned int one:1; | 
|  | 180 | unsigned int mantissa1:32; | 
|  | 181 | # else | 
|  | 182 | unsigned int mantissa1:32; | 
|  | 183 | unsigned int mantissa0:30; | 
|  | 184 | unsigned int quiet_nan:1; | 
|  | 185 | unsigned int one:1; | 
|  | 186 | unsigned int exponent:15; | 
|  | 187 | unsigned int negative:1; | 
|  | 188 | unsigned int empty:16; | 
|  | 189 | # endif | 
|  | 190 | #endif | 
|  | 191 | } ieee_nan; | 
|  | 192 | }; | 
|  | 193 |  | 
|  | 194 | #define IEEE854_LONG_DOUBLE_BIAS 0x3fff | 
|  | 195 |  | 
|  | 196 | __END_DECLS | 
|  | 197 |  | 
|  | 198 | #endif /* ieee754.h */ |