float.sizeof should be 4

Johan j at j.nl
Sun Sep 22 16:45:23 UTC 2024


On Sunday, 22 September 2024 at 14:59:36 UTC, Timon Gehr wrote:
> On 9/22/24 14:59, Steven Schveighoffer wrote:
>> Not `4LU`.
>> 
>> For the billionth time while porting raylib to D, I'm having 
>> to replace `n*float.sizeof` with `n*int(float.sizeof)` because 
>> otherwise, it doesn't fit into the `int` I'm assigning it to.
>> 
>> Why isn't it just 4? 4 will convert to any width you want. It 
>> does not poison integer multiplications or additions.
>> 
>> The chances that `T.sizeof > int.max` is near zero. And even 
>> if it did, making it the same as a number literal would just 
>> work -- it would become `size_t` if it was too big.
>> 
>> -Steve
>
> Well, the point of contention is not that `float.sizeof > 
> int.max`. Rather, `n*float.sizeof` could be bigger than 
> `int.max`.

Is that true?
`n*int(float.sizeof)` could also be bigger than `int.max`, but 
Steven says it works for his case.  (@Steven: best to show the 
full case).

-Johan



More information about the Digitalmars-d mailing list