The Elk Code
gcd.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2002-2005 J. K. Dewhurst, S. Sharma and C. Ambrosch-Draxl.
3 ! This file is distributed under the terms of the GNU Lesser General Public
4 ! License. See the file COPYING for license details.
5 
6 !BOP
7 ! !ROUTINE: gcd
8 ! !INTERFACE:
9 integer function gcd(x,y)
10 ! !INPUT/OUTPUT PARAMETERS:
11 ! x : first integer (in,integer)
12 ! y : second integer (in,integer)
13 ! !DESCRIPTION:
14 ! Computes the greatest common divisor (GCD) of two integers using Euclid's
15 ! algorithm.
16 !
17 ! !REVISION HISTORY:
18 ! Created September 2004 (JKD)
19 !EOP
20 !BOC
21 implicit none
22 ! arguments
23 integer, intent(in) :: x,y
24 ! local variables
25 integer a,b,c
26 if ((x < 1).or.(y < 1)) then
27  write(*,*)
28  write(*,'("Error(gcd): x < 1 or y < 1 : ",2I8)') x,y
29  write(*,*)
30  stop
31 end if
32 if (x >= y) then
33  a=x
34  b=y
35 else
36  a=y
37  b=x
38 end if
39 10 continue
40 c=mod(a,b)
41 a=b
42 b=c
43 if (c > 0) goto 10
44 gcd=a
45 end function
46 !EOC
47 
integer function gcd(x, y)
Definition: gcd.f90:10