xref: /dflybsd-src/contrib/gdb-7/gdb/doublest.h (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* Floating point definitions for GDB.
25796c8dcSSimon Schubert 
3*ef5ccd6cSJohn Marino    Copyright (C) 1986-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert #ifndef DOUBLEST_H
215796c8dcSSimon Schubert #define DOUBLEST_H
225796c8dcSSimon Schubert 
235796c8dcSSimon Schubert struct type;
245796c8dcSSimon Schubert struct floatformat;
255796c8dcSSimon Schubert 
265796c8dcSSimon Schubert /* Setup definitions for host and target floating point formats.  We need to
275796c8dcSSimon Schubert    consider the format for `float', `double', and `long double' for both target
285796c8dcSSimon Schubert    and host.  We need to do this so that we know what kind of conversions need
295796c8dcSSimon Schubert    to be done when converting target numbers to and from the hosts DOUBLEST
305796c8dcSSimon Schubert    data type.  */
315796c8dcSSimon Schubert 
325796c8dcSSimon Schubert /* This is used to indicate that we don't know the format of the floating point
335796c8dcSSimon Schubert    number.  Typically, this is useful for native ports, where the actual format
345796c8dcSSimon Schubert    is irrelevant, since no conversions will be taking place.  */
355796c8dcSSimon Schubert 
365796c8dcSSimon Schubert #include "floatformat.h"	/* For struct floatformat */
375796c8dcSSimon Schubert 
385796c8dcSSimon Schubert /* Use `long double' if the host compiler supports it.  (Note that this is not
395796c8dcSSimon Schubert    necessarily any longer than `double'.  On SunOS/gcc, it's the same as
405796c8dcSSimon Schubert    double.)  This is necessary because GDB internally converts all floating
415796c8dcSSimon Schubert    point values to the widest type supported by the host.
425796c8dcSSimon Schubert 
435796c8dcSSimon Schubert    There are problems however, when the target `long double' is longer than the
445796c8dcSSimon Schubert    host's `long double'.  In general, we'll probably reduce the precision of
455796c8dcSSimon Schubert    any such values and print a warning.  */
465796c8dcSSimon Schubert 
475796c8dcSSimon Schubert #if (defined HAVE_LONG_DOUBLE && defined PRINTF_HAS_LONG_DOUBLE \
485796c8dcSSimon Schubert      && defined SCANF_HAS_LONG_DOUBLE)
495796c8dcSSimon Schubert typedef long double DOUBLEST;
505796c8dcSSimon Schubert # define DOUBLEST_PRINT_FORMAT "Lg"
515796c8dcSSimon Schubert # define DOUBLEST_SCAN_FORMAT "Lg"
525796c8dcSSimon Schubert #else
535796c8dcSSimon Schubert typedef double DOUBLEST;
545796c8dcSSimon Schubert # define DOUBLEST_PRINT_FORMAT "g"
555796c8dcSSimon Schubert # define DOUBLEST_SCAN_FORMAT "lg"
565796c8dcSSimon Schubert /* If we can't scan or print long double, we don't want to use it
575796c8dcSSimon Schubert    anywhere.  */
585796c8dcSSimon Schubert # undef HAVE_LONG_DOUBLE
595796c8dcSSimon Schubert # undef PRINTF_HAS_LONG_DOUBLE
605796c8dcSSimon Schubert # undef SCANF_HAS_LONG_DOUBLE
615796c8dcSSimon Schubert #endif
625796c8dcSSimon Schubert 
635796c8dcSSimon Schubert /* Different kinds of floatformat numbers recognized by
645796c8dcSSimon Schubert    floatformat_classify.  To avoid portability issues, we use local
655796c8dcSSimon Schubert    values instead of the C99 macros (FP_NAN et cetera).  */
665796c8dcSSimon Schubert enum float_kind {
675796c8dcSSimon Schubert   float_nan,
685796c8dcSSimon Schubert   float_infinite,
695796c8dcSSimon Schubert   float_zero,
705796c8dcSSimon Schubert   float_normal,
715796c8dcSSimon Schubert   float_subnormal
725796c8dcSSimon Schubert };
735796c8dcSSimon Schubert 
745796c8dcSSimon Schubert extern void floatformat_to_doublest (const struct floatformat *,
755796c8dcSSimon Schubert 				     const void *in, DOUBLEST *out);
765796c8dcSSimon Schubert extern void floatformat_from_doublest (const struct floatformat *,
775796c8dcSSimon Schubert 				       const DOUBLEST *in, void *out);
785796c8dcSSimon Schubert 
795796c8dcSSimon Schubert extern int floatformat_is_negative (const struct floatformat *,
805796c8dcSSimon Schubert 				    const bfd_byte *);
815796c8dcSSimon Schubert extern enum float_kind floatformat_classify (const struct floatformat *,
825796c8dcSSimon Schubert 					     const bfd_byte *);
835796c8dcSSimon Schubert extern const char *floatformat_mantissa (const struct floatformat *,
845796c8dcSSimon Schubert 					 const bfd_byte *);
855796c8dcSSimon Schubert 
865796c8dcSSimon Schubert /* Given TYPE, return its floatformat.  TYPE_FLOATFORMAT() may return
875796c8dcSSimon Schubert    NULL.  type_floatformat() detects that and returns a floatformat
885796c8dcSSimon Schubert    based on the type size when FLOATFORMAT is NULL.  */
895796c8dcSSimon Schubert 
905796c8dcSSimon Schubert const struct floatformat *floatformat_from_type (const struct type *type);
915796c8dcSSimon Schubert 
925796c8dcSSimon Schubert extern DOUBLEST extract_typed_floating (const void *addr,
935796c8dcSSimon Schubert 					const struct type *type);
945796c8dcSSimon Schubert extern void store_typed_floating (void *addr, const struct type *type,
955796c8dcSSimon Schubert 				  DOUBLEST val);
965796c8dcSSimon Schubert extern void convert_typed_floating (const void *from,
975796c8dcSSimon Schubert 				    const struct type *from_type,
985796c8dcSSimon Schubert                                     void *to, const struct type *to_type);
995796c8dcSSimon Schubert 
1005796c8dcSSimon Schubert #endif
101