[cfp-interest 3949] Re: Weird Casting Error

Vincent Lefevre vincent at vinc17.net
Wed Jun 10 08:50:41 PDT 2026


On 2026-06-10 11:35:56 -0400, Joshua Cranmer wrote:
> My copy of IEEE 754 has this in section 5.8:
> 
> > Implementations shall provide conversion operations from all supported
> > arithmetic formats to all supported
> > signed and unsigned integer formats.
> IEEE 754 clearly intends that conversion from floating-point formats to
> unsigned integers is a legal (static) operation. What happens when the
> dynamic value is out-of-range is not specified by IEEE 754 (outside of
> invalid exception), and C opts for the UB route there.

IEEE 754-2019 says:

  When a NaN or infinite operand cannot be represented in the
  destination format and this cannot otherwise be indicated, the
  invalid operation exception shall be signaled. When a numeric
  operand would convert to an integer outside the range of the
  destination format, the invalid operation exception shall be
  signaled if this situation cannot otherwise be indicated.

So I don't think that UB is correct. However, it depends on the
bindings (there may be a way to do the conversion that is UB and
another way that conforms to IEEE 754).

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)


More information about the cfp-interest mailing list