C C C----------------------------------------------------------------------------- C C FUNCTION: G C D I C C AUTHOR: Jan H. Belgraver C C DATE: 29-NOV-83 C C VERSION: V1.0 C C MODIFIED BY: C C PURPOSE: Computes the Greatest Common Divisor of two integers. C C DESCRIPTION: Step 1 C Subtract the 2nd number (I2) as many times as possible C from the 1st one (I1) and save remainder using FORTRAN C function MOD. C Step 2 C Test if remainder is equal to zero, if so GCD = I2. C If not replace I1 with I2 and I2 with remainder and C proceed with step 1. C Repeat both steps until remainder becomes zero. C C CALL: result = GCDI (I1, I2) C C ARGUMENTS: NAME DESCRIPTOIN C I I1 Integer value (INTEGER*4) C I I2 Integer value (INTEGER*4) C O result Contains GCD (INTEGER*4) C C CALLS TO: MOD C C----------------------------------------------------------------------------- C C C C INTEGER*4 FUNCTION G C D I ( I1, I2 ) C C INTEGER*4 I1, I2, IREST 10 IREST = MOD (I1, I2) IF (IREST .EQ. 0) GOTO 20 I1 = I2 I2 = IREST GOTO 10 20 GCDI = IABS (I2) RETURN END