I am creating Lisp and I want 32-bit integers to automatically switch to 64-bit integers if the calculation leads to their overflow. Similarly, for 64-bit overflows, switch to integers of arbitrary size.
The problem is that I do not know what the βcorrectβ way to detect integer overflows.
a, b := 2147483647, 2147483647 c := a + b
How can I effectively check if c is full?
I always considered converting to 64-bit values ββfor computation, and then reduce the size after that whenever possible, but it seems expensive, and memory is wasteful for something that is primitive and core to the language as basic arithmetic.
go integer-overflow
d11wtq
source share