This has probably been covered - maybe there is an article somewhere ?
I have a program that makes use of INTEGER arithmetic in quite a few places.
I would like to KNOW when an integer operation causes a bad result.
I was wondering if there is a way to automatically find out when this occurs,
other than putting in dozens of IF tests.
For example, if I have m=N*7, if there is an overflow, m and N will have different signs
about half the time. In the old IBM 7094 CPUs, this would trap if that occurs, but apparently the INTEL
does not give us that option.
any thoughts on this ?
It has been covered on the previous times you asked the same question. If it is important to your code write a couple of subroutines to operate on two integers passed in, one to add and one to multiply. You can then extensively test the args for overflow / truncation etc and return an error status..... It won't take a great deal of time to do.
Additional comments on Andrew's suggestion:
If you are really a tickler, you may also need to add unary negate (protect against -Z"80000000" being Z"80000000").
... or ,,,
You might want to extend the feature to use Z"80000000" as an integer equivalent to NaN (which can also be used a indicator for uninitialized vriable).
Then using the Fortran Preprocessor, you function calls to overflow detection routines can alternately expand to inline statements.
! some header #included
#define ADD(a,b) iov_ADD(a,b)
#define ADD(a,b) (a+b)
C = ADD(A,B)