[OT] The Usual Arithmetic Confusions
Dukc
ajieskola at gmail.com
Wed Feb 2 21:42:43 UTC 2022
On Monday, 31 January 2022 at 08:38:28 UTC, Ola Fosheim Grøstad
wrote:
> On Monday, 31 January 2022 at 07:33:00 UTC, Elronnd wrote:
>> I have no doubt it comes up _at all_. What I am asking is
>> that I do not believe it has an _appreciable_ effect on any
>> real software.
>
> Not if you work around it, but ask yourself: is it a good idea
> to design your language in such a way that the compiler is
> unable to remove this:
>
> ```
> if (x < x + 1) { … }
> ```
>
> Probably not.
It is a good idea. You can manually optimise that `if` out if
performance is important. Manual optimisation is a must to get
performant code anyway so not really a big deal. In the opposite
case we would have undefined behaviour at `@safe` code.
We have array bounds checks for the exact same reason. They do
penaltise the performance a bit, but prevent undefined behaviour
and can be manually optimised out when performace is more
important than memory protection.
More information about the Digitalmars-d
mailing list