Greatest common divisor: Difference between revisions

Content added Content deleted
(added scheme)
(Added Haskell example)
Line 188:
 
<code>gcd_bin(40902, 24140)</code> takes us about '''2.5''' usec
 
=={{header|Haskell}}==
 
That is already available as the function ''gcd'' in the Prelude. Here's the implementation:
 
gcd :: (Integral a) => a -> a -> a
gcd 0 0 = error "Prelude.gcd: gcd 0 0 is undefined"
gcd x y = gcd' (abs x) (abs y) where
gcd' a 0 = a
gcd' a b = gcd' b (a `rem` b)
 
=={{header|J}}==