Solution for Arithmetic overflow

BobTPH

Joined Jun 5, 2013
11,463
By using a larger integer type.

I.e. to guarantee you don’t get an overflow when adding two ints, use a long int.
 

WBahn

Joined Mar 31, 2012
32,703
You can detect that overflow either did happen or is about to happen and then take appropriate action. The application determines what action is appropriate.
 

MrAl

Joined Jun 17, 2014
13,667
How are Arithmetic overflows overcome.
Hello,

This depends a lot on what you mean by "overcome".

If you intend to 'overcome' by being able to handle more digits, then you need a larger register length.

If you need to 'overcome' by just detecting an overflow, then the most basic way is to use a carry flag. If the result overflows the carry flag is set, which could result from an addition operation. If the result underflows the carry flag may be set or reset depending on the way it works and then it is sometimes referred to as a 'borrow' flag, which could result from a subtraction operation. These ideas are used in a lot of CPU chips.
 

olphart

Joined Sep 22, 2012
124
ALL math routines Should be checked for violations - all cpus have suitable flags.
This can be a speed advantage: use 8 bit math, and on under / overflow, decrement / increment the next 8 bit memory (register).
'Mem to check That register for cascading value.
 
Top