Rational_greatest_common_divisor   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/core/rational.xtm

Implementation

(bind-func Rational_greatest_common_divisor
  (lambda (m:i64 n:i64)
    (if (and (= m 0) (= n 0))
        -1
        (let ((r 0))
          (if (< m 0) (set! m (* m -1)))
          (if (< n 0) (set! n (* n -1)))
          (while (not (= n 0))
            (set! r (% m n))
            (set! m n)
            (set! n r))
          m))))


Back to Index

Similar Entries