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);
1159#define MPFR_USE_INTMAX_T
1167 const char *format)
const override;
1169 const std::string &
string)
const override;
1172 const struct type *
type)
const override;
1174 LONGEST val)
const override;
1176 ULONGEST val)
const override;
1178 const struct type *
type)
const override;
1180 double val)
const override;
1181 void convert (
const gdb_byte *from,
const struct type *from_type,
1182 gdb_byte *to,
const struct type *to_type)
const override;
1185 const gdb_byte *x,
const struct type *type_x,
1186 const gdb_byte *y,
const struct type *type_y,
1187 gdb_byte *res,
const struct type *type_res)
const override;
1188 int compare (
const gdb_byte *x,
const struct type *type_x,
1189 const gdb_byte *y,
const struct type *type_y)
const override;
1206 mpfr_init2 (
val, mpfr_get_prec (source.val));
1216 const gdb_byte *from, gdb_mpfr &to)
const;
1218 const gdb_byte *from, gdb_mpfr &to)
const;
1221 const gdb_mpfr &from, gdb_byte *to)
const;
1222 void to_target (
const struct floatformat *fmt,
1223 const gdb_mpfr &from, gdb_byte *to)
const;
1231 const gdb_byte *orig_from,
gdb_mpfr &to)
const
1233 const gdb_byte *from = orig_from;
1234 mpfr_exp_t exponent;
1236 unsigned int mant_bits, mant_off;
1238 int special_exponent;
1239 enum floatformat_byteorders order;
1243 gdb_assert (fmt->totalsize
1255 mpfr_set_nan (to.
val);
1261 if (order != fmt->byteorder)
1264 if (fmt->split_half)
1270 if (mpfr_zero_p (top.val))
1272 mpfr_set (to.
val, top.val, MPFR_RNDN);
1277 mpfr_add (to.
val, top.val, bot.
val, MPFR_RNDN);
1281 exponent =
get_field (from, order, fmt->totalsize, fmt->exp_start,
1287 mant_bits_left = fmt->man_len;
1288 mant_off = fmt->man_start;
1289 mpfr_set_zero (to.
val, 0);
1291 special_exponent = exponent == 0 || exponent == fmt->exp_nan;
1297 if (!special_exponent)
1298 exponent -= fmt->exp_bias;
1299 else if (exponent == 0)
1300 exponent = 1 - fmt->exp_bias;
1308 if (!special_exponent)
1310 if (fmt->intbit == floatformat_intbit_no)
1311 mpfr_set_ui_2exp (to.
val, 1, exponent, MPFR_RNDN);
1318 while (mant_bits_left > 0)
1320 mant_bits = std::min (mant_bits_left, 32);
1322 mant =
get_field (from, order, fmt->totalsize, mant_off, mant_bits);
1324 mpfr_set_ui (tmp.
val, mant, MPFR_RNDN);
1325 mpfr_mul_2si (tmp.
val, tmp.
val, exponent - mant_bits, MPFR_RNDN);
1326 mpfr_add (to.
val, to.
val, tmp.
val, MPFR_RNDN);
1327 exponent -= mant_bits;
1328 mant_off += mant_bits;
1329 mant_bits_left -= mant_bits;
1333 if (
get_field (from, order, fmt->totalsize, fmt->sign_start, 1))
1334 mpfr_neg (to.
val, to.
val, MPFR_RNDN);
1339 const gdb_byte *from,
gdb_mpfr &to)
const
1346 const gdb_mpfr &from, gdb_byte *orig_to)
const
1348 unsigned char *to = orig_to;
1349 mpfr_exp_t exponent;
1350 unsigned int mant_bits, mant_off;
1352 enum floatformat_byteorders order = fmt->byteorder;
1355 if (order != floatformat_little)
1356 order = floatformat_big;
1358 if (order != fmt->byteorder)
1363 if (fmt->split_half)
1367 mpfr_set (top.val, from.
val, MPFR_RNDN);
1370 if (mpfr_inf_p (top.val))
1371 mpfr_set_zero (bot.
val, 0);
1373 mpfr_sub (bot.
val, from.
val, top.val, MPFR_RNDN);
1383 if (mpfr_zero_p (from.
val))
1384 goto finalize_byteorder;
1386 mpfr_set (tmp.
val, from.
val, MPFR_RNDN);
1388 if (mpfr_nan_p (tmp.
val))
1391 put_field (to, order, fmt->totalsize, fmt->exp_start,
1392 fmt->exp_len, fmt->exp_nan);
1394 put_field (to, order, fmt->totalsize, fmt->man_start,
1396 goto finalize_byteorder;
1400 if (mpfr_sgn (tmp.
val) < 0)
1402 put_field (to, order, fmt->totalsize, fmt->sign_start, 1, 1);
1403 mpfr_neg (tmp.
val, tmp.
val, MPFR_RNDN);
1406 if (mpfr_inf_p (tmp.
val))
1409 put_field (to, order, fmt->totalsize, fmt->exp_start,
1410 fmt->exp_len, fmt->exp_nan);
1412 put_field (to, order, fmt->totalsize, fmt->man_start,
1414 goto finalize_byteorder;
1417 mpfr_frexp (&exponent, tmp.
val, tmp.
val, MPFR_RNDN);
1419 if (exponent + fmt->exp_bias <= 0)
1423 put_field (to, order, fmt->totalsize, fmt->exp_start,
1425 put_field (to, order, fmt->totalsize, fmt->man_start,
1427 goto finalize_byteorder;
1430 if (exponent + fmt->exp_bias >= (1 << fmt->exp_len))
1434 put_field (to, order, fmt->totalsize, fmt->exp_start,
1435 fmt->exp_len, fmt->exp_nan);
1436 put_field (to, order, fmt->totalsize, fmt->man_start,
1438 goto finalize_byteorder;
1441 put_field (to, order, fmt->totalsize, fmt->exp_start, fmt->exp_len,
1442 exponent + fmt->exp_bias - 1);
1444 mant_bits_left = fmt->man_len;
1445 mant_off = fmt->man_start;
1446 while (mant_bits_left > 0)
1448 unsigned long mant_long;
1450 mant_bits = mant_bits_left < 32 ? mant_bits_left : 32;
1452 mpfr_mul_2ui (tmp.
val, tmp.
val, 32, MPFR_RNDN);
1453 mant_long = mpfr_get_ui (tmp.
val, MPFR_RNDZ) & 0xffffffffL;
1454 mpfr_sub_ui (tmp.
val, tmp.
val, mant_long, MPFR_RNDZ);
1460 if (mant_bits_left == fmt->man_len
1461 && fmt->intbit == floatformat_intbit_no)
1464 mant_long &= 0xffffffffL;
1472 if (mant_bits == 32)
1480 mant_long >>= 32 - mant_bits;
1484 mant_off, mant_bits, mant_long);
1485 mant_off += mant_bits;
1486 mant_bits_left -= mant_bits;
1491 if (order != fmt->byteorder)
1497 const gdb_mpfr &from, gdb_byte *to)
const
1510 const char *format)
const
1516 if (format ==
nullptr)
1519 if (!floatformat_is_valid (fmt, addr))
1520 return "<invalid float value>";
1528 return string_printf (
"%snan(0x%s)", sign, mantissa);
1533 return string_printf (
"%sinf", sign);
1543 int size = mpfr_snprintf (NULL, 0, host_format.c_str (), tmp.
val);
1544 std::string str (
size,
'\0');
1545 mpfr_sprintf (&str[0], host_format.c_str (), tmp.
val);
1555 const std::string &in)
const
1560 mpfr_strtofr (tmp.
val, in.c_str (), &endptr, 0, MPFR_RNDN);
1578 return mpfr_get_sj (tmp.
val, MPFR_RNDZ);
1589 mpfr_set_sj (tmp.
val, val, MPFR_RNDN);
1601 mpfr_set_uj (tmp.
val, val, MPFR_RNDN);
1613 return mpfr_get_d (tmp.
val, MPFR_RNDN);
1624 mpfr_set_d (tmp.
val, val, MPFR_RNDN);
1633 const struct type *from_type,
1635 const struct type *to_type)
const
1637 gdb_mpfr from_tmp (from_type), to_tmp (to_type);
1639 mpfr_set (to_tmp.
val, from_tmp.val, MPFR_RNDN);
1649 const gdb_byte *x,
const struct type *type_x,
1650 const gdb_byte *y,
const struct type *type_y,
1651 gdb_byte *res,
const struct type *type_res)
const
1653 gdb_mpfr x_tmp (type_x), y_tmp (type_y), tmp (type_res);
1661 mpfr_add (tmp.
val, x_tmp.val, y_tmp.val, MPFR_RNDN);
1665 mpfr_sub (tmp.
val, x_tmp.val, y_tmp.val, MPFR_RNDN);
1669 mpfr_mul (tmp.
val, x_tmp.val, y_tmp.val, MPFR_RNDN);
1673 mpfr_div (tmp.
val, x_tmp.val, y_tmp.val, MPFR_RNDN);
1677 mpfr_pow (tmp.
val, x_tmp.val, y_tmp.val, MPFR_RNDN);
1681 mpfr_min (tmp.
val, x_tmp.val, y_tmp.val, MPFR_RNDN);
1685 mpfr_max (tmp.
val, x_tmp.val, y_tmp.val, MPFR_RNDN);
1689 error (_(
"Integer-only operation on floating point number."));
1701 const gdb_byte *y,
const struct type *type_y)
const
1703 gdb_mpfr x_tmp (type_x), y_tmp (type_y);
1708 if (mpfr_equal_p (x_tmp.val, y_tmp.
val))
1710 else if (mpfr_less_p (x_tmp.val, y_tmp.
val))
1727#include "dpd/decimal128.h"
1728#include "dpd/decimal64.h"
1729#include "dpd/decimal32.h"
1733#define MAX_DECIMAL_STRING 43
1741 gdb_assert (
type->
code () == TYPE_CODE_DECFLOAT);
1747#define OPPOSITE_BYTE_ORDER BFD_ENDIAN_LITTLE
1749#define OPPOSITE_BYTE_ORDER BFD_ENDIAN_BIG
1753 for (i = 0; i < len; i++)
1754 to[i] = from[len - i - 1];
1756 for (i = 0; i < len; i++)
1767 gdb_assert (
type->
code () == TYPE_CODE_DECFLOAT);
1772 decContextDefault (ctx, DEC_INIT_DECIMAL32);
1775 decContextDefault (ctx, DEC_INIT_DECIMAL64);
1778 decContextDefault (ctx, DEC_INIT_DECIMAL128);
1794 if (ctx->status & DEC_IEEE_854_Invalid_operation)
1797 ctx->status &= DEC_IEEE_854_Invalid_operation;
1798 error (_(
"Cannot perform operation: %s"),
1799 decContextStatusToString (ctx));
1807 gdb_byte *to,
const struct type *
type)
1818 decimal32FromNumber ((decimal32 *) dec, from, &set);
1821 decimal64FromNumber ((decimal64 *) dec, from, &set);
1824 decimal128FromNumber ((decimal128 *) dec, from, &set);
1827 error (_(
"Unknown decimal floating point type."));
1846 decimal32ToNumber ((decimal32 *) dec, to);
1849 decimal64ToNumber ((decimal64 *) dec, to);
1852 decimal128ToNumber ((decimal128 *) dec, to);
1855 error (_(
"Unknown decimal floating point type."));
1868 return decNumberIsZero (&number);
1879 const char *format)
const override;
1881 const std::string &
string)
const override;
1884 const struct type *
type)
const override;
1886 LONGEST val)
const override;
1888 ULONGEST val)
const override;
1890 const struct type *
type)
const override
1894 gdb_assert_not_reached (
"invalid operation on decimal float");
1897 double val)
const override
1901 gdb_assert_not_reached (
"invalid operation on decimal float");
1903 void convert (
const gdb_byte *from,
const struct type *from_type,
1904 gdb_byte *to,
const struct type *to_type)
const override;
1907 const gdb_byte *x,
const struct type *type_x,
1908 const gdb_byte *y,
const struct type *type_y,
1909 gdb_byte *res,
const struct type *type_res)
const override;
1910 int compare (
const gdb_byte *x,
const struct type *type_x,
1911 const gdb_byte *y,
const struct type *type_y)
const override;
1919 const char *format =
nullptr)
const
1925 if (format !=
nullptr)
1930#if defined (PRINTF_HAS_DECFLOAT)
1932 return string_printf (format, dec);
1942 decimal32ToString ((decimal32 *) dec, &result[0]);
1945 decimal64ToString ((decimal64 *) dec, &result[0]);
1948 decimal128ToString ((decimal128 *) dec, &result[0]);
1951 error (_(
"Unknown decimal floating point type."));
1963 const std::string &
string)
const
1973 decimal32FromString ((decimal32 *) dec,
string.c_str (), &set);
1976 decimal64FromString ((decimal64 *) dec,
string.c_str (), &set);
1979 decimal128FromString ((decimal128 *) dec,
string.c_str (), &set);
1982 error (_(
"Unknown decimal floating point type."));
2001 if ((int32_t) from != from)
2003 error (_(
"Conversion of large integer to a "
2004 "decimal floating type is not supported."));
2006 decNumberFromInt32 (&number, (int32_t) from);
2014 ULONGEST from)
const
2018 if ((uint32_t) from != from)
2020 error (_(
"Conversion of large integer to a "
2021 "decimal floating type is not supported."));
2023 decNumberFromUInt32 (&number, (uint32_t) from);
2036 return strtoll (str.c_str (), NULL, 10);
2044 const gdb_byte *x,
const struct type *type_x,
2045 const gdb_byte *y,
const struct type *type_y,
2046 gdb_byte *res,
const struct type *type_res)
const
2049 decNumber number1, number2, number3;
2059 decNumberAdd (&number3, &number1, &number2, &set);
2062 decNumberSubtract (&number3, &number1, &number2, &set);
2065 decNumberMultiply (&number3, &number1, &number2, &set);
2068 decNumberDivide (&number3, &number1, &number2, &set);
2071 decNumberPower (&number3, &number1, &number2, &set);
2074 error (_(
"Operation not valid for decimal floating point number."));
2089 const gdb_byte *y,
const struct type *type_y)
const
2091 decNumber number1, number2, result;
2093 const struct type *type_result;
2099 type_result = type_x->
length () > type_y->
length () ? type_x : type_y;
2102 decNumberCompare (&result, &number1, &number2, &set);
2107 if (decNumberIsNaN (&result))
2108 error (_(
"Comparison with an invalid number (NaN)."));
2109 else if (decNumberIsZero (&result))
2111 else if (decNumberIsNegative (&result))
2121 gdb_byte *to,
const struct type *to_type)
const
2139 const struct type *type2)
2141 return type1->
code () == type2->
code ();
2147 const struct type *type2)
2152 switch (type1->
code ())
2157 case TYPE_CODE_DECFLOAT:
2163 gdb_assert_not_reached (
"unexpected type code");
2177 case TYPE_CODE_DECFLOAT:
2181 gdb_assert_not_reached (
"unexpected type code");
2222 case TYPE_CODE_DECFLOAT:
2229 gdb_assert_not_reached (
"unexpected type code");
2244 return &host_float_ops_float;
2250 return &host_float_ops_double;
2256 return &host_float_ops_long_double;
2266 return &binary_float_ops;
2278 gdb_assert_not_reached (
"unexpected target_float_ops_kind");
2295 gdb_assert (type1->
code () == type2->
code ());
2310 if (
type->
code () == TYPE_CODE_FLT)
2313 if (
type->
code () == TYPE_CODE_DECFLOAT)
2316 gdb_assert_not_reached (
"unexpected type code");
2324 if (
type->
code () == TYPE_CODE_FLT)
2328 if (
type->
code () == TYPE_CODE_DECFLOAT)
2331 gdb_assert_not_reached (
"unexpected type code");
2342 if (format ==
nullptr &&
type->
code () == TYPE_CODE_FLT)
2347 if (!floatformat_is_valid (fmt, addr))
2348 return "<invalid float value>";
2356 return string_printf (
"%snan(0x%s)", sign, mantissa);
2361 return string_printf (
"%sinf", sign);
2373 const std::string &
string)
2433 gdb_byte *to,
const struct type *to_type)
2448 ops->
convert (from, from_type, to, to_type);
2454 memset (to, 0, to_type->
length ());
2468 const gdb_byte *x,
const struct type *type_x,
2469 const gdb_byte *y,
const struct type *type_y,
2470 gdb_byte *res,
const struct type *type_res)
2476 ops->
binop (opcode, x, type_x, y, type_y, res, type_res);
2488 const gdb_byte *y,
const struct type *type_y)
2493 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)