Spec on casting to integer with smaller range than value

Stefan Koch uplink.coder at googlemail.com
Sat Mar 28 15:23:19 UTC 2020


On Saturday, 28 March 2020 at 12:09:49 UTC, Johan wrote:
> Hi all,
>   Where can I read in the spec what the outcomes of the 
> following are?
>
> ```
> uint a = 260;
> auto b = cast(ubyte) a;
>
> float f = 1.203125f  * 255.0f;
> auto zz =  cast(ubyte) f;
> // https://github.com/ldc-developers/ldc/issues/3237
> ```
>
> Thanks,
>   Johan

cast (ubyte)x is the same as = ((cast(uint)x) & 0xff)


More information about the Digitalmars-d mailing list