Greatest common divisor: Difference between revisions

m (missing parameter default)
Line 3,519:
b.is_zero ? a.abs : gcd(b, a % b);
}</lang>
 
=={{header|Smalltalk}}==
 
"gcd" is already in the base library and understood by all integer objects. Its implementation is typically based on Euclid, as in:
<lang smalltalk>
gcd:anInteger
"return the greatest common divisor of the receiver and anInteger.
Euclids algorithm."
 
|a b t|
 
a := self abs.
b := anInteger abs.
 
a < b ifTrue:[
t := a. a := b. b := t.
].
 
b = 0 ifTrue: [^ a].
a := a \\ b.
a = 0 ifTrue:[^ b].
^ b gcd:a
</lang>
 
=={{header|Slate}}==
Anonymous user