4 ms·
Actually, CL goes a step further, which I like: by default, integer arithmetic is arbitrary precision. There are no overflows, unless you count running out of
by betterunix 13y ago
Actually, CL goes a step further, which I like: by default, integer arithmetic is arbitrary precision. There are no overflows, unless you count running out of RAM to store your numbers as an overflow. Modular arithmetic must be explicitly specified, leaving no room for surprises:
(mod (+ x y) N)
The reason I prefer this behavior to C's is that it is more natural. Most of the time when we think of integer arithmetic, we do not assume that it is modulo N; we assume things like " x - 1 < x " will always be true. Forcing unexpected semantics on programmers is a recipe for bugs, and integer underflow/overflow bugs are not uncommon in C programs.
- dllthomas 13y agoI think that'd probably be inappropriate for C's use cases, but I think generally it's a good move. I do like encoding the modular behavior in the type, FWIW; specifying a mod manually everywhere it goes leads to unreadable code. I agree, however, that it should probably not be the default type.