[OT] The Usual Arithmetic Confusions

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Mon Jan 31 18:32:32 UTC 2022


On Monday, 31 January 2022 at 18:12:32 UTC, Ola Fosheim Grøstad 
wrote:
> On Monday, 31 January 2022 at 17:52:17 UTC, Ola Fosheim Grøstad 
> wrote:
>> ```
>> int x;
>> for(int i=1; i<99998; i++){
>>    x = next_monotonically_increasing_int_with_no_sideffect();
>> }
>> assert(x <= maximum_integer_value - 99998);
>>
>> ```
>
> Typo, should have been a "…" in the loop, assuming no 
> sideffects.

Another typo: the loop termination should remain "i<99999", so to 
avoid further confusion… It is equivalent to:

```
int x;
for(int i=1; i<99999; i++){
     x = next_monotonically_increasing_int_with_no_sideffect();
     …
}
assert(x <= maximum_integer_value - 99998);
```

I hope I got it right now… Hm.

Of course a more drastic example would be code that test the 
negated conditional (always false), if you then can deduce the 
last value of x by computation then you can remove the loop 
entirely and only keep the assert statement.

I don't see how that would break the Go spec.



More information about the Digitalmars-d mailing list