GCD()

Fortran version:

Fortran-90 generic routines GCD(), LCM for I/O API-3.2: compiler selects the appropriate type-specific form depending upon the number and types of the keys and key-lists:
    INTEGER FUNCTION  GCD( P, Q )
        <type>, INTENT( IN ) :: P, Q
    INTEGER FUNCTION  LCM( P, Q )
        <type>, INTENT( IN ) :: P, Q

Type-specific forms:

    INTEGER    FUNCTION  GCDI( I1, I2 )
    INTEGER(8) FUNCTION  GCDL( L1, L2 )
    INTEGER    FUNCTION  LCMI( I1, I2 )
    INTEGER(8) FUNCTION  LCML( L1, L2 )
        INTEGER,    INTENT( IN ) :: I1, I2
        INTEGER(8), INTENT( IN ) :: L1, L2

C version:

    int GCD( const int *p, const int *q ) ;

Summary:

GCD() returns the greatest common divisor, and LCM() returns the least common multiple of integers P,Q.

For generic version, Fortran-90 declarations, and interface checking:

    USE M3UTILIO
    

Preconditions:

#include "iodecl3.h" if called from C.

Fortran Usage:

    ...
    USE M3UTILIO
    ...
    INTEGER     P, Q, D
    INTEGER(8)  L, M, N
    ...
    D = GCD( P, Q )   !  Now D is the gcd of P,Q
    ...
    N = GCD( L, M )   !  Now N is the gcd of L,M
    ...
    ...
    D = LCM( P, Q )   !  Now D is the lcm of P,Q
    ...
    N = LCM( L, M )   !  Now N is the lcm of L,M
    ...

C Usage:

    ...
    #include "iodecl3.h"                          
    ...
    int  p, q, d ;
    ...
    d = GCD( &p, &q ) ; /*  Now d is GCD of p,q */
    ...


Previous: FIND1, FIND2, FIND3, FIND4

Next: GCTP

Up: Utility Routines

To: Models-3/EDSS I/O API: The Help Pages