[OT] The Usual Arithmetic Confusions
Paul Backus
snarwin at gmail.com
Thu Feb 17 20:11:07 UTC 2022
On Thursday, 17 February 2022 at 17:53:58 UTC, bachmeier wrote:
> On Friday, 28 January 2022 at 02:15:51 UTC, Paul Backus wrote:
>> Unfortunately, this is also one of the areas of D that comes
>> directly from C, so D programmers have to watch out for these
>> as well.
>
> Here's a lovely one I wrote about yesterday in Learn:
>
> ```
> import std.conv, std.range, std.stdio;
>
> void main() {
> writeln(iota(5, 0, -1));
> writeln(iota(5, -1, -1));
> writeln(iota(5.to!uint, -1, -1));
> writeln(iota(5.to!uint, 0, -1));
> writeln(-1.to!uint);
> auto z = -1;
> writeln(z.to!uint);
> }
> ```
Yeah, implicit signed-to-unsigned conversion is really nasty.
Even if we keep the rest of the C-style promotion rules, getting
rid of that one would still be a big improvement.
More information about the Digitalmars-d
mailing list