Back to index

glibc  2.9
ieee754.h
Go to the documentation of this file.
00001 /* Copyright (C) 1992, 1995, 1996, 1999, 2002, 2003
00002        Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _IEEE754_H
00021 
00022 #define _IEEE754_H 1
00023 #include <features.h>
00024 
00025 #include <endian.h>
00026 
00027 #include <float.h>
00028 
00029 __BEGIN_DECLS
00030 
00031 union ieee754_float
00032   {
00033     float f;
00034 
00035     /* This is the IEEE 754 single-precision format.  */
00036     struct
00037       {
00038 #if    __BYTE_ORDER == __BIG_ENDIAN
00039        unsigned int negative:1;
00040        unsigned int exponent:8;
00041        unsigned int mantissa:23;
00042 #endif                      /* Big endian.  */
00043 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00044        unsigned int mantissa:23;
00045        unsigned int exponent:8;
00046        unsigned int negative:1;
00047 #endif                      /* Little endian.  */
00048       } ieee;
00049 
00050     /* This format makes it easier to see if a NaN is a signalling NaN.  */
00051     struct
00052       {
00053 #if    __BYTE_ORDER == __BIG_ENDIAN
00054        unsigned int negative:1;
00055        unsigned int exponent:8;
00056        unsigned int quiet_nan:1;
00057        unsigned int mantissa:22;
00058 #endif                      /* Big endian.  */
00059 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00060        unsigned int mantissa:22;
00061        unsigned int quiet_nan:1;
00062        unsigned int exponent:8;
00063        unsigned int negative:1;
00064 #endif                      /* Little endian.  */
00065       } ieee_nan;
00066   };
00067 
00068 #define IEEE754_FLOAT_BIAS  0x7f /* Added to exponent.  */
00069 
00070 
00071 union ieee754_double
00072   {
00073     double d;
00074 
00075     /* This is the IEEE 754 double-precision format.  */
00076     struct
00077       {
00078 #if    __BYTE_ORDER == __BIG_ENDIAN
00079        unsigned int negative:1;
00080        unsigned int exponent:11;
00081        /* Together these comprise the mantissa.  */
00082        unsigned int mantissa0:20;
00083        unsigned int mantissa1:32;
00084 #endif                      /* Big endian.  */
00085 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00086 # if   __FLOAT_WORD_ORDER == __BIG_ENDIAN
00087        unsigned int mantissa0:20;
00088        unsigned int exponent:11;
00089        unsigned int negative:1;
00090        unsigned int mantissa1:32;
00091 # else
00092        /* Together these comprise the mantissa.  */
00093        unsigned int mantissa1:32;
00094        unsigned int mantissa0:20;
00095        unsigned int exponent:11;
00096        unsigned int negative:1;
00097 # endif
00098 #endif                      /* Little endian.  */
00099       } ieee;
00100 
00101     /* This format makes it easier to see if a NaN is a signalling NaN.  */
00102     struct
00103       {
00104 #if    __BYTE_ORDER == __BIG_ENDIAN
00105        unsigned int negative:1;
00106        unsigned int exponent:11;
00107        unsigned int quiet_nan:1;
00108        /* Together these comprise the mantissa.  */
00109        unsigned int mantissa0:19;
00110        unsigned int mantissa1:32;
00111 #else
00112 # if   __FLOAT_WORD_ORDER == __BIG_ENDIAN
00113        unsigned int mantissa0:19;
00114        unsigned int quiet_nan:1;
00115        unsigned int exponent:11;
00116        unsigned int negative:1;
00117        unsigned int mantissa1:32;
00118 # else
00119        /* Together these comprise the mantissa.  */
00120        unsigned int mantissa1:32;
00121        unsigned int mantissa0:19;
00122        unsigned int quiet_nan:1;
00123        unsigned int exponent:11;
00124        unsigned int negative:1;
00125 # endif
00126 #endif
00127       } ieee_nan;
00128   };
00129 
00130 #define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent.  */
00131 
00132 #if LDBL_MANT_DIG == 113
00133 
00134 union ieee854_long_double
00135   {
00136     long double d;
00137 
00138     /* This is the IEEE 854 quad-precision format.  */
00139     struct
00140       {
00141 #if    __BYTE_ORDER == __BIG_ENDIAN
00142        unsigned int negative:1;
00143        unsigned int exponent:15;
00144        /* Together these comprise the mantissa.  */
00145        unsigned int mantissa0:16;
00146        unsigned int mantissa1:32;
00147        unsigned int mantissa2:32;
00148        unsigned int mantissa3:32;
00149 #endif                      /* Big endian.  */
00150 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00151        /* Together these comprise the mantissa.  */
00152        unsigned int mantissa3:32;
00153        unsigned int mantissa2:32;
00154        unsigned int mantissa1:32;
00155        unsigned int mantissa0:16;
00156        unsigned int exponent:15;
00157        unsigned int negative:1;
00158 #endif                      /* Little endian.  */
00159       } ieee;
00160 
00161     /* This format makes it easier to see if a NaN is a signalling NaN.  */
00162     struct
00163       {
00164 #if    __BYTE_ORDER == __BIG_ENDIAN
00165        unsigned int negative:1;
00166        unsigned int exponent:15;
00167        unsigned int quiet_nan:1;
00168        /* Together these comprise the mantissa.  */
00169        unsigned int mantissa0:15;
00170        unsigned int mantissa1:32;
00171        unsigned int mantissa2:32;
00172        unsigned int mantissa3:32;
00173 #endif                      /* Big endian.  */
00174 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00175        /* Together these comprise the mantissa.  */
00176        unsigned int mantissa3:32;
00177        unsigned int mantissa2:32;
00178        unsigned int mantissa1:32;
00179        unsigned int mantissa0:15;
00180        unsigned int quiet_nan:1;
00181        unsigned int exponent:15;
00182        unsigned int negative:1;
00183 #endif                      /* Little endian.  */
00184       } ieee_nan;
00185   };
00186 
00187 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff /* Added to exponent.  */
00188 
00189 #elif LDBL_MANT_DIG == 64
00190 
00191 union ieee854_long_double
00192   {
00193     long double d;
00194 
00195     /* This is the IEEE 854 double-extended-precision format.  */
00196     struct
00197       {
00198 #if    __BYTE_ORDER == __BIG_ENDIAN
00199        unsigned int negative:1;
00200        unsigned int exponent:15;
00201        unsigned int empty:16;
00202        unsigned int mantissa0:32;
00203        unsigned int mantissa1:32;
00204 #endif
00205 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00206 # if   __FLOAT_WORD_ORDER == __BIG_ENDIAN
00207        unsigned int exponent:15;
00208        unsigned int negative:1;
00209        unsigned int empty:16;
00210        unsigned int mantissa0:32;
00211        unsigned int mantissa1:32;
00212 # else
00213        unsigned int mantissa1:32;
00214        unsigned int mantissa0:32;
00215        unsigned int exponent:15;
00216        unsigned int negative:1;
00217        unsigned int empty:16;
00218 # endif
00219 #endif
00220       } ieee;
00221 
00222     /* This is for NaNs in the IEEE 854 double-extended-precision format.  */
00223     struct
00224       {
00225 #if    __BYTE_ORDER == __BIG_ENDIAN
00226        unsigned int negative:1;
00227        unsigned int exponent:15;
00228        unsigned int empty:16;
00229        unsigned int one:1;
00230        unsigned int quiet_nan:1;
00231        unsigned int mantissa0:30;
00232        unsigned int mantissa1:32;
00233 #endif
00234 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00235 # if   __FLOAT_WORD_ORDER == __BIG_ENDIAN
00236        unsigned int exponent:15;
00237        unsigned int negative:1;
00238        unsigned int empty:16;
00239        unsigned int mantissa0:30;
00240        unsigned int quiet_nan:1;
00241        unsigned int one:1;
00242        unsigned int mantissa1:32;
00243 # else
00244        unsigned int mantissa1:32;
00245        unsigned int mantissa0:30;
00246        unsigned int quiet_nan:1;
00247        unsigned int one:1;
00248        unsigned int exponent:15;
00249        unsigned int negative:1;
00250        unsigned int empty:16;
00251 # endif
00252 #endif
00253       } ieee_nan;
00254   };
00255 
00256 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff
00257 
00258 #elif LDBL_MANT_DIG == 53
00259 
00260 union ieee854_long_double
00261   {
00262     long double d;
00263 
00264     /* This is the IEEE 754 double-precision format.  */
00265     struct
00266       {
00267 #if    __BYTE_ORDER == __BIG_ENDIAN
00268        unsigned int negative:1;
00269        unsigned int exponent:11;
00270        /* Together these comprise the mantissa.  */
00271        unsigned int mantissa0:20;
00272        unsigned int mantissa1:32;
00273 #endif                      /* Big endian.  */
00274 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00275 # if   __FLOAT_WORD_ORDER == __BIG_ENDIAN
00276        unsigned int mantissa0:20;
00277        unsigned int exponent:11;
00278        unsigned int negative:1;
00279        unsigned int mantissa1:32;
00280 # else
00281        /* Together these comprise the mantissa.  */
00282        unsigned int mantissa1:32;
00283        unsigned int mantissa0:20;
00284        unsigned int exponent:11;
00285        unsigned int negative:1;
00286 # endif
00287 #endif                      /* Little endian.  */
00288       } ieee;
00289 
00290     /* This format makes it easier to see if a NaN is a signalling NaN.  */
00291     struct
00292       {
00293 #if    __BYTE_ORDER == __BIG_ENDIAN
00294        unsigned int negative:1;
00295        unsigned int exponent:11;
00296        unsigned int quiet_nan:1;
00297        /* Together these comprise the mantissa.  */
00298        unsigned int mantissa0:19;
00299        unsigned int mantissa1:32;
00300 #else
00301 # if   __FLOAT_WORD_ORDER == __BIG_ENDIAN
00302        unsigned int mantissa0:19;
00303        unsigned int quiet_nan:1;
00304        unsigned int exponent:11;
00305        unsigned int negative:1;
00306        unsigned int mantissa1:32;
00307 # else
00308        /* Together these comprise the mantissa.  */
00309        unsigned int mantissa1:32;
00310        unsigned int mantissa0:19;
00311        unsigned int quiet_nan:1;
00312        unsigned int exponent:11;
00313        unsigned int negative:1;
00314 # endif
00315 #endif
00316       } ieee_nan;
00317   };
00318 
00319 #define IEEE854_LONG_DOUBLE_BIAS   0x3ff /* Added to exponent.  */
00320 
00321 #endif /* LDBL_MANT_DIG == 53 */
00322 
00323 __END_DECLS
00324 
00325 #endif /* ieee754.h */