1 /* Floating point definitions for GDB.
3 Copyright (C) 1986, 1988-2001, 2003, 2005-2012 Free Software
6 This file is part of GDB.
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.
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.
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/>. */
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
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. */
37 #include "floatformat.h" /* For struct floatformat */
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.
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. */
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"
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
59 # undef HAVE_LONG_DOUBLE
60 # undef PRINTF_HAS_LONG_DOUBLE
61 # undef SCANF_HAS_LONG_DOUBLE
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). */
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);
80 extern int floatformat_is_negative (const struct floatformat *,
82 extern enum float_kind floatformat_classify (const struct floatformat *,
84 extern const char *floatformat_mantissa (const struct floatformat *,
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. */
91 const struct floatformat *floatformat_from_type (const struct type *type);
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,
97 extern void convert_typed_floating (const void *from,
98 const struct type *from_type,
99 void *to, const struct type *to_type);