float.sizeof should be 4

Dom DiSc dominikus at scherkl.de
Tue Sep 24 10:49:45 UTC 2024


On Tuesday, 24 September 2024 at 03:23:31 UTC, Jonathan M Davis 
wrote:
> So, the issue really isn't the value itself. That will convert 
> to other sizes just fine, particularly since it's known at 
> compile time. Rather, what matters is what you get when you do 
> math on it

Doing math most of the time involves at least two values, in this 
case sizeof (of type size_t) and 4 (a nibble).
It should be clearly defined in what type such an operation 
should result. Best would be: the larger type of the two 
operands, here size_t (but for multiplication also the next 
larger type would be reasonable, if you want to be sure to never 
get an overflow).
So if you do ubyte * 4 the result should be ubyte, because ubyte 
is the larger of the two types.
It doesn't matter that the calculation is done in the size of the 
registers of the machine, may that be 8bit, 16bit, 32bit or 64bit 
(or maybe any unusual odd word size), but the result should be 
per default restricted to the type of the larger operand (or 
collected from multiple registers if the type is larger than the 
machine word size).
If you want a different result type, you should cast at least one 
of the operands to the desired result type beforehand.

Of course there is also math with only one value. This should 
result in the same type as the operand. The unitary operators 
should NEVER change the type of its parameter. This is an awful 
behaviour of D that should be burned with fire!


More information about the Digitalmars-d mailing list