/* Floating point routines for GDB, the GNU debugger.
- Copyright (C) 2017-2019 Free Software Foundation, Inc.
+ Copyright (C) 2017-2020 Free Software Foundation, Inc.
This file is part of GDB.
{
double dto;
- floatformat_to_double (fmt->split_half ? fmt->split_half : fmt,
- from, &dto);
+ floatformat_to_double /* ARI: floatformat_to_double */
+ (fmt->split_half ? fmt->split_half : fmt, from, &dto);
*to = (T) dto;
return;
}
{
T host_float;
from_target (type, addr, &host_float);
- /* Converting an out-of-range value is undefined behavior in C, but we
- prefer to return a defined value here. */
- if (host_float > std::numeric_limits<LONGEST>::max())
- return std::numeric_limits<LONGEST>::max();
- if (host_float < std::numeric_limits<LONGEST>::min())
+ T min_possible_range = static_cast<T>(std::numeric_limits<LONGEST>::min());
+ T max_possible_range = -min_possible_range;
+ /* host_float can be converted to an integer as long as it's in
+ the range [min_possible_range, max_possible_range). If not, it is either
+ too large, or too small, or is NaN; in this case return the maximum or
+ minimum possible value. */
+ if (host_float < max_possible_range && host_float >= min_possible_range)
+ return static_cast<LONGEST> (host_float);
+ if (host_float < min_possible_range)
return std::numeric_limits<LONGEST>::min();
- return (LONGEST) host_float;
+ /* This line will be executed if host_float is NaN. */
+ return std::numeric_limits<LONGEST>::max();
}
/* Convert signed integer VAL to a target floating-number of type TYPE
#define OPPOSITE_BYTE_ORDER BFD_ENDIAN_BIG
#endif
- if (gdbarch_byte_order (get_type_arch (type)) == OPPOSITE_BYTE_ORDER)
+ if (type_byte_order (type) == OPPOSITE_BYTE_ORDER)
for (i = 0; i < len; i++)
to[i] = from[len - i - 1];
else
case TYPE_CODE_DECFLOAT:
return (TYPE_LENGTH (type1) == TYPE_LENGTH (type2)
- && (gdbarch_byte_order (get_type_arch (type1))
- == gdbarch_byte_order (get_type_arch (type2))));
+ && (type_byte_order (type1)
+ == type_byte_order (type2)));
default:
gdb_assert_not_reached ("unexpected type code");
/* For binary floating-point formats that do not match any host format,
use mpfr_t as intermediate format to provide precise target-floating
- point emulation. However, if the MPFR library is not availabe,
+ point emulation. However, if the MPFR library is not available,
use the largest host floating-point type as intermediate format. */
case target_float_ops_kind::binary:
{