22#include "floatformat.h"
38 const char *format)
const = 0;
40 const std::string &
string)
const = 0;
45 LONGEST val)
const = 0;
47 ULONGEST val)
const = 0;
51 double val)
const = 0;
52 virtual void convert (
const gdb_byte *from,
const struct type *from_type,
53 gdb_byte *to,
const struct type *to_type)
const = 0;
56 const gdb_byte *x,
const struct type *type_x,
57 const gdb_byte *y,
const struct type *type_y,
58 gdb_byte *res,
const struct type *type_res)
const = 0;
59 virtual int compare (
const gdb_byte *x,
const struct type *type_x,
60 const gdb_byte *y,
const struct type *type_y)
const = 0;
83#define FLOATFORMAT_CHAR_BIT 8
87#define FLOATFORMAT_LARGEST_BYTES 16
108 int prec = fmt->man_len;
109 if (fmt->intbit == floatformat_intbit_no)
118static enum floatformat_byteorders
120 const void *from,
void *to)
122 const unsigned char *swapin;
123 unsigned char *swapout;
126 if (fmt->byteorder == floatformat_little
127 || fmt->byteorder == floatformat_big)
128 return fmt->byteorder;
133 swapout = (
unsigned char *)to;
134 swapin = (
const unsigned char *)from;
136 if (fmt->byteorder == floatformat_vax)
140 *swapout++ = swapin[1];
141 *swapout++ = swapin[0];
142 *swapout++ = swapin[3];
143 *swapout++ = swapin[2];
148 return floatformat_big;
152 gdb_assert (fmt->byteorder == floatformat_littlebyte_bigword);
156 *swapout++ = swapin[3];
157 *swapout++ = swapin[2];
158 *swapout++ = swapin[1];
159 *swapout++ = swapin[0];
162 return floatformat_big;
169get_field (
const bfd_byte *data,
enum floatformat_byteorders order,
170 unsigned int total_len,
unsigned int start,
unsigned int len)
172 unsigned long result;
173 unsigned int cur_byte;
177 gdb_assert (order == floatformat_little || order == floatformat_big);
180 if (order == floatformat_little)
203 result = *(data + cur_byte) >> (-cur_bitshift);
207 if (order == floatformat_little)
213 while (cur_bitshift < len)
215 result |= (
unsigned long)*(data + cur_byte) << cur_bitshift;
219 case floatformat_little:
222 case floatformat_big:
229 result &= ((1UL << len) - 1);
236put_field (
unsigned char *data,
enum floatformat_byteorders order,
237 unsigned int total_len,
unsigned int start,
unsigned int len,
238 unsigned long stuff_to_put)
240 unsigned int cur_byte;
244 gdb_assert (order == floatformat_little || order == floatformat_big);
247 if (order == floatformat_little)
264 *(data + cur_byte) &=
267 *(data + cur_byte) |=
271 if (order == floatformat_little)
277 while (cur_bitshift < len)
282 *(data + cur_byte) &=
283 ~((1 << (len - cur_bitshift)) - 1);
284 *(data + cur_byte) |= (stuff_to_put >> cur_bitshift);
287 *(data + cur_byte) = ((stuff_to_put >> cur_bitshift)
290 if (order == floatformat_little)
301 const bfd_byte *uval)
303 enum floatformat_byteorders order;
306 gdb_assert (fmt != NULL);
307 gdb_assert (fmt->totalsize
313 fmt = fmt->split_half;
317 if (order != fmt->byteorder)
320 return get_field (uval, order, fmt->totalsize, fmt->sign_start, 1);
326 const bfd_byte *uval)
330 unsigned int mant_bits, mant_off;
332 enum floatformat_byteorders order;
336 gdb_assert (fmt != NULL);
337 gdb_assert (fmt->totalsize
345 fmt = fmt->split_half;
349 if (order != fmt->byteorder)
352 exponent =
get_field (uval, order, fmt->totalsize, fmt->exp_start,
355 mant_bits_left = fmt->man_len;
356 mant_off = fmt->man_start;
359 while (mant_bits_left > 0)
361 mant_bits = std::min (mant_bits_left, 32);
363 mant =
get_field (uval, order, fmt->totalsize, mant_off, mant_bits);
366 if (mant_off == fmt->man_start
367 && fmt->intbit == floatformat_intbit_yes)
368 mant &= ~(1 << (mant_bits - 1));
376 mant_off += mant_bits;
377 mant_bits_left -= mant_bits;
398 if (exponent == fmt->exp_nan)
416 unsigned char *uval = (
unsigned char *) val;
418 unsigned int mant_bits, mant_off;
423 enum floatformat_byteorders order;
426 gdb_assert (fmt != NULL);
427 gdb_assert (fmt->totalsize
438 fmt = fmt->split_half;
442 if (order != fmt->byteorder)
449 gdb_assert (
sizeof res > ((fmt->man_len + 7) / 8) * 2);
451 mant_off = fmt->man_start;
452 mant_bits_left = fmt->man_len;
453 mant_bits = (mant_bits_left % 32) > 0 ? mant_bits_left % 32 : 32;
455 mant =
get_field (uval, order, fmt->totalsize, mant_off, mant_bits);
457 len = xsnprintf (res,
sizeof res,
"%lx", mant);
459 mant_off += mant_bits;
460 mant_bits_left -= mant_bits;
462 while (mant_bits_left > 0)
464 mant =
get_field (uval, order, fmt->totalsize, mant_off, 32);
466 xsnprintf (buf,
sizeof buf,
"%08lx", mant);
467 gdb_assert (len + strlen (buf) <=
sizeof res);
471 mant_bits_left -= 32;
484 const char *format,
char length)
486 std::string host_format;
489 if (format ==
nullptr)
499 const double log10_2 = .30102999566398119521;
501 int decimal_dig = d_decimal_dig;
502 if (decimal_dig < d_decimal_dig)
505 host_format = string_printf (
"%%.%d", decimal_dig);
512 size_t len = strlen (format);
513 gdb_assert (len > 1);
514 conversion = format[--len];
515 gdb_assert (conversion ==
'e' || conversion ==
'f' || conversion ==
'g'
516 || conversion ==
'E' || conversion ==
'G');
517 if (format[len - 1] ==
'L')
520 host_format = std::string (format, len);
526 host_format += length;
527 host_format += conversion;
539 const char *format)
const override;
541 const std::string &
string)
const override;
544 const struct type *
type)
const override;
546 LONGEST val)
const override;
548 ULONGEST val)
const override;
550 const struct type *
type)
const override;
552 double val)
const override;
553 void convert (
const gdb_byte *from,
const struct type *from_type,
554 gdb_byte *to,
const struct type *to_type)
const override;
557 const gdb_byte *x,
const struct type *type_x,
558 const gdb_byte *y,
const struct type *type_y,
559 gdb_byte *res,
const struct type *type_res)
const override;
560 int compare (
const gdb_byte *x,
const struct type *type_x,
561 const gdb_byte *y,
const struct type *type_y)
const override;
565 const gdb_byte *from,
T *to)
const;
567 const gdb_byte *from,
T *to)
const;
570 const T *from, gdb_byte *to)
const;
571 void to_target (
const struct floatformat *fmt,
572 const T *from, gdb_byte *to)
const;
598template<
typename T>
void
600 const gdb_byte *from,
T *to)
const
602 gdb_assert (fmt != NULL);
629 unsigned char *ufrom = (
unsigned char *) from;
632 unsigned int mant_bits, mant_off;
634 int special_exponent;
635 enum floatformat_byteorders order;
639 gdb_assert (fmt->totalsize
650 floatformat_to_double
651 (fmt->split_half ? fmt->split_half : fmt, from, &dto);
658 if (order != fmt->byteorder)
665 from_target (fmt->split_half, ufrom, &dtop);
673 from_target (fmt->split_half,
679 exponent =
get_field (ufrom, order, fmt->totalsize, fmt->exp_start,
685 mant_bits_left = fmt->man_len;
686 mant_off = fmt->man_start;
689 special_exponent = exponent == 0 || exponent == fmt->exp_nan;
695 if (!special_exponent)
696 exponent -= fmt->exp_bias;
697 else if (exponent == 0)
698 exponent = 1 - fmt->exp_bias;
706 if (!special_exponent)
708 if (fmt->intbit == floatformat_intbit_no)
709 dto = ldexp (1.0, exponent);
714 while (mant_bits_left > 0)
716 mant_bits = std::min (mant_bits_left, 32);
718 mant =
get_field (ufrom, order, fmt->totalsize, mant_off, mant_bits);
720 dto += ldexp ((
T) mant, exponent - mant_bits);
721 exponent -= mant_bits;
722 mant_off += mant_bits;
723 mant_bits_left -= mant_bits;
727 if (
get_field (ufrom, order, fmt->totalsize, fmt->sign_start, 1))
732template<
typename T>
void
734 const gdb_byte *from,
T *to)
const
741template<
typename T>
void
743 const T *from, gdb_byte *to)
const
745 gdb_assert (fmt != NULL);
763 long double val = *from;
772 unsigned int mant_bits, mant_off;
774 unsigned char *uto = (
unsigned char *) to;
775 enum floatformat_byteorders order = fmt->byteorder;
778 if (order != floatformat_little)
779 order = floatformat_big;
781 if (order != fmt->byteorder)
784 memcpy (&dfrom, from,
sizeof (dfrom));
792 static volatile double dtop, dbot;
795 dtop = (double) dfrom;
798 if (dtop + dtop == dtop && dtop != 0.0)
801 dbot = (double) (dfrom - (
T) dtop);
804 to_target (fmt->split_half, &dtopnv, uto);
805 to_target (fmt->split_half, &dbotnv,
811 goto finalize_byteorder;
815 put_field (uto, order, fmt->totalsize, fmt->exp_start,
816 fmt->exp_len, fmt->exp_nan);
818 put_field (uto, order, fmt->totalsize, fmt->man_start,
820 goto finalize_byteorder;
826 put_field (uto, order, fmt->totalsize, fmt->sign_start, 1, 1);
830 if (dfrom + dfrom == dfrom && dfrom != 0.0)
833 put_field (uto, order, fmt->totalsize, fmt->exp_start,
834 fmt->exp_len, fmt->exp_nan);
836 put_field (uto, order, fmt->totalsize, fmt->man_start,
838 goto finalize_byteorder;
841 mant = frexp (dfrom, &exponent);
843 if (exponent + fmt->exp_bias <= 0)
847 put_field (uto, order, fmt->totalsize, fmt->exp_start,
849 put_field (uto, order, fmt->totalsize, fmt->man_start,
851 goto finalize_byteorder;
854 if (exponent + fmt->exp_bias >= (1 << fmt->exp_len))
858 put_field (uto, order, fmt->totalsize, fmt->exp_start,
859 fmt->exp_len, fmt->exp_nan);
860 put_field (uto, order, fmt->totalsize, fmt->man_start,
862 goto finalize_byteorder;
865 put_field (uto, order, fmt->totalsize, fmt->exp_start, fmt->exp_len,
866 exponent + fmt->exp_bias - 1);
868 mant_bits_left = fmt->man_len;
869 mant_off = fmt->man_start;
870 while (mant_bits_left > 0)
872 unsigned long mant_long;
874 mant_bits = mant_bits_left < 32 ? mant_bits_left : 32;
876 mant *= 4294967296.0;
877 mant_long = ((
unsigned long) mant) & 0xffffffffL;
884 if (mant_bits_left == fmt->man_len
885 && fmt->intbit == floatformat_intbit_no)
888 mant_long &= 0xffffffffL;
904 mant_long >>= 32 - mant_bits;
908 mant_off, mant_bits, mant_long);
909 mant_off += mant_bits;
910 mant_bits_left -= mant_bits;
915 if (order != fmt->byteorder)
919template<
typename T>
void
921 const T *from, gdb_byte *to)
const
939template<
typename T> std::string
941 const char *format)
const
952 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
953 return string_printf (host_format.c_str (),
host_float);
971template<
typename T>
bool
973 const std::string &in)
const
978 std::string scan_format =
"%";
981 scan_format +=
"g%n";
984 DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
985 num = sscanf (in.c_str (), scan_format.c_str(), &
host_float, &n);
1004template<
typename T> LONGEST
1010 T min_possible_range =
static_cast<T>(std::numeric_limits<LONGEST>::min());
1011 T max_possible_range = -min_possible_range;
1016 if (host_float < max_possible_range && host_float >= min_possible_range)
1019 return std::numeric_limits<LONGEST>::min();
1021 return std::numeric_limits<LONGEST>::max();
1026template<
typename T>
void
1036template<
typename T>
void
1046template<
typename T>
double
1057template<
typename T>
void
1068template<
typename T>
void
1070 const struct type *from_type,
1072 const struct type *to_type)
const
1083template<
typename T>
void
1085 const gdb_byte *x,
const struct type *type_x,
1086 const gdb_byte *y,
const struct type *type_y,
1087 gdb_byte *res,
const struct type *type_res)
const
1091 from_target (type_x, x, &v1);
1092 from_target (type_y, y, &v2);
1116 error (_(
"Cannot perform exponentiation: %s"),
1117 safe_strerror (errno));
1121 v = v1 < v2 ? v1 : v2;
1125 v = v1 > v2 ? v1 : v2;
1129 error (_(
"Integer-only operation on floating point number."));
1133 to_target (type_res, &v, res);
1139template<
typename T>
int
1141 const gdb_byte *y,
const struct type *type_y)
const
1145 from_target (type_x, x, &v1);
1146 from_target (type_y, y, &v2);
1161#define MPFR_USE_INTMAX_T
1169 const char *format)
const override;
1171 const std::string &
string)
const override;
1174 const struct type *
type)
const override;
1176 LONGEST val)
const override;
1178 ULONGEST val)
const override;
1180 const struct type *
type)
const override;
1182 double val)
const override;
1183 void convert (
const gdb_byte *from,
const struct type *from_type,
1184 gdb_byte *to,
const struct type *to_type)
const override;
1187 const gdb_byte *x,
const struct type *type_x,
1188 const gdb_byte *y,
const struct type *type_y,
1189 gdb_byte *res,
const struct type *type_res)
const override;
1190 int compare (
const gdb_byte *x,
const struct type *type_x,
1191 const gdb_byte *y,
const struct type *type_y)
const override;
1208 mpfr_init2 (
val, mpfr_get_prec (source.
val));
1218 const gdb_byte *from, gdb_mpfr &to)
const;
1220 const gdb_byte *from, gdb_mpfr &to)
const;
1223 const gdb_mpfr &from, gdb_byte *to)
const;
1224 void to_target (
const struct floatformat *fmt,
1225 const gdb_mpfr &from, gdb_byte *to)
const;
1233 const gdb_byte *orig_from,
gdb_mpfr &to)
const
1235 const gdb_byte *from = orig_from;
1236 mpfr_exp_t exponent;
1238 unsigned int mant_bits, mant_off;
1240 int special_exponent;
1241 enum floatformat_byteorders order;
1245 gdb_assert (fmt->totalsize
1257 mpfr_set_nan (to.
val);
1263 if (order != fmt->byteorder)
1266 if (fmt->split_half)
1272 if (mpfr_zero_p (top.val))
1274 mpfr_set (to.
val, top.val, MPFR_RNDN);
1279 mpfr_add (to.
val, top.val, bot.
val, MPFR_RNDN);
1283 exponent =
get_field (from, order, fmt->totalsize, fmt->exp_start,
1289 mant_bits_left = fmt->man_len;
1290 mant_off = fmt->man_start;
1291 mpfr_set_zero (to.
val, 0);
1293 special_exponent = exponent == 0 || exponent == fmt->exp_nan;
1299 if (!special_exponent)
1300 exponent -= fmt->exp_bias;
1301 else if (exponent == 0)
1302 exponent = 1 - fmt->exp_bias;
1310 if (!special_exponent)
1312 if (fmt->intbit == floatformat_intbit_no)
1313 mpfr_set_ui_2exp (to.
val, 1, exponent, MPFR_RNDN);
1320 while (mant_bits_left > 0)
1322 mant_bits = std::min (mant_bits_left, 32);
1324 mant =
get_field (from, order, fmt->totalsize, mant_off, mant_bits);
1326 mpfr_set_ui (tmp.
val, mant, MPFR_RNDN);
1327 mpfr_mul_2si (tmp.
val, tmp.
val, exponent - mant_bits, MPFR_RNDN);
1328 mpfr_add (to.
val, to.
val, tmp.
val, MPFR_RNDN);
1329 exponent -= mant_bits;
1330 mant_off += mant_bits;
1331 mant_bits_left -= mant_bits;
1335 if (
get_field (from, order, fmt->totalsize, fmt->sign_start, 1))
1336 mpfr_neg (to.
val, to.
val, MPFR_RNDN);
1341 const gdb_byte *from,
gdb_mpfr &to)
const
1348 const gdb_mpfr &from, gdb_byte *orig_to)
const
1350 unsigned char *to = orig_to;
1351 mpfr_exp_t exponent;
1352 unsigned int mant_bits, mant_off;
1354 enum floatformat_byteorders order = fmt->byteorder;
1357 if (order != floatformat_little)
1358 order = floatformat_big;
1360 if (order != fmt->byteorder)
1365 if (fmt->split_half)
1369 mpfr_set (top.val, from.
val, MPFR_RNDN);
1372 if (mpfr_inf_p (top.val))
1373 mpfr_set_zero (bot.
val, 0);
1375 mpfr_sub (bot.
val, from.
val, top.val, MPFR_RNDN);
1385 if (mpfr_zero_p (from.
val))
1386 goto finalize_byteorder;
1388 mpfr_set (tmp.
val, from.
val, MPFR_RNDN);
1390 if (mpfr_nan_p (tmp.
val))
1393 put_field (to, order, fmt->totalsize, fmt->exp_start,
1394 fmt->exp_len, fmt->exp_nan);
1396 put_field (to, order, fmt->totalsize, fmt->man_start,
1398 goto finalize_byteorder;
1402 if (mpfr_sgn (tmp.
val) < 0)
1404 put_field (to, order, fmt->totalsize, fmt->sign_start, 1, 1);
1405 mpfr_neg (tmp.
val, tmp.
val, MPFR_RNDN);
1408 if (mpfr_inf_p (tmp.
val))
1411 put_field (to, order, fmt->totalsize, fmt->exp_start,
1412 fmt->exp_len, fmt->exp_nan);
1414 put_field (to, order, fmt->totalsize, fmt->man_start,
1416 goto finalize_byteorder;
1419 mpfr_frexp (&exponent, tmp.
val, tmp.
val, MPFR_RNDN);
1421 if (exponent + fmt->exp_bias <= 0)
1425 put_field (to, order, fmt->totalsize, fmt->exp_start,
1427 put_field (to, order, fmt->totalsize, fmt->man_start,
1429 goto finalize_byteorder;
1432 if (exponent + fmt->exp_bias >= (1 << fmt->exp_len))
1436 put_field (to, order, fmt->totalsize, fmt->exp_start,
1437 fmt->exp_len, fmt->exp_nan);
1438 put_field (to, order, fmt->totalsize, fmt->man_start,
1440 goto finalize_byteorder;
1443 put_field (to, order, fmt->totalsize, fmt->exp_start, fmt->exp_len,
1444 exponent + fmt->exp_bias - 1);
1446 mant_bits_left = fmt->man_len;
1447 mant_off = fmt->man_start;
1448 while (mant_bits_left > 0)
1450 unsigned long mant_long;
1452 mant_bits = mant_bits_left < 32 ? mant_bits_left : 32;
1454 mpfr_mul_2ui (tmp.
val, tmp.
val, 32, MPFR_RNDN);
1455 mant_long = mpfr_get_ui (tmp.
val, MPFR_RNDZ) & 0xffffffffL;
1456 mpfr_sub_ui (tmp.
val, tmp.
val, mant_long, MPFR_RNDZ);
1462 if (mant_bits_left == fmt->man_len
1463 && fmt->intbit == floatformat_intbit_no)
1466 mant_long &= 0xffffffffL;
1474 if (mant_bits == 32)
1482 mant_long >>= 32 - mant_bits;
1486 mant_off, mant_bits, mant_long);
1487 mant_off += mant_bits;
1488 mant_bits_left -= mant_bits;
1493 if (order != fmt->byteorder)
1499 const gdb_mpfr &from, gdb_byte *to)
const
1512 const char *format)
const
1518 if (format ==
nullptr)
1521 if (!floatformat_is_valid (fmt, addr))
1522 return "<invalid float value>";
1530 return string_printf (
"%snan(0x%s)", sign, mantissa);
1535 return string_printf (
"%sinf", sign);
1545 int size = mpfr_snprintf (NULL, 0, host_format.c_str (), tmp.
val);
1546 std::string str (
size,
'\0');
1547 mpfr_sprintf (&str[0], host_format.c_str (), tmp.
val);
1557 const std::string &in)
const
1562 mpfr_strtofr (tmp.
val, in.c_str (), &endptr, 0, MPFR_RNDN);
1580 return mpfr_get_sj (tmp.
val, MPFR_RNDZ);
1591 mpfr_set_sj (tmp.
val, val, MPFR_RNDN);
1603 mpfr_set_uj (tmp.
val, val, MPFR_RNDN);
1615 return mpfr_get_d (tmp.
val, MPFR_RNDN);
1626 mpfr_set_d (tmp.
val, val, MPFR_RNDN);
1635 const struct type *from_type,
1637 const struct type *to_type)
const
1639 gdb_mpfr from_tmp (from_type), to_tmp (to_type);
1641 mpfr_set (to_tmp.
val, from_tmp.val, MPFR_RNDN);
1651 const gdb_byte *x,
const struct type *type_x,
1652 const gdb_byte *y,
const struct type *type_y,
1653 gdb_byte *res,
const struct type *type_res)
const
1655 gdb_mpfr x_tmp (type_x), y_tmp (type_y), tmp (type_res);
1663 mpfr_add (tmp.
val, x_tmp.val, y_tmp.val, MPFR_RNDN);
1667 mpfr_sub (tmp.
val, x_tmp.val, y_tmp.val, MPFR_RNDN);
1671 mpfr_mul (tmp.
val, x_tmp.val, y_tmp.val, MPFR_RNDN);
1675 mpfr_div (tmp.
val, x_tmp.val, y_tmp.val, MPFR_RNDN);
1679 mpfr_pow (tmp.
val, x_tmp.val, y_tmp.val, MPFR_RNDN);
1683 mpfr_min (tmp.
val, x_tmp.val, y_tmp.val, MPFR_RNDN);
1687 mpfr_max (tmp.
val, x_tmp.val, y_tmp.val, MPFR_RNDN);
1691 error (_(
"Integer-only operation on floating point number."));
1703 const gdb_byte *y,
const struct type *type_y)
const
1705 gdb_mpfr x_tmp (type_x), y_tmp (type_y);
1710 if (mpfr_equal_p (x_tmp.val, y_tmp.
val))
1712 else if (mpfr_less_p (x_tmp.val, y_tmp.
val))
1731#include "dpd/decimal128.h"
1732#include "dpd/decimal64.h"
1733#include "dpd/decimal32.h"
1737#define MAX_DECIMAL_STRING 43
1745 gdb_assert (
type->
code () == TYPE_CODE_DECFLOAT);
1751#define OPPOSITE_BYTE_ORDER BFD_ENDIAN_LITTLE
1753#define OPPOSITE_BYTE_ORDER BFD_ENDIAN_BIG
1757 for (i = 0; i < len; i++)
1758 to[i] = from[len - i - 1];
1760 for (i = 0; i < len; i++)
1771 gdb_assert (
type->
code () == TYPE_CODE_DECFLOAT);
1776 decContextDefault (ctx, DEC_INIT_DECIMAL32);
1779 decContextDefault (ctx, DEC_INIT_DECIMAL64);
1782 decContextDefault (ctx, DEC_INIT_DECIMAL128);
1798 if (ctx->status & DEC_IEEE_854_Invalid_operation)
1801 ctx->status &= DEC_IEEE_854_Invalid_operation;
1802 error (_(
"Cannot perform operation: %s"),
1803 decContextStatusToString (ctx));
1811 gdb_byte *to,
const struct type *
type)
1822 decimal32FromNumber ((decimal32 *) dec, from, &set);
1825 decimal64FromNumber ((decimal64 *) dec, from, &set);
1828 decimal128FromNumber ((decimal128 *) dec, from, &set);
1831 error (_(
"Unknown decimal floating point type."));
1850 decimal32ToNumber ((decimal32 *) dec, to);
1853 decimal64ToNumber ((decimal64 *) dec, to);
1856 decimal128ToNumber ((decimal128 *) dec, to);
1859 error (_(
"Unknown decimal floating point type."));
1872 return decNumberIsZero (&number);
1883 const char *format)
const override;
1885 const std::string &
string)
const override;
1888 const struct type *
type)
const override;
1890 LONGEST val)
const override;
1892 ULONGEST val)
const override;
1894 const struct type *
type)
const override
1898 gdb_assert_not_reached (
"invalid operation on decimal float");
1901 double val)
const override
1905 gdb_assert_not_reached (
"invalid operation on decimal float");
1907 void convert (
const gdb_byte *from,
const struct type *from_type,
1908 gdb_byte *to,
const struct type *to_type)
const override;
1911 const gdb_byte *x,
const struct type *type_x,
1912 const gdb_byte *y,
const struct type *type_y,
1913 gdb_byte *res,
const struct type *type_res)
const override;
1914 int compare (
const gdb_byte *x,
const struct type *type_x,
1915 const gdb_byte *y,
const struct type *type_y)
const override;
1923 const char *format =
nullptr)
const
1929 if (format !=
nullptr)
1934#if defined (PRINTF_HAS_DECFLOAT)
1936 return string_printf (format, dec);
1946 decimal32ToString ((decimal32 *) dec, &result[0]);
1949 decimal64ToString ((decimal64 *) dec, &result[0]);
1952 decimal128ToString ((decimal128 *) dec, &result[0]);
1955 error (_(
"Unknown decimal floating point type."));
1967 const std::string &
string)
const
1977 decimal32FromString ((decimal32 *) dec,
string.c_str (), &set);
1980 decimal64FromString ((decimal64 *) dec,
string.c_str (), &set);
1983 decimal128FromString ((decimal128 *) dec,
string.c_str (), &set);
1986 error (_(
"Unknown decimal floating point type."));
2005 if ((int32_t) from != from)
2007 error (_(
"Conversion of large integer to a "
2008 "decimal floating type is not supported."));
2010 decNumberFromInt32 (&number, (int32_t) from);
2018 ULONGEST from)
const
2022 if ((uint32_t) from != from)
2024 error (_(
"Conversion of large integer to a "
2025 "decimal floating type is not supported."));
2027 decNumberFromUInt32 (&number, (uint32_t) from);
2040 return strtoll (str.c_str (), NULL, 10);
2048 const gdb_byte *x,
const struct type *type_x,
2049 const gdb_byte *y,
const struct type *type_y,
2050 gdb_byte *res,
const struct type *type_res)
const
2053 decNumber number1, number2, number3;
2063 decNumberAdd (&number3, &number1, &number2, &set);
2066 decNumberSubtract (&number3, &number1, &number2, &set);
2069 decNumberMultiply (&number3, &number1, &number2, &set);
2072 decNumberDivide (&number3, &number1, &number2, &set);
2075 decNumberPower (&number3, &number1, &number2, &set);
2078 error (_(
"Operation not valid for decimal floating point number."));
2093 const gdb_byte *y,
const struct type *type_y)
const
2095 decNumber number1, number2, result;
2097 const struct type *type_result;
2103 type_result = type_x->
length () > type_y->
length () ? type_x : type_y;
2106 decNumberCompare (&result, &number1, &number2, &set);
2111 if (decNumberIsNaN (&result))
2112 error (_(
"Comparison with an invalid number (NaN)."));
2113 else if (decNumberIsZero (&result))
2115 else if (decNumberIsNegative (&result))
2125 gdb_byte *to,
const struct type *to_type)
const
2143 const struct type *type2)
2145 return type1->
code () == type2->
code ();
2151 const struct type *type2)
2156 switch (type1->
code ())
2161 case TYPE_CODE_DECFLOAT:
2167 gdb_assert_not_reached (
"unexpected type code");
2181 case TYPE_CODE_DECFLOAT:
2185 gdb_assert_not_reached (
"unexpected type code");
2226 case TYPE_CODE_DECFLOAT:
2233 gdb_assert_not_reached (
"unexpected type code");
2248 return &host_float_ops_float;
2254 return &host_float_ops_double;
2260 return &host_float_ops_long_double;
2274 return &binary_float_ops;
2286 gdb_assert_not_reached (
"unexpected target_float_ops_kind");
2303 gdb_assert (type1->
code () == type2->
code ());
2318 if (
type->
code () == TYPE_CODE_FLT)
2321 if (
type->
code () == TYPE_CODE_DECFLOAT)
2324 gdb_assert_not_reached (
"unexpected type code");
2332 if (
type->
code () == TYPE_CODE_FLT)
2336 if (
type->
code () == TYPE_CODE_DECFLOAT)
2339 gdb_assert_not_reached (
"unexpected type code");
2350 if (format ==
nullptr &&
type->
code () == TYPE_CODE_FLT)
2355 if (!floatformat_is_valid (fmt, addr))
2356 return "<invalid float value>";
2364 return string_printf (
"%snan(0x%s)", sign, mantissa);
2369 return string_printf (
"%sinf", sign);
2381 const std::string &
string)
2441 gdb_byte *to,
const struct type *to_type)
2456 ops->
convert (from, from_type, to, to_type);
2462 memset (to, 0, to_type->
length ());
2476 const gdb_byte *x,
const struct type *type_x,
2477 const gdb_byte *y,
const struct type *type_y,
2478 gdb_byte *res,
const struct type *type_res)
2484 ops->
binop (opcode, x, type_x, y, type_y, res, type_res);
2496 const gdb_byte *y,
const struct type *type_y)
2501 return ops->
compare (x, type_x, y, type_y);
double to_host_double(const gdb_byte *addr, const struct type *type) const override
void from_host_double(gdb_byte *addr, const struct type *type, double val) const override
void binop(enum exp_opcode opcode, const gdb_byte *x, const struct type *type_x, const gdb_byte *y, const struct type *type_y, gdb_byte *res, const struct type *type_res) const override
void convert(const gdb_byte *from, const struct type *from_type, gdb_byte *to, const struct type *to_type) const override
std::string to_string(const gdb_byte *addr, const struct type *type, const char *format) const override
int compare(const gdb_byte *x, const struct type *type_x, const gdb_byte *y, const struct type *type_y) const override
void from_ulongest(gdb_byte *addr, const struct type *type, ULONGEST val) const override
void from_longest(gdb_byte *addr, const struct type *type, LONGEST val) const override
bool from_string(gdb_byte *addr, const struct type *type, const std::string &string) const override
LONGEST to_longest(const gdb_byte *addr, const struct type *type) const override
int compare(const gdb_byte *x, const struct type *type_x, const gdb_byte *y, const struct type *type_y) const override
LONGEST to_longest(const gdb_byte *addr, const struct type *type) const override
void from_host_double(gdb_byte *addr, const struct type *type, double val) const override
void from_longest(gdb_byte *addr, const struct type *type, LONGEST val) const override
void binop(enum exp_opcode opcode, const gdb_byte *x, const struct type *type_x, const gdb_byte *y, const struct type *type_y, gdb_byte *res, const struct type *type_res) const override
void from_ulongest(gdb_byte *addr, const struct type *type, ULONGEST val) const override
double to_host_double(const gdb_byte *addr, const struct type *type) const override
void to_target(const struct type *type, const T *from, gdb_byte *to) const
void convert(const gdb_byte *from, const struct type *from_type, gdb_byte *to, const struct type *to_type) const override
std::string to_string(const gdb_byte *addr, const struct type *type, const char *format) const override
void from_target(const struct floatformat *fmt, const gdb_byte *from, T *to) const
bool from_string(gdb_byte *addr, const struct type *type, const std::string &string) const override
gdb_mpfr(const struct type *type)
gdb_mpfr(const gdb_mpfr &source)
void to_target(const struct type *type, const gdb_mpfr &from, gdb_byte *to) const
void convert(const gdb_byte *from, const struct type *from_type, gdb_byte *to, const struct type *to_type) const override
void from_host_double(gdb_byte *addr, const struct type *type, double val) const override
void binop(enum exp_opcode opcode, const gdb_byte *x, const struct type *type_x, const gdb_byte *y, const struct type *type_y, gdb_byte *res, const struct type *type_res) const override
void from_ulongest(gdb_byte *addr, const struct type *type, ULONGEST val) const override
std::string to_string(const gdb_byte *addr, const struct type *type, const char *format) const override
void from_target(const struct floatformat *fmt, const gdb_byte *from, gdb_mpfr &to) const
LONGEST to_longest(const gdb_byte *addr, const struct type *type) const override
double to_host_double(const gdb_byte *addr, const struct type *type) const override
int compare(const gdb_byte *x, const struct type *type_x, const gdb_byte *y, const struct type *type_y) const override
void from_longest(gdb_byte *addr, const struct type *type, LONGEST val) const override
bool from_string(gdb_byte *addr, const struct type *type, const std::string &string) const override
virtual std::string to_string(const gdb_byte *addr, const struct type *type, const char *format) const =0
virtual void from_longest(gdb_byte *addr, const struct type *type, LONGEST val) const =0
virtual void from_host_double(gdb_byte *addr, const struct type *type, double val) const =0
virtual void from_ulongest(gdb_byte *addr, const struct type *type, ULONGEST val) const =0
virtual void binop(enum exp_opcode opcode, const gdb_byte *x, const struct type *type_x, const gdb_byte *y, const struct type *type_y, gdb_byte *res, const struct type *type_res) const =0
virtual int compare(const gdb_byte *x, const struct type *type_x, const gdb_byte *y, const struct type *type_y) const =0
virtual void convert(const gdb_byte *from, const struct type *from_type, gdb_byte *to, const struct type *to_type) const =0
virtual LONGEST to_longest(const gdb_byte *addr, const struct type *type) const =0
virtual double to_host_double(const gdb_byte *addr, const struct type *type) const =0
virtual bool from_string(gdb_byte *addr, const struct type *type, const std::string &string) const =0
#define GDB_HOST_FLOAT_FORMAT
#define GDB_HOST_LONG_DOUBLE_FORMAT
#define GDB_HOST_DOUBLE_FORMAT
enum bfd_endian type_byte_order(const struct type *type)
const struct floatformat * floatformat_from_type(const struct type *type)
static int floatformat_is_negative(const struct floatformat *fmt, const bfd_byte *uval)
#define FLOATFORMAT_CHAR_BIT
static const struct floatformat * host_double_format
int target_float_compare(const gdb_byte *x, const struct type *type_x, const gdb_byte *y, const struct type *type_y)
static int floatformat_precision(const struct floatformat *fmt)
static void decimal_from_number(const decNumber *from, gdb_byte *to, const struct type *type)
static bool decimal_is_zero(const gdb_byte *addr, const struct type *type)
static std::string floatformat_printf_format(const struct floatformat *fmt, const char *format, char length)
LONGEST target_float_to_longest(const gdb_byte *addr, const struct type *type)
static const struct floatformat * host_float_format
bool target_float_is_zero(const gdb_byte *addr, const struct type *type)
static size_t floatformat_totalsize_bytes(const struct floatformat *fmt)
static bool target_float_same_format_p(const struct type *type1, const struct type *type2)
static void set_decnumber_context(decContext *ctx, const struct type *type)
static enum target_float_ops_kind get_target_float_ops_kind(const struct type *type)
#define OPPOSITE_BYTE_ORDER
static unsigned long get_field(const bfd_byte *data, enum floatformat_byteorders order, unsigned int total_len, unsigned int start, unsigned int len)
static bool target_float_same_category_p(const struct type *type1, const struct type *type2)
void target_float_binop(enum exp_opcode opcode, const gdb_byte *x, const struct type *type_x, const gdb_byte *y, const struct type *type_y, gdb_byte *res, const struct type *type_res)
bool target_float_is_valid(const gdb_byte *addr, const struct type *type)
static const char * floatformat_mantissa(const struct floatformat *fmt, const bfd_byte *val)
bool target_float_from_string(gdb_byte *addr, const struct type *type, const std::string &string)
static enum floatformat_byteorders floatformat_normalize_byteorder(const struct floatformat *fmt, const void *from, void *to)
static int target_float_format_length(const struct type *type)
#define FLOATFORMAT_LARGEST_BYTES
#define MAX_DECIMAL_STRING
static void match_endianness(const gdb_byte *from, const struct type *type, gdb_byte *to)
void target_float_convert(const gdb_byte *from, const struct type *from_type, gdb_byte *to, const struct type *to_type)
static const struct floatformat * host_long_double_format
void target_float_from_longest(gdb_byte *addr, const struct type *type, LONGEST val)
double target_float_to_host_double(const gdb_byte *addr, const struct type *type)
std::string target_float_to_string(const gdb_byte *addr, const struct type *type, const char *format)
static const target_float_ops * get_target_float_ops(enum target_float_ops_kind kind)
static enum float_kind floatformat_classify(const struct floatformat *fmt, const bfd_byte *uval)
void target_float_from_host_double(gdb_byte *addr, const struct type *type, double val)
static void decimal_to_number(const gdb_byte *addr, const struct type *type, decNumber *to)
static void decimal_check_errors(decContext *ctx)
static void put_field(unsigned char *data, enum floatformat_byteorders order, unsigned int total_len, unsigned int start, unsigned int len, unsigned long stuff_to_put)
void target_float_from_ulongest(gdb_byte *addr, const struct type *type, ULONGEST val)