Back to index

glibc  2.9
ieee754.h
Go to the documentation of this file.
00001 /* Copyright (C) 1992, 1995, 1996, 1999 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef _IEEE754_H
00020 
00021 #define _IEEE754_H 1
00022 #include <features.h>
00023 
00024 #include <endian.h>
00025 
00026 __BEGIN_DECLS
00027 
00028 union ieee754_float
00029   {
00030     float f;
00031 
00032     /* This is the IEEE 754 single-precision format.  */
00033     struct
00034       {
00035 #if    __BYTE_ORDER == __BIG_ENDIAN
00036        unsigned int negative:1;
00037        unsigned int exponent:8;
00038        unsigned int mantissa:23;
00039 #endif                      /* Big endian.  */
00040 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00041        unsigned int mantissa:23;
00042        unsigned int exponent:8;
00043        unsigned int negative:1;
00044 #endif                      /* Little endian.  */
00045       } ieee;
00046 
00047     /* This format makes it easier to see if a NaN is a signalling NaN.  */
00048     struct
00049       {
00050 #if    __BYTE_ORDER == __BIG_ENDIAN
00051        unsigned int negative:1;
00052        unsigned int exponent:8;
00053        unsigned int quiet_nan:1;
00054        unsigned int mantissa:22;
00055 #endif                      /* Big endian.  */
00056 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00057        unsigned int mantissa:22;
00058        unsigned int quiet_nan:1;
00059        unsigned int exponent:8;
00060        unsigned int negative:1;
00061 #endif                      /* Little endian.  */
00062       } ieee_nan;
00063   };
00064 
00065 #define IEEE754_FLOAT_BIAS  0x7f /* Added to exponent.  */
00066 
00067 
00068 union ieee754_double
00069   {
00070     double d;
00071 
00072     /* This is the IEEE 754 double-precision format.  */
00073     struct
00074       {
00075 #if    __BYTE_ORDER == __BIG_ENDIAN
00076        unsigned int negative:1;
00077        unsigned int exponent:11;
00078        /* Together these comprise the mantissa.  */
00079        unsigned int mantissa0:20;
00080        unsigned int mantissa1:32;
00081 #endif                      /* Big endian.  */
00082 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00083 # if   __FLOAT_WORD_ORDER == __BIG_ENDIAN
00084        unsigned int mantissa0:20;
00085        unsigned int exponent:11;
00086        unsigned int negative:1;
00087        unsigned int mantissa1:32;
00088 # else
00089        /* Together these comprise the mantissa.  */
00090        unsigned int mantissa1:32;
00091        unsigned int mantissa0:20;
00092        unsigned int exponent:11;
00093        unsigned int negative:1;
00094 # endif
00095 #endif                      /* Little endian.  */
00096       } ieee;
00097 
00098     /* This format makes it easier to see if a NaN is a signalling NaN.  */
00099     struct
00100       {
00101 #if    __BYTE_ORDER == __BIG_ENDIAN
00102        unsigned int negative:1;
00103        unsigned int exponent:11;
00104        unsigned int quiet_nan:1;
00105        /* Together these comprise the mantissa.  */
00106        unsigned int mantissa0:19;
00107        unsigned int mantissa1:32;
00108 #else
00109 # if   __FLOAT_WORD_ORDER == __BIG_ENDIAN
00110        unsigned int mantissa0:19;
00111        unsigned int quiet_nan:1;
00112        unsigned int exponent:11;
00113        unsigned int negative:1;
00114        unsigned int mantissa1:32;
00115 # else
00116        /* Together these comprise the mantissa.  */
00117        unsigned int mantissa1:32;
00118        unsigned int mantissa0:19;
00119        unsigned int quiet_nan:1;
00120        unsigned int exponent:11;
00121        unsigned int negative:1;
00122 # endif
00123 #endif
00124       } ieee_nan;
00125   };
00126 
00127 #define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent.  */
00128 
00129 
00130 union ieee854_long_double
00131   {
00132     long double d;
00133 
00134     /* This is the IEEE 854 double-extended-precision format.  */
00135     struct
00136       {
00137 #if    __BYTE_ORDER == __BIG_ENDIAN
00138        unsigned int negative:1;
00139        unsigned int exponent:15;
00140        unsigned int empty:16;
00141        unsigned int mantissa0:32;
00142        unsigned int mantissa1:32;
00143 #endif
00144 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00145 # if   __FLOAT_WORD_ORDER == __BIG_ENDIAN
00146        unsigned int exponent:15;
00147        unsigned int negative:1;
00148        unsigned int empty:16;
00149        unsigned int mantissa0:32;
00150        unsigned int mantissa1:32;
00151 # else
00152        unsigned int mantissa1:32;
00153        unsigned int mantissa0:32;
00154        unsigned int exponent:15;
00155        unsigned int negative:1;
00156        unsigned int empty:16;
00157 # endif
00158 #endif
00159       } ieee;
00160 
00161     /* This is for NaNs in the IEEE 854 double-extended-precision format.  */
00162     struct
00163       {
00164 #if    __BYTE_ORDER == __BIG_ENDIAN
00165        unsigned int negative:1;
00166        unsigned int exponent:15;
00167        unsigned int empty:16;
00168        unsigned int one:1;
00169        unsigned int quiet_nan:1;
00170        unsigned int mantissa0:30;
00171        unsigned int mantissa1:32;
00172 #endif
00173 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00174 # if   __FLOAT_WORD_ORDER == __BIG_ENDIAN
00175        unsigned int exponent:15;
00176        unsigned int negative:1;
00177        unsigned int empty:16;
00178        unsigned int mantissa0:30;
00179        unsigned int quiet_nan:1;
00180        unsigned int one:1;
00181        unsigned int mantissa1:32;
00182 # else
00183        unsigned int mantissa1:32;
00184        unsigned int mantissa0:30;
00185        unsigned int quiet_nan:1;
00186        unsigned int one:1;
00187        unsigned int exponent:15;
00188        unsigned int negative:1;
00189        unsigned int empty:16;
00190 # endif
00191 #endif
00192       } ieee_nan;
00193   };
00194 
00195 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff
00196 
00197 __END_DECLS
00198 
00199 #endif /* ieee754.h */