[cfp-interest 3948] Re: Weird Casting Error

Joshua Cranmer joshua.cranmer at intel.com
Wed Jun 10 08:35:56 PDT 2026


On 6/9/2026 20:14, Damian McGuckin wrote:
> Mind you, if x can be guaranteed positive, it is perfectly legitimate. 
> But if not, it is cause of a subtle bug.
>
> Why does C allow a cast from a signed floating point datum to an 
> unsigned integer datum when that primitive does not exist in IEEE 754. 
> Is it purely historical. Just curious. 

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.



More information about the cfp-interest mailing list