<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Binary_GCD_algorithm</id>
	<title>Binary GCD algorithm - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Binary_GCD_algorithm"/>
	<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Binary_GCD_algorithm&amp;action=history"/>
	<updated>2026-04-19T07:25:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.sarg.dev/index.php?title=Binary_GCD_algorithm&amp;diff=582606&amp;oldid=prev</id>
		<title>imported&gt;Frap: Add category</title>
		<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Binary_GCD_algorithm&amp;diff=582606&amp;oldid=prev"/>
		<updated>2025-01-28T13:05:04Z</updated>

		<summary type="html">&lt;p&gt;Add category&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Algorithm for computing the greatest common divisor}}&lt;br /&gt;
{{Use dmy dates|date=April 2022}}&lt;br /&gt;
[[File:binary_GCD_algorithm_visualisation.svg|thumb|upright=1.8|Visualisation of using the binary GCD algorithm to find the greatest common divisor (GCD) of 36 and 24.  Thus, the GCD is 2&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; × 3 = 12.]]&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;binary GCD algorithm&amp;#039;&amp;#039;&amp;#039;, also known as &amp;#039;&amp;#039;&amp;#039;Stein&amp;#039;s algorithm&amp;#039;&amp;#039;&amp;#039; or the &amp;#039;&amp;#039;&amp;#039;binary Euclidean algorithm&amp;#039;&amp;#039;&amp;#039;,{{r|brenta|brentb}} is an algorithm that computes the [[greatest common divisor]] (GCD) of two nonnegative integers. Stein&amp;#039;s algorithm uses simpler arithmetic operations than the conventional [[Euclidean algorithm]]; it replaces division with [[arithmetic shift]]s, comparisons, and subtraction.&lt;br /&gt;
&lt;br /&gt;
Although the algorithm in its contemporary form was first published by the physicist and programmer Josef Stein in 1967,&amp;lt;ref name=&amp;quot;Stein&amp;quot;/&amp;gt; it was known by the 2nd century BCE, in ancient China.{{r|Knuth98}}&lt;br /&gt;
&lt;br /&gt;
==Algorithm==&lt;br /&gt;
&lt;br /&gt;
The algorithm finds the GCD of two nonnegative numbers &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; by repeatedly applying these identities:&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;math&amp;gt;\gcd(u, 0) = u&amp;lt;/math&amp;gt;: everything divides zero, and &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; is the largest number that divides &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt;.&lt;br /&gt;
# &amp;lt;math&amp;gt;\gcd(2u, 2v) = 2 \cdot \gcd(u, v)&amp;lt;/math&amp;gt;: &amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt; is a common divisor.&lt;br /&gt;
# &amp;lt;math&amp;gt;\gcd(u, 2v) = \gcd(u, v)&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; is odd: &amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt; is then not a common divisor.&lt;br /&gt;
# &amp;lt;math&amp;gt;\gcd(u, v) = \gcd(u, v - u)&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;u, v&amp;lt;/math&amp;gt; odd and &amp;lt;math&amp;gt;u \leq v&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
As GCD is commutative (&amp;lt;math&amp;gt;\gcd(u, v) = \gcd(v, u)&amp;lt;/math&amp;gt;), those identities still apply if the operands are swapped: &amp;lt;math&amp;gt;\gcd(0, v) = v&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\gcd(2u, v) = \gcd(u, v)&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is odd, etc.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
While the above description of the algorithm is mathematically correct, performant software implementations typically differ from it in a few notable ways:&lt;br /&gt;
* eschewing [[trial division]] by &amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt; in favour of a single bitshift and the [[count trailing zeros]] primitive; this is functionally equivalent to repeatedly applying identity 3, but much faster;&lt;br /&gt;
* expressing the algorithm [[Iteration#Computing|iteratively]] rather than [[Recursion (computer science)|recursively]]: the resulting implementation can be laid out to avoid repeated work, invoking identity&amp;amp;nbsp;2 at the start and maintaining as invariant that both numbers are odd upon entering the loop, which only needs to implement identities 3 and 4;&lt;br /&gt;
* making the loop&amp;#039;s body [[Branch_(computer_science)#Branch-free_code|branch-free]] except for its exit condition (&amp;lt;math&amp;gt;v = 0&amp;lt;/math&amp;gt;): in the example below, the exchange of &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; (ensuring &amp;lt;math&amp;gt;u \leq v&amp;lt;/math&amp;gt;) compiles down to [[conditional moves]];&amp;lt;ref name=&amp;quot;rust disassembly&amp;quot;/&amp;gt; hard-to-predict branches can have a large, negative impact on performance.&amp;lt;ref name=&amp;quot;intel&amp;quot;/&amp;gt;&amp;lt;ref name=&amp;quot;lemire&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is an implementation of the algorithm in [[Rust (programming language)|Rust]] exemplifying those differences, adapted from [https://github.com/uutils/coreutils/blob/1eabda91cf35ec45c78cb95c77d5463607daed65/src/uu/factor/src/numeric/gcd.rs &amp;#039;&amp;#039;uutils&amp;#039;&amp;#039;]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- PLEASE CHECK ANY CHANGES TO THIS ALGORITHM WITH THE TESTS AND OUTPUT HERE:&lt;br /&gt;
     https://play.rust-lang.org/?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=ea08036e202de879eb462dd5fc9747b3 --&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rust&amp;quot;&amp;gt;&lt;br /&gt;
use std::cmp::min;&lt;br /&gt;
use std::mem::swap;&lt;br /&gt;
&lt;br /&gt;
pub fn gcd(mut u: u64, mut v: u64) -&amp;gt; u64 {&lt;br /&gt;
    // Base cases: gcd(n, 0) = gcd(0, n) = n&lt;br /&gt;
    if u == 0 {&lt;br /&gt;
        return v;&lt;br /&gt;
    } else if v == 0 {&lt;br /&gt;
        return u;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Using identities 2 and 3:&lt;br /&gt;
    // gcd(2ⁱ u, 2ʲ v) = 2ᵏ gcd(u, v) with u, v odd and k = min(i, j)&lt;br /&gt;
    // 2ᵏ is the greatest power of two that divides both 2ⁱ u and 2ʲ v&lt;br /&gt;
    let i = u.trailing_zeros();  u &amp;gt;&amp;gt;= i;&lt;br /&gt;
    let j = v.trailing_zeros();  v &amp;gt;&amp;gt;= j;&lt;br /&gt;
    let k = min(i, j);&lt;br /&gt;
&lt;br /&gt;
    loop {&lt;br /&gt;
        // u and v are odd at the start of the loop&lt;br /&gt;
        debug_assert!(u % 2 == 1, &amp;quot;u = {} should be odd&amp;quot;, u);&lt;br /&gt;
        debug_assert!(v % 2 == 1, &amp;quot;v = {} should be odd&amp;quot;, v);&lt;br /&gt;
&lt;br /&gt;
        // Swap if necessary so u ≤ v&lt;br /&gt;
        if u &amp;gt; v {&lt;br /&gt;
            swap(&amp;amp;mut u, &amp;amp;mut v);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        // Identity 4: gcd(u, v) = gcd(u, v-u) as u ≤ v and u, v are both odd &lt;br /&gt;
        v -= u;&lt;br /&gt;
        // v is now even&lt;br /&gt;
&lt;br /&gt;
        if v == 0 {&lt;br /&gt;
            // Identity 1: gcd(u, 0) = u&lt;br /&gt;
            // The shift by k is necessary to add back the 2ᵏ factor that was removed before the loop&lt;br /&gt;
            return u &amp;lt;&amp;lt; k;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        // Identity 3: gcd(u, 2ʲ v) = gcd(u, v) as u is odd&lt;br /&gt;
        v &amp;gt;&amp;gt;= v.trailing_zeros();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;: The implementation above accepts &amp;#039;&amp;#039;unsigned&amp;#039;&amp;#039; (non-negative) integers; given that &amp;lt;math&amp;gt;\gcd(u, v) = \gcd(\pm{}u, \pm{}v)&amp;lt;/math&amp;gt;, the signed case can be handled as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rust&amp;quot;&amp;gt;&lt;br /&gt;
/// Computes the GCD of two signed 64-bit integers&lt;br /&gt;
/// The result is unsigned and not always representable as i64: gcd(i64::MIN, i64::MIN) == 1 &amp;lt;&amp;lt; 63&lt;br /&gt;
pub fn signed_gcd(u: i64, v: i64) -&amp;gt; u64 {&lt;br /&gt;
    gcd(u.unsigned_abs(), v.unsigned_abs())&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Complexity==&lt;br /&gt;
[[Big O notation|Asymptotically]], the algorithm requires &amp;lt;math&amp;gt;O(n)&amp;lt;/math&amp;gt; steps, where &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is the number of bits in the larger of the two numbers, as every two steps reduce at least one of the operands by at least a factor of &amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;.  Each step involves only a few arithmetic operations (&amp;lt;math&amp;gt;O(1)&amp;lt;/math&amp;gt; with a small constant); when working with [[Word (computer architecture)|word-sized]] numbers, each arithmetic operation translates to a single machine operation, so the number of machine operations is on the order of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, i.e. &amp;lt;math&amp;gt;\log_{2}(\max(u, v))&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For arbitrarily large numbers, the [[asymptotic notation|asymptotic complexity]] of this algorithm is &amp;lt;math&amp;gt;O(n^2)&amp;lt;/math&amp;gt;,&amp;lt;ref name=&amp;quot;gmplib&amp;quot;/&amp;gt; as each arithmetic operation (subtract and shift) involves a linear number of machine operations (one per word in the numbers&amp;#039; binary representation).&lt;br /&gt;
If the numbers can be represented in the machine&amp;#039;s memory, &amp;#039;&amp;#039;i.e.&amp;#039;&amp;#039; each number&amp;#039;s &amp;#039;&amp;#039;size&amp;#039;&amp;#039; can be represented by a single machine word, this bound is reduced to:&lt;br /&gt;
&amp;lt;math display=&amp;quot;block&amp;quot;&amp;gt;&lt;br /&gt;
O\left(\frac{n^2}{\log_2 n}\right)&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is the same as for the Euclidean algorithm, though a more precise analysis by Akhavi and Vallée proved that binary GCD uses about 60% fewer bit operations.&amp;lt;ref name=&amp;quot;bit-complexity&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Extensions==&lt;br /&gt;
&lt;br /&gt;
The binary GCD algorithm can be extended in several ways, either to output additional information, deal with [[Arbitrary-precision arithmetic|arbitrarily large integers]] more efficiently, or to compute GCDs in domains other than the integers.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;extended binary GCD&amp;#039;&amp;#039; algorithm, analogous to the [[extended Euclidean algorithm]], fits in the first kind of extension, as it provides the [[Bézout coefficients]] in addition to the GCD: integers &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;b&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;a\cdot{}u + b\cdot{}v = \gcd(u, v)&amp;lt;/math&amp;gt;.&amp;lt;ref name=&amp;quot;egcd-knuth&amp;quot;/&amp;gt;&amp;lt;ref name=&amp;quot;egcd-applied-crypto&amp;quot;/&amp;gt;&amp;lt;ref name=&amp;quot;egcd-cohen&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the case of large integers, the best asymptotic complexity is &amp;lt;math&amp;gt;O(M(n) \log n)&amp;lt;/math&amp;gt;, with &amp;lt;math&amp;gt;M(n)&amp;lt;/math&amp;gt; the cost of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-bit multiplication; this is near-linear and vastly smaller than the binary GCD algorithm&amp;#039;s &amp;lt;math&amp;gt;O(n^2)&amp;lt;/math&amp;gt;, though concrete implementations only outperform older algorithms for numbers larger than about 64 kilobits (&amp;#039;&amp;#039;i.e.&amp;#039;&amp;#039; greater than 8×10&amp;lt;sup&amp;gt;19265&amp;lt;/sup&amp;gt;).  This is achieved by extending the binary GCD algorithm using ideas from the [[Schönhage–Strassen algorithm]] for fast integer multiplication.&amp;lt;ref name=&amp;quot;stehlé-zimmermann&amp;quot;/&amp;gt; &lt;br /&gt;
&lt;br /&gt;
The binary GCD algorithm has also been extended to domains other than natural numbers, such as [[Gaussian integers]],&amp;lt;ref name=&amp;quot;weilert&amp;quot;/&amp;gt; [[Eisenstein integers]],&amp;lt;ref name=&amp;quot;eisenstein&amp;quot;/&amp;gt; quadratic rings,&amp;lt;ref name=&amp;quot;some-quadratic-rings&amp;quot;/&amp;gt;&amp;lt;ref name=&amp;quot;UFD-quadratic-rings&amp;quot;/&amp;gt; and [[Ring of integers|integer rings]] of [[number fields]].&amp;lt;ref name=&amp;quot;integer-rings&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Historical description==&lt;br /&gt;
An algorithm for computing the GCD of two numbers was known in ancient China, under the [[Han dynasty]], as a method to reduce fractions:&lt;br /&gt;
&lt;br /&gt;
{{quote| title= Fangtian – Land surveying| source=&amp;#039;&amp;#039;[[The Nine Chapters on the Mathematical Art]]&amp;#039;&amp;#039; |text=If possible halve it; otherwise, take the denominator and the numerator, subtract the lesser from the greater, and do that alternately to make them the same. Reduce by the same number.}}&lt;br /&gt;
&lt;br /&gt;
The phrase &amp;quot;if possible halve it&amp;quot; is ambiguous,&amp;lt;ref name=&amp;quot;Knuth98&amp;quot;/&amp;gt;&lt;br /&gt;
* if this applies when &amp;#039;&amp;#039;either&amp;#039;&amp;#039; of the numbers become even, the algorithm is the binary GCD algorithm;&lt;br /&gt;
* if this only applies when &amp;#039;&amp;#039;both&amp;#039;&amp;#039; numbers are even, the algorithm is similar to the [[Euclidean algorithm]].&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
{{Portal|Computer programming}}&lt;br /&gt;
* [[Euclidean algorithm]]&lt;br /&gt;
* [[Extended Euclidean algorithm]]&lt;br /&gt;
* [[Least common multiple]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Stein&amp;quot;&amp;gt;{{Citation |first=J. |last=Stein |title=Computational problems associated with Racah algebra |journal=Journal of Computational Physics |volume= 1 |issue=3 |pages=397–405 |date=February 1967 |issn=0021-9991 |doi=10.1016/0021-9991(67)90047-2|bibcode=1967JCoPh...1..397S }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Knuth98&amp;quot;&amp;gt;{{Citation |first=Donald |last=Knuth |author-link=Donald Knuth |series=[[The Art of Computer Programming]] |volume=2 |title=Seminumerical Algorithms |edition=3rd |publisher=Addison-Wesley |isbn=978-0-201-89684-8 |year=1998 }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref name=&amp;quot;intel&amp;quot;&amp;gt;{{Cite web | title=Avoiding the Cost of Branch Misprediction | first=Rajiv | last=Kapoor | date=21 February 2009 | website=Intel Developer Zone | url=https://software.intel.com/content/www/us/en/develop/articles/avoiding-the-cost-of-branch-misprediction.html }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref name=&amp;quot;lemire&amp;quot;&amp;gt;{{Cite web | title=Mispredicted branches can multiply your running times | first=Daniel | last=Lemire | date=15 October 2019 | url=https://lemire.me/blog/2019/10/15/mispredicted-branches-can-multiply-your-running-times/ }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref name=&amp;quot;rust disassembly&amp;quot;&amp;gt;{{Cite web | title=Compiler Explorer | first=Matt | last=Godbolt | access-date=4 February 2024 | url=https://rust.godbolt.org/z/56jva3KPn }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref name=&amp;quot;egcd-knuth&amp;quot;&amp;gt;{{Harvnb|Knuth|1998|p=646}}, answer to exercise 39 of section 4.5.2&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref name=&amp;quot;egcd-applied-crypto&amp;quot;&amp;gt;{{Cite book |chapter=§14.4 Greatest Common Divisor Algorithms |chapter-url=http://cacr.uwaterloo.ca/hac/about/chap14.pdf#page=17 |title=Handbook of Applied Cryptography |url=http://cacr.uwaterloo.ca/hac/ |pages=606–610 |date=October 1996 |publisher=CRC Press |first1=Alfred J. |last1=Menezes |first2=Paul C. |last2=van Oorschot |first3=Scott A. |last3=Vanstone |isbn=0-8493-8523-7 |access-date=9 September 2017}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref name=&amp;quot;egcd-cohen&amp;quot;&amp;gt;{{cite book |last=Cohen |first=Henri |author-link= Henri Cohen (number theorist) |year=1993 |title=A Course In Computational Algebraic Number Theory&lt;br /&gt;
|pages=17–18 |chapter=Chapter 1 : Fundamental Number-Theoretic Algorithms &amp;lt;!-- TODO: Section 3: Euclid&amp;#039;s algorithms --&amp;gt;&lt;br /&gt;
|isbn= 0-387-55640-0|publisher=[[Springer-Verlag]]|series=[[Graduate Texts in Mathematics]]|volume=138&lt;br /&gt;
|url= https://books.google.com/books?id=hXGr-9l1DXcC}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref name=&amp;quot;gmplib&amp;quot;&amp;gt;{{Cite web | url=http://gmplib.org/manual/Binary-GCD.html | title=GNU MP 6.1.2: Binary GCD}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;stehlé-zimmermann&amp;quot;&amp;gt;{{citation&lt;br /&gt;
 | last1 = Stehlé | first1 = Damien&lt;br /&gt;
 | last2 = Zimmermann | first2 = Paul | author-link2 = Paul Zimmermann (mathematician)&lt;br /&gt;
 | contribution = A binary recursive gcd algorithm&lt;br /&gt;
 | doi = 10.1007/978-3-540-24847-7_31&lt;br /&gt;
 | mr = 2138011&lt;br /&gt;
 | pages = 411–425&lt;br /&gt;
 | publisher = Springer, Berlin&lt;br /&gt;
 | series = Lecture Notes in Comput. Sci.&lt;br /&gt;
 | title = Algorithmic number theory&lt;br /&gt;
 | contribution-url = http://hal.archives-ouvertes.fr/docs/00/07/15/33/PDF/RR-5050.pdf&lt;br /&gt;
 | volume = 3076&lt;br /&gt;
 | year = 2004 | isbn = 978-3-540-22156-2&lt;br /&gt;
 | citeseerx = 10.1.1.107.8612&lt;br /&gt;
 | s2cid = 3119374&lt;br /&gt;
 | id = INRIA Research Report RR-5050&lt;br /&gt;
 }}.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;bit-complexity&amp;quot;&amp;gt;{{Citation | first1 = Ali | last1 = Akhavi | first2 = Brigitte | last2 = Vallée | title = Average Bit-Complexity of Euclidean Algorithms | year = 2000 | journal = Proceedings ICALP&amp;#039;00, Lecture Notes Computer Science 1853 | pages = 373–387 | url = https://vallee.users.greyc.fr/Publications/icalp8-2000.ps | citeseerx = 10.1.1.42.7616}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=brenta&amp;gt;{{cite conference |first=Richard P. |last=Brent |author-link=Richard P. Brent |url=http://wwwmaths.anu.edu.au/~brent/pub/pub183.html |title=Twenty years&amp;#039; analysis of the Binary Euclidean Algorithm |conference=1999 Oxford-Microsoft Symposium in honour of Professor Sir Antony Hoare |date=13–15 September 1999 |location=Oxford}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=brentb&amp;gt;{{cite tech report |first=Richard P. |last=Brent |author-link=Richard P. Brent |title=Further analysis of the Binary Euclidean algorithm |publisher=Oxford University Computing Laboratory |id=PRG TR-7-99 |date=November 1999 |arxiv=1303.2772 |url=https://www.cs.ox.ac.uk/techreports/oucl/tr-7-99.html}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;weilert&amp;quot;&amp;gt;{{cite journal |first=André |last=Weilert |title=(1+i)-ary GCD Computation in Z[i] as an Analogue to the Binary GCD Algorithm&lt;br /&gt;
|date=July 2000 |journal=Journal of Symbolic Computation |volume=30 |issue=5 |pages=605–617 |doi=10.1006/jsco.2000.0422|doi-access=free }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;eisenstein&amp;quot;&amp;gt;{{cite conference |last1=Damgård |first1=Ivan Bjerre |last2=Frandsen |first2=Gudmund Skovbjerg&lt;br /&gt;
|title=Efficient Algorithms for GCD and Cubic Residuosity in the Ring of Eisenstein Integers |doi=10.1007/978-3-540-45077-1_11&lt;br /&gt;
|doi-access= |pages=109–117 |conference=14th International Symposium on the Fundamentals of Computation Theory |location=[[Malmö]], Sweden |date= 12–15 August 2003}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;some-quadratic-rings&amp;quot;&amp;gt;{{cite conference |last1=Agarwal |first1=Saurabh |last2=Frandsen |first2=Gudmund Skovbjerg&lt;br /&gt;
|title=Binary GCD Like Algorithms for Some Complex Quadratic Rings |doi=10.1007/978-3-540-24847-7_4 |pages=57–71&lt;br /&gt;
|conference=Algorithmic Number Theory Symposium |date= 13–18 June 2004 |location=[[Burlington, VT]], USA}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;UFD-quadratic-rings&amp;quot;&amp;gt;{{cite conference |last1=Agarwal |first1=Saurabh |last2=Frandsen |first2=Gudmund Skovbjerg&lt;br /&gt;
|title=A New GCD Algorithm for Quadratic Number Rings with Unique Factorization |doi=10.1007/11682462_8 |pages=30–42&lt;br /&gt;
|conference=7th Latin American Symposium on Theoretical Informatics |date= 20–24 March 2006 |location=Valdivia, Chile}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;integer-rings&amp;quot;&amp;gt;{{cite conference |last=Wikström |first=Douglas&lt;br /&gt;
|title=On the l-Ary GCD-Algorithm in Rings of Integers |doi=10.1007/11523468_96 |pages=1189–1201 |date= 11–15 July 2005&lt;br /&gt;
|conference=Automata, Languages and Programming, 32nd International Colloquium |location=Lisbon, Portugal}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Further reading==&lt;br /&gt;
* {{cite book |first=Donald |last=Knuth |author-link=Donald Knuth |series=[[The Art of Computer Programming]] |volume=2&lt;br /&gt;
|title=Seminumerical Algorithms |chapter=§4.5 Rational arithmetic |pages=330–417&lt;br /&gt;
|edition=3rd |publisher=Addison-Wesley |isbn=978-0-201-89684-8 |year=1998 |ref=none}}&lt;br /&gt;
Covers the extended binary GCD, and a probabilistic analysis of the algorithm.&lt;br /&gt;
&lt;br /&gt;
* {{cite book |last=Cohen |first=Henri |author-link= Henri Cohen (number theorist) |year=1993 |title=A Course In Computational Algebraic Number Theory&lt;br /&gt;
|pages=12–24 |chapter=Chapter 1 : Fundamental Number-Theoretic Algorithms &amp;lt;!-- TODO: Section 3: Euclid&amp;#039;s algorithms --&amp;gt;&lt;br /&gt;
|isbn= 0-387-55640-0|publisher=[[Springer-Verlag]]|series=[[Graduate Texts in Mathematics]]|volume=138&lt;br /&gt;
|url= https://books.google.com/books?id=hXGr-9l1DXcC}}&lt;br /&gt;
Covers a variety of topics, including the extended binary GCD algorithm which outputs [[Bézout coefficients]], efficient handling of multi-precision integers using a variant of [[Lehmer&amp;#039;s GCD algorithm]], and the relationship between GCD and [[simple continued fraction|continued fraction expansion]]s of real numbers.&lt;br /&gt;
&lt;br /&gt;
* {{cite journal|last=Vallée |first=Brigitte | author-link=Brigitte Vallée&lt;br /&gt;
| title=Dynamics of the Binary Euclidean Algorithm: Functional Analysis and Operators |pages=660–685&lt;br /&gt;
| date=September–October 1998 |journal=Algorithmica |volume=22 |issue=4 |doi=10.1007/PL00009246&lt;br /&gt;
|s2cid=27441335 | archive-url=https://web.archive.org/web/20110513012901/http://users.info.unicaen.fr/~brigitte/Publications/bin-gcd.ps&lt;br /&gt;
| url=https://users.info.unicaen.fr/~brigitte/Publications/bin-gcd.ps |archive-date=13 May 2011 |format=PS&lt;br /&gt;
}}&lt;br /&gt;
An analysis of the algorithm in the average case, through the lens of [[functional analysis]]: the algorithms&amp;#039; main parameters are cast as a [[dynamical system]], and their average value is related to the [[invariant measure]] of the system&amp;#039;s [[transfer operator]].&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [https://xlinux.nist.gov/dads/HTML/binaryGCD.html NIST Dictionary of Algorithms and Data Structures: binary GCD algorithm]&lt;br /&gt;
* [http://www.cut-the-knot.org/blue/binary.shtml Cut-the-Knot: Binary Euclid&amp;#039;s Algorithm] at [[cut-the-knot]]&lt;br /&gt;
* [http://wwwmaths.anu.edu.au/~brent/pub/pub037.html &amp;#039;&amp;#039;Analysis of the Binary Euclidean Algorithm&amp;#039;&amp;#039;] (1976), a paper by [[Richard Brent (scientist)|Richard P. Brent]], including a variant using left shifts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{number theoretic algorithms}}&lt;br /&gt;
&lt;br /&gt;
{{DEFAULTSORT:Binary Gcd Algorithm}}&lt;br /&gt;
[[Category:Number theoretic algorithms]]&lt;br /&gt;
[[Category:Articles with example Rust code]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Frap</name></author>
	</entry>
</feed>