1 /* auxiliary data to generate special IEEE floats (NaN, +Inf, -Inf) 2 3 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. 4 Contributed by the Arenaire and Caramel projects, INRIA. 5 6 This file is part of the GNU MPFR Library. 7 8 The GNU MPFR Library is free software; you can redistribute it and/or modify 9 it under the terms of the GNU Lesser General Public License as published by 10 the Free Software Foundation; either version 3 of the License, or (at your 11 option) any later version. 12 13 The GNU MPFR Library is distributed in the hope that it will be useful, but 14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 License for more details. 17 18 You should have received a copy of the GNU Lesser General Public License 19 along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see 20 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ 22 23 /* "double" NaN and infinities are written as explicit bytes to be sure of 24 getting what we want, and to be sure of not depending on libm. 25 26 Could use 4-byte "float" values and let the code convert them, but it 27 seems more direct to give exactly what we want. Certainly for gcc 3.0.2 28 on alphaev56-unknown-freebsd4.3 the NaN must be 8-bytes, since that 29 compiler+system was seen incorrectly converting from a "float" NaN. */ 30 31 #if _GMP_IEEE_FLOATS 32 33 /* The "d" field guarantees alignment to a suitable boundary for a double. 34 Could use a union instead, if we checked the compiler supports union 35 initializers. */ 36 union dbl_bytes { 37 unsigned char b[8]; 38 double d; 39 }; 40 41 #define MPFR_DBL_INFP (dbl_infp.d) 42 #define MPFR_DBL_INFM (dbl_infm.d) 43 #define MPFR_DBL_NAN (dbl_nan.d) 44 45 /* Warning! dbl_nan.d is not consistently the same NaN on all the 46 processors: it can be either a qNaN (quiet) or sNaN (signaling). 47 Processors are known to differ... */ 48 49 #if HAVE_DOUBLE_IEEE_LITTLE_ENDIAN 50 static const union dbl_bytes dbl_infp = 51 { { 0, 0, 0, 0, 0, 0, 0xF0, 0x7F } }; 52 static const union dbl_bytes dbl_infm = 53 { { 0, 0, 0, 0, 0, 0, 0xF0, 0xFF } }; 54 static const union dbl_bytes dbl_nan = 55 { { 0, 0, 0, 0, 0, 0, 0xF8, 0x7F } }; 56 #endif 57 #if HAVE_DOUBLE_IEEE_LITTLE_SWAPPED 58 static const union dbl_bytes dbl_infp = 59 { { 0, 0, 0xF0, 0x7F, 0, 0, 0, 0 } }; 60 static const union dbl_bytes dbl_infm = 61 { { 0, 0, 0xF0, 0xFF, 0, 0, 0, 0 } }; 62 static const union dbl_bytes dbl_nan = 63 { { 0, 0, 0xF8, 0x7F, 0, 0, 0, 0 } }; 64 #endif 65 #if HAVE_DOUBLE_IEEE_BIG_ENDIAN 66 static const union dbl_bytes dbl_infp = 67 { { 0x7F, 0xF0, 0, 0, 0, 0, 0, 0 } }; 68 static const union dbl_bytes dbl_infm = 69 { { 0xFF, 0xF0, 0, 0, 0, 0, 0, 0 } }; 70 static const union dbl_bytes dbl_nan = 71 { { 0x7F, 0xF8, 0, 0, 0, 0, 0, 0 } }; 72 #endif 73 74 #else /* _GMP_IEEE_FLOATS */ 75 76 #define MPFR_DBL_INFP DBL_POS_INF 77 #define MPFR_DBL_INFM DBL_NEG_INF 78 #define MPFR_DBL_NAN DBL_NAN 79 80 #endif /* _GMP_IEEE_FLOATS */ 81