Commit | Line | Data |
---|---|---|
d16aafd8 | 1 | /* Floating point definitions for GDB. |
f1908289 | 2 | |
0b302171 JB |
3 | Copyright (C) 1986, 1988-2001, 2003, 2005-2012 Free Software |
4 | Foundation, Inc. | |
d16aafd8 AC |
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 | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
d16aafd8 AC |
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 | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
d16aafd8 AC |
20 | |
21 | #ifndef DOUBLEST_H | |
22 | #define DOUBLEST_H | |
23 | ||
da3331ec | 24 | struct type; |
5ef2d0aa | 25 | struct floatformat; |
da3331ec | 26 | |
d16aafd8 AC |
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 | ||
d16aafd8 AC |
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 | ||
a6205f53 DJ |
48 | #if (defined HAVE_LONG_DOUBLE && defined PRINTF_HAS_LONG_DOUBLE \ |
49 | && defined SCANF_HAS_LONG_DOUBLE) | |
d16aafd8 | 50 | typedef long double DOUBLEST; |
689e4e2d TJB |
51 | # define DOUBLEST_PRINT_FORMAT "Lg" |
52 | # define DOUBLEST_SCAN_FORMAT "Lg" | |
d16aafd8 AC |
53 | #else |
54 | typedef double DOUBLEST; | |
689e4e2d TJB |
55 | # define DOUBLEST_PRINT_FORMAT "g" |
56 | # define DOUBLEST_SCAN_FORMAT "lg" | |
96c1eda2 AO |
57 | /* If we can't scan or print long double, we don't want to use it |
58 | anywhere. */ | |
59 | # undef HAVE_LONG_DOUBLE | |
a6205f53 DJ |
60 | # undef PRINTF_HAS_LONG_DOUBLE |
61 | # undef SCANF_HAS_LONG_DOUBLE | |
d16aafd8 AC |
62 | #endif |
63 | ||
20389057 DJ |
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 | ||
d16aafd8 | 75 | extern void floatformat_to_doublest (const struct floatformat *, |
64f6fcad | 76 | const void *in, DOUBLEST *out); |
d16aafd8 | 77 | extern void floatformat_from_doublest (const struct floatformat *, |
64f6fcad | 78 | const DOUBLEST *in, void *out); |
d16aafd8 | 79 | |
108d6ead AC |
80 | extern int floatformat_is_negative (const struct floatformat *, |
81 | const bfd_byte *); | |
20389057 DJ |
82 | extern enum float_kind floatformat_classify (const struct floatformat *, |
83 | const bfd_byte *); | |
108d6ead AC |
84 | extern const char *floatformat_mantissa (const struct floatformat *, |
85 | const bfd_byte *); | |
d16aafd8 | 86 | |
c2f05ac9 AC |
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 | ||
96d2f608 AC |
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); | |
43686d64 MK |
97 | extern void convert_typed_floating (const void *from, |
98 | const struct type *from_type, | |
99 | void *to, const struct type *to_type); | |
d16aafd8 AC |
100 | |
101 | #endif |