{
  "category": "Math and trigonometry functions",
  "display_name": "GCD",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.GCD",
  "implementation_state": {
    "answer_bank": {
      "excel_builds": [
        "20430"
      ],
      "larger_numeric": 0,
      "last_bit": 0,
      "matched": 7966,
      "other_mismatch": 0,
      "refused": 0,
      "rows": 7966,
      "unread": 0,
      "worst_ulp": 0
    },
    "detail": "Recorded: 7,966 in the answer bank and 6 workbook cells.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 7,972 recorded answers",
    "workbook_corpus": {
      "cells": 6,
      "matched": 6
    }
  },
  "implementations": [
    {
      "commit": "9e1884369a678158dd82d3d74188daf986995e87",
      "flavour": "excel-compatibility-candidate",
      "language": "Rust",
      "name": "CalcFunc",
      "own_code": [
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/math.rs#L134-L137",
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/ported/gcd_fn.rs#L4-L6"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "catalogue/math::integer_groups",
        "ported/gcd_lcm_common::gcd_int"
      ],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/math.rs#L134-L137",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 7,972 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.GCD.json",
  "name": "GCD",
  "notes": [
    {
      "basis": "All recorded rows match after the boundary change: GCD 7,966 of 7,966 and LCM 7,967 of 7,967.",
      "documentation": {
        "claim": "If a parameter to GCD is >=2^53, GCD returns the #NUM! error value. If LCM(a,b) >=2^53, LCM returns the #NUM! error value.",
        "source": "https://support.microsoft.com/en-us/office/gcd-function-d5107a51-69e3-461f-8e4c-ddfc21b5073a; https://support.microsoft.com/en-us/office/lcm-function-7152b67a-8bb5-4075-ae5c-06ede5563c94"
      },
      "evidence": [
        {
          "commit": "9c23dde1dfd6d93e742d763a4bad3eaec229b29c",
          "locator": "recorded_gcd_lcm_admit_the_exact_operand_boundary",
          "note": "recorded readings pinned",
          "path": "apps/dna-onecalc/tests/acceptance.rs",
          "repository": "DnaCalc"
        }
      ],
      "functions": [
        "FUNC.GCD",
        "FUNC.LCM"
      ],
      "inferred": null,
      "kind": "documentation-differs",
      "note_id": "FN-GCD-001",
      "open": [],
      "recorded_on": "2026-11-04",
      "repros": [
        {
          "call": "GCD(9007199254740992, 1)",
          "correct": null,
          "excel": {
            "bits": "0x3ff0000000000000",
            "display": "1",
            "kind": "number"
          },
          "input_route": "cell-value2",
          "inputs": [
            {
              "name": "number1",
              "value": {
                "bits": "0x4340000000000000",
                "display": "9007199254740992",
                "kind": "number"
              }
            },
            {
              "name": "number2",
              "value": {
                "bits": "0x3ff0000000000000",
                "display": "1",
                "kind": "number"
              }
            }
          ],
          "recorded_in": "Excel 16.0 build 20430, Windows 64-bit, CPU not recorded in this capture",
          "source": {
            "commit": "4d5320dfdc385354469b4d506153357bb932ab08",
            "locator": "w111boundary-GCD-00190",
            "note": null,
            "path": "runs/w111-integer-publication-20260929/answers/answers-gcd.json.gz",
            "repository": "CalcFunc-Evidence"
          }
        },
        {
          "call": "LCM(9007199254740992, 2)",
          "correct": null,
          "excel": {
            "bits": "0x4340000000000000",
            "display": "9007199254740992",
            "kind": "number"
          },
          "input_route": "cell-value2",
          "inputs": [
            {
              "name": "number1",
              "value": {
                "bits": "0x4340000000000000",
                "display": "9007199254740992",
                "kind": "number"
              }
            },
            {
              "name": "number2",
              "value": {
                "bits": "0x4000000000000000",
                "display": "2",
                "kind": "number"
              }
            }
          ],
          "recorded_in": "Excel 16.0 build 20430, Windows 64-bit, CPU not recorded in this capture",
          "source": {
            "commit": "4d5320dfdc385354469b4d506153357bb932ab08",
            "locator": "w111boundary-LCM-00194",
            "note": null,
            "path": "runs/w111-integer-publication-20260929/answers/answers-lcm.json.gz",
            "repository": "CalcFunc-Evidence"
          }
        },
        {
          "call": "GCD(9007199254740994, 0)",
          "correct": null,
          "excel": {
            "bits": null,
            "display": "#NUM!",
            "kind": "error"
          },
          "input_route": "cell-value2",
          "inputs": [
            {
              "name": "number1",
              "value": {
                "bits": "0x4340000000000001",
                "display": "9007199254740994",
                "kind": "number"
              }
            },
            {
              "name": "number2",
              "value": {
                "bits": "0x0000000000000000",
                "display": "0",
                "kind": "number"
              }
            }
          ],
          "recorded_in": "Excel 16.0 build 20430, Windows 64-bit, CPU not recorded in this capture",
          "source": {
            "commit": "4d5320dfdc385354469b4d506153357bb932ab08",
            "locator": "w111boundary-GCD-00217",
            "note": null,
            "path": "runs/w111-integer-publication-20260929/answers/answers-gcd.json.gz",
            "repository": "CalcFunc-Evidence"
          }
        }
      ],
      "schema": "efh.function-note/v1",
      "statement": "GCD accepts an operand equal to 2^53, and LCM accepts an operand or a result equal to 2^53. Only values above 2^53 give #NUM!.",
      "status": "measured",
      "title": "GCD and LCM accept 2^53 itself, not only values below it"
    }
  ],
  "schema": "efh.function-reference/v1",
  "section_order": [
    "what-it-does",
    "try-it",
    "quirks",
    "how-to-implement",
    "version-differences",
    "alternatives"
  ],
  "sections": {
    "alternatives": "\n### Relationships\n\n- **[MOD](FUNC.MOD.md)** — the primitive the Euclidean algorithm is built from. `GCD` is what\n  repeated `MOD` converges to.\n- **[QUOTIENT](FUNC.QUOTIENT.md)** and **[INT](FUNC.INT.md)** — the other truncating integer\n  operations; each truncates by a different rule, and only `INT` floors.\n- **`MULTINOMIAL`** — the other variadic integer-combinatorial function in\n  this category, and one that shares `GCD`'s group structural evidence record.\n- Readers reach for `GCD` most often to reduce a fraction: `n/GCD(n,d)` over `d/GCD(n,d)`. That\n  usage never approaches the documented 2^53 ceiling, which is why the ceiling is so rarely\n  noticed.\n\n\n",
    "how-to-implement": "\n### Numerical notes\n\n\n`GCD` is one of the few functions in the math category with **no floating-point error at all**\nin its intended domain — every intermediate value is an exact integer — and yet it has a\ngenuine numerical hazard, which is the representation boundary rather than rounding.\n\n**The 2^53 wall.** Arguments arrive as binary64. Below 2^53 every integer is exactly\nrepresentable and truncation recovers exactly the integer the user typed. At or above 2^53 the\ndoubles are spaced two or more apart, so the value that arrives is not necessarily the integer\nthat was written, and a gcd computed from it is the gcd of a rounded neighbour. Microsoft's\ndocumented `#NUM!` at 2^53 is precisely a refusal to answer a question that can no longer be\nasked. An implementation that instead converts to a 64-bit integer inherits a *different*\nboundary at 2^63, and above that the conversion saturates or wraps — which is how a function\nwith no rounding error still produces a wrong answer.\n\n**Algorithm choice.** Euclid's algorithm with remainder (Knuth, *TAOCP* volume 2, section 4.5.2)\nruns in O(log min(*a*, *b*)) divisions; the binary GCD of Stein replaces division with shifts\nand subtraction and is usually faster on hardware without a fast integer divide. Both are exact,\nso the choice is performance-only — unusually for this category, there is no accuracy trade-off\nto weigh. The variadic fold benefits from an early exit: once the running gcd reaches 1 no later\nargument can change it, and the remaining arguments need only be validated, not divided.\n\n**What a careful implementation does about the boundary**, in order of decreasing preference:\nguard the documented domain explicitly and return `#NUM!`; or, if a wider domain is wanted,\ncarry the reduction in a type wide enough to hold every finite double's integer part and state\nthe widened domain as a deliberate, documented departure. What it must not do is convert to a\nfixed-width integer and let the conversion decide.\n\n\n",
    "quirks": "\n### Result and edge cases\n\n\nReturns `Number` — a non-negative integer value.\n\n- **Zero alone** yields zero, consistent with the identity-element reading above.\n- **A logical argument** is accepted and converted; **numeric text** is accepted and then\n  truncated. Neither case is covered by Microsoft's page, which speaks only of \"nonnumeric\".\n- **An inline array argument** is consumed as a set of values and reduced to one result, not\n  lifted elementwise. This is the aggregate shape, not the scalar-kernel shape.\n- **An empty range** produces `#VALUE!` rather than the zero that the identity element would\n  suggest.\n- **A subnormal magnitude** truncates to zero and therefore contributes nothing.\n\n\n\n### Errors\n\n\nAs documented on Microsoft's `GCD` page:\n\n| Error | Documented condition |\n|---|---|\n| `#VALUE!` | \"If any argument is nonnumeric, GCD returns the #VALUE! error value.\" |\n| `#NUM!` | \"If any argument is less than zero, GCD returns the #NUM! error value.\" |\n| `#NUM!` | \"If a parameter to GCD is >=2^53, GCD returns the #NUM! error value.\" |\n\nError values in any argument propagate under the shared coercion discipline.\n\n",
    "sources": "- Microsoft, \"GCD function\" —\n  <https://support.microsoft.com/en-us/office/gcd-function-d5107a51-69e3-461f-8e4c-ddfc21b5073a>.\n  Retrieved for this page: the syntax, the \"1 to 255 values\" count, the truncation rule, the\n  `#VALUE!` nonnumeric remark, the `#NUM!` negative remark, the `#NUM!` at 2^53 remark, and the\n  \"One divides any value evenly\" / prime-divisor notes.\n- Handbook, [the value universe](../model/01-value-universe.md) and\n  [coercion and lifting](../model/02-coercion-and-lifting.md) — value kinds, to-number outcomes,\n  error propagation, and the aggregate-versus-lift distinction.\n- D. E. Knuth, *The Art of Computer Programming*, volume 2, section 4.5.2 — Euclid's algorithm,\n  its complexity, and the binary (Stein) variant.\n- `data/presence/FUNC.GCD.json` — the implementing module, its Lean companion, and the\n  `BUG-FUNC-028` defect stream that the structural record above resolves.\n\n",
    "version-differences": "The recorded environments below distinguish a reading from a same-input comparison. Counts describe captured inputs in each environment; overlapping captures and comparisons are not totals of unique worksheet calls.\n\n| Excel 16.0 build | Platform and CPU | Captured inputs |\n|---|---|---:|\n| 20430 | Windows, 64-bit, CPU not recorded | 7,966 |\n\nThe record contains no same-input comparison between these environments. Reading different inputs on different builds does not establish either a version change or cross-build agreement.\n\n[Recorded environments and comparison details](https://github.com/DnaCalc/ExcelFunctionsHandbook/blob/5dc75391aa5125ccc5abdb095da85950980d6fd8/content/evidence/environments/FUNC.GCD.json).",
    "what-it-does": "\n`GCD(number1, [number2], ...)` returns the greatest common divisor of its arguments after each\nhas been truncated to an integer.\n\nThe mathematics is the oldest algorithm in the book. For integers *a*, *b* not both zero,\ngcd(*a*, *b*) is the largest positive integer dividing both. The definition extends to any\nnumber of arguments by associativity:\n\n    gcd(a, b, c) = gcd(gcd(a, b), c)\n\nso the *n*-argument function is a left fold of the binary one, in any order — gcd is\ncommutative and associative, which is why Excel can accept up to 255 arguments without\ndeclaring an evaluation order.\n\nThe structural facts worth carrying:\n\n- **gcd(*a*, 0) = *a***, and **gcd(0, 0) = 0**. Zero is the identity element: every integer\n  divides zero, so zero contributes nothing to the meet. This is not a special case bolted on;\n  it is what makes gcd a well-defined operation on the whole of the non-negative integers.\n- **gcd(*a*, 1) = 1.** Microsoft's page states the same fact in its own words — \"One divides any\n  value evenly\" — and notes that \"A prime number has only itself and one as even divisors.\"\n- **gcd and lcm are dual.** Under divisibility, the non-negative integers form a lattice in\n  which gcd is the meet and lcm the join. For exactly two arguments,\n  gcd(*a*, *b*) · lcm(*a*, *b*) = *a* · *b*. **That identity does not extend to three or more\n  arguments**, and readers who assume it does are the main source of wrong `LCM` formulas.\n- **Bézout.** gcd(*a*, *b*) is the smallest positive integer expressible as *ax* + *by*. Excel\n  exposes no function that returns the Bézout coefficients, so the extended algorithm is not\n  reachable from the worksheet.\n\nDomain: non-negative integers after truncation. Range: non-negative integers.\n\n\n\n### Arguments\n\n\n| Argument | Meaning | Required |\n|---|---|---|\n| `number1` | The first value. | Yes |\n| `number2`, … | Further values. | No |\n\nTwo properties of the truncation rule deserve emphasis.\n\n1. **Truncation happens before the arithmetic, not after.** `GCD(2.5, 5)` is the gcd of 2 and\n   5, not a rounding of some fractional gcd. Fractional arguments are silently reinterpreted;\n   there is no warning.\n2. **The documented rule says \"truncated\", not \"rounded\".** For non-negative inputs — the only\n   ones `GCD` accepts — truncation toward zero and floor agree, so the two readings cannot be\n   distinguished on the admissible domain. The distinction that bites elsewhere in the math\n   category (see [INT](FUNC.INT.md)) is invisible here.\n\nArgument slots are numeric and subject to ordinary to-number coercion; see\n[coercion and lifting](../model/02-coercion-and-lifting.md). Range arguments are scanned rather\nthan lifted — `GCD` is declared with a custom coercion profile rather than the scalar-lift\nprofile used by single-argument math functions.\n\n\n"
  },
  "signature": {
    "display": "GCD(number1, [number2], ...)",
    "parameters": [
      {
        "description": null,
        "name": "number1",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "number2",
        "optional": true,
        "repeats": true
      }
    ],
    "trailing_repeats": true
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "implemented",
        "reason": null
      },
      "arity": {
        "max": 255,
        "min": 1
      },
      "category": "Math and trigonometry functions",
      "classification": {
        "arg_preparation_profile": "ValuesOnlyPreAdapter",
        "coercion_lift_profile": "Custom",
        "determinism_class": "Deterministic",
        "error_collapse_profile": "None",
        "fec_dependency_profile": "None",
        "host_interaction_class": "None",
        "kernel_signature_class": "Custom",
        "rich_value_usage": "RichBlind",
        "surface_fec_dependency_profile": "RefOnly",
        "thread_safety_class": "SafePure",
        "volatility_class": "NonVolatile"
      },
      "descriptions": {
        "long": null,
        "short": "Greatest common divisor of whole numbers",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Returns the greatest common divisor",
        "microsoft_url": "https://support.microsoft.com/en-us/office/gcd-function-d5107a51-69e3-461f-8e4c-ddfc21b5073a"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "GCD"
        },
        {
          "locale": "bg-BG",
          "name": "GCD"
        },
        {
          "locale": "cs-CZ",
          "name": "GCD"
        },
        {
          "locale": "da-DK",
          "name": "STØRSTE.FÆLLES.DIVISOR"
        },
        {
          "locale": "de-DE",
          "name": "GCD"
        },
        {
          "locale": "el-GR",
          "name": "GCD"
        },
        {
          "locale": "en-AU",
          "name": "GCD"
        },
        {
          "locale": "en-GB",
          "name": "GCD"
        },
        {
          "locale": "en-US",
          "name": "GCD"
        },
        {
          "locale": "es-ES",
          "name": "M.C.D"
        },
        {
          "locale": "et-EE",
          "name": "GCD"
        },
        {
          "locale": "fi-FI",
          "name": "SUURIN.YHT.TEKIJÄ"
        },
        {
          "locale": "fr-FR",
          "name": "PGCD*"
        },
        {
          "locale": "he-IL",
          "name": "GCD"
        },
        {
          "locale": "hr-HR",
          "name": "GCD"
        },
        {
          "locale": "hu-HU",
          "name": "LKO"
        },
        {
          "locale": "id-ID",
          "name": "GCD"
        },
        {
          "locale": "it-IT",
          "name": "GCD"
        },
        {
          "locale": "ja-JP",
          "name": "GCD"
        },
        {
          "locale": "ko-KR",
          "name": "GCD"
        },
        {
          "locale": "lt-LT",
          "name": "GCD"
        },
        {
          "locale": "lv-LV",
          "name": "GCD"
        },
        {
          "locale": "nb-NO",
          "name": "GCD"
        },
        {
          "locale": "nl-NL",
          "name": "GGD"
        },
        {
          "locale": "pl-PL",
          "name": "NAJW.WSP.DZIEL"
        },
        {
          "locale": "pt-BR",
          "name": "GCD"
        },
        {
          "locale": "pt-PT",
          "name": "MDC"
        },
        {
          "locale": "ro-RO",
          "name": "GCD"
        },
        {
          "locale": "ru-RU",
          "name": "НОД"
        },
        {
          "locale": "sk-SK",
          "name": "GCD"
        },
        {
          "locale": "sl-SI",
          "name": "GCD"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "GCD"
        },
        {
          "locale": "sv-SE",
          "name": "SGD"
        },
        {
          "locale": "th-TH",
          "name": "GCD"
        },
        {
          "locale": "tr-TR",
          "name": "OBEB işlevi"
        },
        {
          "locale": "uk-UA",
          "name": "GCD"
        },
        {
          "locale": "vi-VN",
          "name": "GCD"
        },
        {
          "locale": "zh-CN",
          "name": "GCD"
        },
        {
          "locale": "zh-HK",
          "name": "GCD"
        },
        {
          "locale": "zh-TW",
          "name": "GCD"
        }
      ],
      "signature": {
        "display": "GCD(number1, [number2], ...)",
        "parameters": [
          {
            "description": null,
            "name": "number1",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "number2",
            "optional": true,
            "repeats": true
          }
        ],
        "trailing_repeats": true
      },
      "surface_name": "GCD",
      "version_marker": null,
      "xlcall": {
        "code": "473",
        "symbol": "xlfGcd"
      }
    },
    "microsoft": "https://support.microsoft.com/en-us/office/gcd-function-d5107a51-69e3-461f-8e4c-ddfc21b5073a"
  },
  "try_it": {
    "formula": "=GCD(2.5, 5)"
  },
  "url": "https://handbook.dnacalc.com/functions/GCD.html",
  "variants": [],
  "versions": [
    {
      "behaviour": "GCD(9007199254740992, 1) returned 1 (0x3ff0000000000000). GCD(9007199254740994, 0) returned #NUM!. Inputs were supplied through cells using Value2. These are controls from this environment, not a same-input comparison with another build.",
      "excel_build": "16.0 build 20430",
      "observations": [
        {
          "call": "GCD(9007199254740992, 1)",
          "excel": {
            "bits": "0x3ff0000000000000",
            "display": "1",
            "kind": "number"
          },
          "input_route": "cell-value2",
          "inputs": [
            {
              "name": "number1",
              "value": {
                "bits": "0x4340000000000000",
                "display": "9007199254740992",
                "kind": "number"
              }
            },
            {
              "name": "number2",
              "value": {
                "bits": "0x3ff0000000000000",
                "display": "1",
                "kind": "number"
              }
            }
          ],
          "recorded_in": "Excel 16.0 build 20430, Windows 64-bit, CPU not recorded in this capture"
        },
        {
          "call": "GCD(9007199254740994, 0)",
          "excel": {
            "bits": null,
            "display": "#NUM!",
            "kind": "error"
          },
          "input_route": "cell-value2",
          "inputs": [
            {
              "name": "number1",
              "value": {
                "bits": "0x4340000000000001",
                "display": "9007199254740994",
                "kind": "number"
              }
            },
            {
              "name": "number2",
              "value": {
                "bits": "0x0000000000000000",
                "display": "0",
                "kind": "number"
              }
            }
          ],
          "recorded_in": "Excel 16.0 build 20430, Windows 64-bit, CPU not recorded in this capture"
        }
      ],
      "platform": "Windows 64-bit, CPU not recorded in this capture",
      "sources": [
        "https://github.com/DnaCalc/ExcelFunctionsHandbook/blob/3345a87/content/notes/FN-GCD-001.json"
      ]
    },
    {
      "behaviour": "7,966 captured inputs are indexed for this environment. Capture dates: 2026-09-29 to 2026-09-29. This is a reading count, not a comparison with another build.",
      "excel_build": "16.0 build 20430",
      "platform": "Windows, 64-bit, CPU not recorded",
      "sources": [
        "https://github.com/DnaCalc/ExcelFunctionsHandbook/blob/5dc75391aa5125ccc5abdb095da85950980d6fd8/content/evidence/environments/FUNC.GCD.json"
      ]
    }
  ]
}