gdb/doublest.h - gdb

Data types defined

Macros defined

Source code

  1. /* Floating point definitions for GDB.

  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #ifndef DOUBLEST_H
  15. #define DOUBLEST_H

  16. struct type;
  17. struct floatformat;

  18. /* Setup definitions for host and target floating point formats.  We need to
  19.    consider the format for `float', `double', and `long double' for both target
  20.    and host.  We need to do this so that we know what kind of conversions need
  21.    to be done when converting target numbers to and from the hosts DOUBLEST
  22.    data type.  */

  23. /* This is used to indicate that we don't know the format of the floating point
  24.    number.  Typically, this is useful for native ports, where the actual format
  25.    is irrelevant, since no conversions will be taking place.  */

  26. #include "floatformat.h"        /* For struct floatformat */

  27. /* Use `long double' if the host compiler supports it.  (Note that this is not
  28.    necessarily any longer than `double'.  On SunOS/gcc, it's the same as
  29.    double.)  This is necessary because GDB internally converts all floating
  30.    point values to the widest type supported by the host.

  31.    There are problems however, when the target `long double' is longer than the
  32.    host's `long double'.  In general, we'll probably reduce the precision of
  33.    any such values and print a warning.  */

  34. #if (defined HAVE_LONG_DOUBLE && defined PRINTF_HAS_LONG_DOUBLE \
  35.      && defined SCANF_HAS_LONG_DOUBLE)
  36. typedef long double DOUBLEST;
  37. # define DOUBLEST_PRINT_FORMAT "Lg"
  38. # define DOUBLEST_SCAN_FORMAT "Lg"
  39. #else
  40. typedef double DOUBLEST;
  41. # define DOUBLEST_PRINT_FORMAT "g"
  42. # define DOUBLEST_SCAN_FORMAT "lg"
  43. /* If we can't scan or print long double, we don't want to use it
  44.    anywhere.  */
  45. # undef HAVE_LONG_DOUBLE
  46. # undef PRINTF_HAS_LONG_DOUBLE
  47. # undef SCANF_HAS_LONG_DOUBLE
  48. #endif

  49. /* Different kinds of floatformat numbers recognized by
  50.    floatformat_classify.  To avoid portability issues, we use local
  51.    values instead of the C99 macros (FP_NAN et cetera).  */
  52. enum float_kind {
  53.   float_nan,
  54.   float_infinite,
  55.   float_zero,
  56.   float_normal,
  57.   float_subnormal
  58. };

  59. extern void floatformat_to_doublest (const struct floatformat *,
  60.                                      const void *in, DOUBLEST *out);
  61. extern void floatformat_from_doublest (const struct floatformat *,
  62.                                        const DOUBLEST *in, void *out);

  63. extern int floatformat_is_negative (const struct floatformat *,
  64.                                     const bfd_byte *);
  65. extern enum float_kind floatformat_classify (const struct floatformat *,
  66.                                              const bfd_byte *);
  67. extern const char *floatformat_mantissa (const struct floatformat *,
  68.                                          const bfd_byte *);

  69. /* Given TYPE, return its floatformat.  TYPE_FLOATFORMAT() may return
  70.    NULL.  type_floatformat() detects that and returns a floatformat
  71.    based on the type size when FLOATFORMAT is NULL.  */

  72. const struct floatformat *floatformat_from_type (const struct type *type);

  73. extern DOUBLEST extract_typed_floating (const void *addr,
  74.                                         const struct type *type);
  75. extern void store_typed_floating (void *addr, const struct type *type,
  76.                                   DOUBLEST val);
  77. extern void convert_typed_floating (const void *from,
  78.                                     const struct type *from_type,
  79.                                     void *to, const struct type *to_type);

  80. #endif