https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84407

--- Comment #5 from joseph at codesourcery dot com <joseph at codesourcery dot 
com> ---
On Wed, 27 Oct 2021, rguenth at gcc dot gnu.org via Gcc-bugs wrote:

> Also a question is the behavior on overflow when converting a real to an
> integer (IIRC the behavior here is undefined, but we constant fold to the
> largest/smallest integer here).

We follow Annex F here (so unspecified value rather than undefined - as 
discussed in other bugs, any given execution of the conversion in the 
abstract machine needs to act as if it does return some value of the 
type).

> For integer to float conversions is the overflow considered before or after
> applying the rounding?  That is, are there integer values that invoke
> undefined behavior when converted to a real dependent on the rounding mode?

It's fully defined regardless of the value (the appropriately rounded 
result is returned, which might be an infinity in case of overflow, or the 
largest finite value depending on the rounding mode).

Whether the conversion overflows can indeed depend on the rounding mode 
(overflow occurs when a conversion in that rounding mode, with infinite 
exponent range, would produce a result with an exponent too large to 
represent in the floating-point format).  For the IEEE formats and integer 
types supported by GCC, the only cases where overflow is possible are for 
conversions to _Float16, and from unsigned __int128 to float.

Reply via email to