Plange


greatestCommonDivisor.pge

<Int * Int → Int> gcd :=
    (a, 0) { return a; } |
    (a, b) {
        a ≥ 0; //preconditions - only positive
        b ≥ 0;
        return gcd(b, a % b);
    } |
    (a, b) {
        a ≠ 0;
        return gcd(abs(a), abs(b));
    } |
    (_, _) {
        throw "gcd undefined for given values";
    };

copyright © Brent Lewis 2017