'int' is enough for 'length' to migrate code from x86 to x64

via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 24 11:27:04 PST 2014


On Monday, 24 November 2014 at 19:06:35 UTC, Matthias Bentrup 
wrote:
> There is no right or wrong in Mathematics, only true and false.
> The result of modular addition with overflow is not wrong, it is
> just different than the result of integer addition.

I think we are talking past each other. In my view the term 
"overflow" has nothing to do with mathematics, overflow is a 
signal from the ALU that the computation is incorrect e.g. not in 
accordance with the intended type.

> Agreed, though I don't like the explosion of new operators. I'd
> prefer the C# syntax like check(<expression>), wrap(expression),
> saturate(expression).

Yep, that is another way to do it. What is preferable probably 
varies from case to case.

> And can fail spectacularly in others. The compiler always has to
> prepare for the worst case, i.e. the largest integer size
> possible, while in practice you may need that only for a few
> extreme cases.

In some loops it probably can get tricky to get it right without 
help from the programmer. I believe some languages allow you to 
annotate loops with an upper boundary to help the semantic 
analysis, but you could also add more frequent overflow checks on 
request?


More information about the Digitalmars-d mailing list