! 	This F90 program shows difference in accuracy of integer variables
!	==============================
        program f90var4
	implicit none

        integer          :: x1, y1, z1
        integer(1)       :: x2, y2, z2
        integer(2)       :: x3, y3, z3
        integer(4)       :: x4, y4, z4
        integer(8)       :: x5, y5, z5

! ===================================================
! Multiply single precision integers
! ===================================================
	x1 = 1023; y1 = 1023; z1 = x1*y1
	print *
	print *, "Integer: ", x1, " * ", y1, " = ", z1

! ===================================================
! Add byte size integers, no overflow
! ===================================================
	x2 = 126; y2 = 1; z2 = x2 + y2		! 2^7 = 128
	print *
	print *, "Integer(1): ", x2, " + ", y2, " = ", z2

! ===================================================
! Add byte size integers, OVERFLOW
! ===================================================
	x2 = 127; y2 = 1; z2 = x2 + y2		! Overflow !!!!
	print *
	print *, "Integer(1): ", x2, " + ", y2, " = ", z2, " ....Overflow !"

! ===================================================
! Add short size integers, no overflow
! ===================================================
	x3 = 32766; y3 = 1; z3 = x3 + y3	! 2^15 = 32768
	print *
	print *, "Integer(2): ", x3, " + ", y3, " = ", z3

! ===================================================
! Add short size integers, OVERFLOW
! ===================================================
	x3 = 32767; y3 = 1; z3 = x3 + y3	! Overflow
	print *
	print *, "Integer(2): ", x3, " + ", y3, " = ", z3, " ....Overflow !"

! ===================================================
! Shows that integer(4) is same as integer
! ===================================================
	x4 = 1023; y4 = 1023; z4 = x4 * y4
	print *
	print *, "Integer(4): ", x4, " * ", y4, " = ", z4

! ===================================================
! Shows overflow with integer(4) type
! ===================================================
	x4 = 1046529; y4 = 1046529; z4 = x4*y4
	print *
	print *, "Integer(4): ", x4, " * ", y4, " = ", z4, " ....Overflow !"

! ===================================================
! Shows that we can use larger integer to overcome overflow 
! ===================================================
	x5 = 1046529; y5 = 1046529; z5 = x5*y5
	print *
	print *, "Integer(8): ", x5, " * ", y5, " = ", z5

	stop
	end
