[OT] The Usual Arithmetic Confusions
bachmeier
no at spam.net
Thu Feb 17 19:15:04 UTC 2022
On Thursday, 17 February 2022 at 18:14:46 UTC, Elronnd wrote:
> On Thursday, 17 February 2022 at 17:53:58 UTC, bachmeier wrote:
>> writeln(-1.to!uint);
>
> This is -(1.to!uint). Not (-1).to!uint. Not really a WTF,
> imo; precedence is just something you have to know, and it
> works more or less the same way in most programming languages.
Setting aside the fact that this is maybe 1% of the point of my
post, it's not about precedence. Write it like this if you want
`writeln(-(1.to!uint))` and you'll get the same output. The
language is more than happy to let someone take the negative of a
uint without so much as a warning, even though the ratio of
mistakes to legitimate uses is a gazillion to one.
But that was not the main point of my post. It's the behavior of
iota silently converting good code to bad code when the second
argument changes from 0 to -1. It's hard to trust the code you've
written - something we already know from decades of writing C.
More information about the Digitalmars-d
mailing list