APPENDIX A - Diagnosing integer arithmetic type
***********************************************
This method of diagnosing the integer arithmetic type is due to
Bill Gosper (MIT AI Memo 239, February 1972, also known as HAKMEM).
The following example program should be compiled with a switch that
disables integer overflow trapping.
$ FORTRAN/CHECK=NOOVERFLOW (VMS)
f77 (UNIX)
PROGRAM POWER2
C ------------------------------------------------------------------
INTEGER
* I,
* N,
* SUM
C ------------------------------------------------------------------
N = 1
SUM = N
WRITE(*,*) 1, SUM
C ------------------------------------------------------------------
DO I = 2, 100
N = 2 * N
SUM = SUM + N
WRITE(*,*) I, SUM
ENDDO
C ------------------------------------------------------------------
END
If the second output column initially increases, and then becomes
constant:
Constant's value Arithmetic type
---------------- ---------------
-1 Two's complement
> 0 Sign-magnitude
If the whole series (from the beginning) is periodic with period > 1
(not just constant), the machine uses one's complement arithmetic.
If the series tail (without the beginning) is periodic with period > 1
(not just constant), the machine is not binary.
If you get an 'out of memory' message, your machine uses multiple
precision arithmetic and represents numbers with strings.