One solution would be to create a class around a 64-bit int that overrides arithmetic operators to check before performing the operation.
I canβt remember the operatorX syntax from the top of my head (I switched from C ++ to Java long ago), but the sample would be as follows:
int64 myint64::add (int64 a, int64 b) { if (MAX_INT64 - a > b) { // error condition here. } return a + b; } int64 myint64::mul (int64 a, int64 b) { if (MAX_INT64 / a > b) { // error condition here. } return a * b; }
Similarly for any other arithmetic operation, although it can become very difficult for uncharacteristic functions such as powers, factorials, etc.
However, if you build those of the basic arithmetic building blocks, they will work.
source share