[683] | 1 | /* Copyright (C) 1992, 1995, 1996 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 Library General Public License as
|
---|
| 6 | published by the Free Software Foundation; either version 2 of the
|
---|
| 7 | 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 | Library General Public License for more details.
|
---|
| 13 |
|
---|
| 14 | You should have received a copy of the GNU Library General Public
|
---|
| 15 | License along with the GNU C Library; see the file COPYING.LIB. If not,
|
---|
| 16 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
---|
| 17 | Boston, MA 02111-1307, USA. */
|
---|
| 18 |
|
---|
| 19 | #ifndef _IEEE754_H
|
---|
| 20 |
|
---|
| 21 | #define _IEEE754_H 1
|
---|
| 22 |
|
---|
| 23 | #define __LITTLE_ENDIAN 1
|
---|
| 24 | #define __BIG_ENDIAN 0
|
---|
| 25 | #define __BYTE_ORDER __BIG_ENDIAN
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | union ieee754_float
|
---|
| 29 | {
|
---|
| 30 | float f;
|
---|
| 31 |
|
---|
| 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;
|
---|
| 71 |
|
---|
| 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
|
---|
| 83 | /* Together these comprise the mantissa. */
|
---|
| 84 | unsigned int mantissa1:32;
|
---|
| 85 | unsigned int mantissa0:20;
|
---|
| 86 | unsigned int exponent:11;
|
---|
| 87 | unsigned int negative:1;
|
---|
| 88 | #endif /* Little endian. */
|
---|
| 89 | } ieee;
|
---|
| 90 |
|
---|
| 91 | /* This format makes it easier to see if a NaN is a signalling NaN. */
|
---|
| 92 | struct
|
---|
| 93 | {
|
---|
| 94 | #if __BYTE_ORDER == __BIG_ENDIAN
|
---|
| 95 | unsigned int negative:1;
|
---|
| 96 | unsigned int exponent:11;
|
---|
| 97 | unsigned int quiet_nan:1;
|
---|
| 98 | /* Together these comprise the mantissa. */
|
---|
| 99 | unsigned int mantissa0:19;
|
---|
| 100 | unsigned int mantissa1:32;
|
---|
| 101 | #else
|
---|
| 102 | /* Together these comprise the mantissa. */
|
---|
| 103 | unsigned int mantissa1:32;
|
---|
| 104 | unsigned int mantissa0:19;
|
---|
| 105 | unsigned int quiet_nan:1;
|
---|
| 106 | unsigned int exponent:11;
|
---|
| 107 | unsigned int negative:1;
|
---|
| 108 | #endif
|
---|
| 109 | } ieee_nan;
|
---|
| 110 | };
|
---|
| 111 |
|
---|
| 112 | #define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 | union ieee854_long_double
|
---|
| 116 | {
|
---|
| 117 | long double d;
|
---|
| 118 |
|
---|
| 119 | /* This is the IEEE 854 double-extended-precision format. */
|
---|
| 120 | struct
|
---|
| 121 | {
|
---|
| 122 | #if __BYTE_ORDER == __BIG_ENDIAN
|
---|
| 123 | unsigned int negative:1;
|
---|
| 124 | unsigned int exponent:15;
|
---|
| 125 | unsigned int empty:16;
|
---|
| 126 | unsigned int mantissa0:32;
|
---|
| 127 | unsigned int mantissa1:32;
|
---|
| 128 | #endif
|
---|
| 129 | #if __BYTE_ORDER == __LITTLE_ENDIAN
|
---|
| 130 | unsigned int mantissa1:32;
|
---|
| 131 | unsigned int mantissa0:32;
|
---|
| 132 | unsigned int exponent:15;
|
---|
| 133 | unsigned int negative:1;
|
---|
| 134 | unsigned int empty:16;
|
---|
| 135 | #endif
|
---|
| 136 | } ieee;
|
---|
| 137 |
|
---|
| 138 | /* This is for NaNs in the IEEE 854 double-extended-precision format. */
|
---|
| 139 | struct
|
---|
| 140 | {
|
---|
| 141 | #if __BYTE_ORDER == __BIG_ENDIAN
|
---|
| 142 | unsigned int negative:1;
|
---|
| 143 | unsigned int exponent:15;
|
---|
| 144 | unsigned int empty:16;
|
---|
| 145 | unsigned int one:1;
|
---|
| 146 | unsigned int quiet_nan:1;
|
---|
| 147 | unsigned int mantissa0:30;
|
---|
| 148 | unsigned int mantissa1:32;
|
---|
| 149 | #endif
|
---|
| 150 | #if __BYTE_ORDER == __LITTLE_ENDIAN
|
---|
| 151 | unsigned int mantissa1:32;
|
---|
| 152 | unsigned int mantissa0:30;
|
---|
| 153 | unsigned int quiet_nan:1;
|
---|
| 154 | unsigned int one:1;
|
---|
| 155 | unsigned int exponent:15;
|
---|
| 156 | unsigned int negative:1;
|
---|
| 157 | unsigned int empty:16;
|
---|
| 158 | #endif
|
---|
| 159 | } ieee_nan;
|
---|
| 160 | };
|
---|
| 161 |
|
---|
| 162 | #define IEEE854_LONG_DOUBLE_BIAS 0x3fff
|
---|
| 163 |
|
---|
| 164 |
|
---|
| 165 | #endif /* ieee754.h */
|
---|