Function Math Arithmetic Class

GreatestCommonDivisor

Return the largest number equally divisible by both numbers. Also known as GCD and Greatest Common Factor and GCF.

Signature (Visual Basic / VBA)

Public Function GreatestCommonDivisor( _
      ByVal vX As Variant _
    , ByVal vY As Variant _
    ) As Variant

Code Example

    GreatestCommonDivisor(7, 97) = 1
    GreatestCommonDivisor(12, 64) = 4
    GreatestCommonDivisor(96, 256) = 32
    GreatestCommonDivisor(96, -64) = 32
    GreatestCommonDivisor(-96, 64) = 32
    GreatestCommonDivisor(4590, 1240) = 10
    GreatestCommonDivisor(4590324, 12401234) = 2

Parameters

Parameter Description
vX First of two numbers whose greatest common factor is to be calculated. Function returns Null if vX is Null or cannot be fixed up to a number.
vY Second of two numbers whose greatest common factor is to be calculated. Function returns Null if vY is Null or cannot be fixed up to a number.