3 ms·
> "As if infinitely ranged" (AIIR) is an obvious idea but it has flaws. One is the run-time checking that it requires, which is unattractive in a C-like languag
by astrange 5y ago
> "As if infinitely ranged" (AIIR) is an obvious idea but it has flaws. One is the run-time checking that it requires, which is unattractive in a C-like language.
It seems to be acceptable in Swift so far. (Swift traps on overflow on all expressions though, it doesn't use AIR.)
It is unpleasant if you don't like to distinguish between statements and expressions, but it might be usable. Anything is as long as it's well defined.
The main advantage is that it makes it easier to fold away intermediate steps like (x + 1 - 1). This is the kind of thing that looks pointless, but is needed to remove abstractions like in macros or C++y generic code.
If you'd like your functions total (not trapping), then there could be a set of wrapping/saturating operations to go with the default infinitely-ranged ones. Or you could declare x/y/z to be unsigned.