Formualizer Docs

GCD

Returns the greatest common divisor of one or two integers.

GCD truncates each argument toward zero before calculating the divisor.

The Formualizer engine in this repository at 0.15.0 plus unreleased changes computes the example results. Known differences from Excel are listed on this page.

Syntax

=GCD(number1, [number2])

Arguments

ArgumentTypeRequiredDefault
number1numberRequired—
number2numberOptional—

Differences from Excel

Formualizer accepts at most two arguments. Excel accepts up to 255.

Remarks

  • Inputs must be between 0 and 9.99999999e9 after truncation, or #NUM! is returned.
  • Any argument error propagates immediately.

Error cases

  • Negative values return #NUM!.

Examples

Compute the result for two positive integers with common factors.

Formula =GCD(18,24)

Expected result 6

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Use fractional inputs to see the effect of truncation.

Formula =GCD(18.7,24.2)

Expected result 6

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Include a zero as one of the operands.

Formula =GCD(0,24)

Expected result 24

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

A negative operand falls outside the supported domain.

Formula =GCD(-18,24)

Expected result #NUM!

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Greatest common divisor of two numbers

Formula =GCD(24, 36)

Expected result 12

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Fractional arguments are truncated

Formula =GCD(18.9, 6)

Expected result 6

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Negative values are invalid

Formula =GCD(-2, 4)

Expected result #NUM!

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

FAQ

What happens to decimal inputs in GCD?

Each argument is truncated toward zero before the divisor is computed.

When does GCD return #NUM!?

Negative values or values outside the supported bound return #NUM!.

Implementation

Engine source

On this page