Integer arithmetic - a question
WB Kloke
wb@pkeus.de
Wed Jul 23 18:28:20 GMT 2025
> I notice that in GNU Algol 68 integer arithmetic wraps around, that is
AFAIK, Algol68 leaves this behaviour "undefined", i.e. the language does
not guarantee this or any other behaviour. Of course, the intention of the
language designers was to prefer efficiency vs. determinism.
If a program depends on a specific overflow behavier, and you want make
the program portable, I would advise to use a custom integral type.
If you want to avoid wrapping, on modern computers the best thing is to
avoid integer arithmetic (for anything else than index calculation in arrays
and loops) altogether, and use IEEE floating point, perhaps activating
the unexact trap, for 24- or 54-bit integers.
More information about the Algol68
mailing list