gcd ( x y -- a d )
Factor documentation > Factor handbook > The language > Numbers > Mathematical functions > Integer functions
Prev:align ( m w -- n )
Next:log2 ( x -- n )


Vocabulary
math.functions

Inputs and outputs
xan integer
yan integer
aan integer
dan integer


Word description
Computes the positive greatest common divisor d of x and y, and another value a satisfying:
a*y = d mod x


Notes
If d is 1, then a is the inverse of y modulo x.

Definition
USING: kernel math math.functions.private ;

IN: math.functions

: gcd ( x y -- a d )
[ 0 1 ] 2dip (gcd) dup 0 < [ neg ] when ; foldable
flushable