1 /* Floating point definitions for GDB. 2 3 Copyright (C) 1986, 1988-2001, 2003, 2005-2012 Free Software 4 Foundation, Inc. 5 6 This file is part of GDB. 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 3 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20 21 #ifndef DOUBLEST_H 22 #define DOUBLEST_H 23 24 struct type; 25 struct floatformat; 26 27 /* Setup definitions for host and target floating point formats. We need to 28 consider the format for `float', `double', and `long double' for both target 29 and host. We need to do this so that we know what kind of conversions need 30 to be done when converting target numbers to and from the hosts DOUBLEST 31 data type. */ 32 33 /* This is used to indicate that we don't know the format of the floating point 34 number. Typically, this is useful for native ports, where the actual format 35 is irrelevant, since no conversions will be taking place. */ 36 37 #include "floatformat.h" /* For struct floatformat */ 38 39 /* Use `long double' if the host compiler supports it. (Note that this is not 40 necessarily any longer than `double'. On SunOS/gcc, it's the same as 41 double.) This is necessary because GDB internally converts all floating 42 point values to the widest type supported by the host. 43 44 There are problems however, when the target `long double' is longer than the 45 host's `long double'. In general, we'll probably reduce the precision of 46 any such values and print a warning. */ 47 48 #if (defined HAVE_LONG_DOUBLE && defined PRINTF_HAS_LONG_DOUBLE \ 49 && defined SCANF_HAS_LONG_DOUBLE) 50 typedef long double DOUBLEST; 51 # define DOUBLEST_PRINT_FORMAT "Lg" 52 # define DOUBLEST_SCAN_FORMAT "Lg" 53 #else 54 typedef double DOUBLEST; 55 # define DOUBLEST_PRINT_FORMAT "g" 56 # define DOUBLEST_SCAN_FORMAT "lg" 57 /* If we can't scan or print long double, we don't want to use it 58 anywhere. */ 59 # undef HAVE_LONG_DOUBLE 60 # undef PRINTF_HAS_LONG_DOUBLE 61 # undef SCANF_HAS_LONG_DOUBLE 62 #endif 63 64 /* Different kinds of floatformat numbers recognized by 65 floatformat_classify. To avoid portability issues, we use local 66 values instead of the C99 macros (FP_NAN et cetera). */ 67 enum float_kind { 68 float_nan, 69 float_infinite, 70 float_zero, 71 float_normal, 72 float_subnormal 73 }; 74 75 extern void floatformat_to_doublest (const struct floatformat *, 76 const void *in, DOUBLEST *out); 77 extern void floatformat_from_doublest (const struct floatformat *, 78 const DOUBLEST *in, void *out); 79 80 extern int floatformat_is_negative (const struct floatformat *, 81 const bfd_byte *); 82 extern enum float_kind floatformat_classify (const struct floatformat *, 83 const bfd_byte *); 84 extern const char *floatformat_mantissa (const struct floatformat *, 85 const bfd_byte *); 86 87 /* Given TYPE, return its floatformat. TYPE_FLOATFORMAT() may return 88 NULL. type_floatformat() detects that and returns a floatformat 89 based on the type size when FLOATFORMAT is NULL. */ 90 91 const struct floatformat *floatformat_from_type (const struct type *type); 92 93 extern DOUBLEST extract_typed_floating (const void *addr, 94 const struct type *type); 95 extern void store_typed_floating (void *addr, const struct type *type, 96 DOUBLEST val); 97 extern void convert_typed_floating (const void *from, 98 const struct type *from_type, 99 void *to, const struct type *to_type); 100 101 #endif 102