Algebra.js
function(poly) { 
            //get the maximum power of each
            var mp1 = this.coeffs.length-1, 
                mp2 = poly.coeffs.length-1,
                T;
            //swap so we always have the greater power first
            if(mp1 < mp2) {
                return poly.gcd(this);
            }
            var a = this;

            while(!poly.isZero()) {   
                var t = poly.clone(); 
                a = a.clone(); 
                T = a.divide(t);
                poly = T[1]; 
                a = t; 
            }

            var gcd = core.Math2.QGCD.apply(null, a.coeffs);
            if(!gcd.equals(1)) { 
                var l = a.coeffs.length;
                for(var i=0; i<l; i++) {
                    a.coeffs[i] = a.coeffs[i].divide(gcd);
                }
            }
            return a;
        }
function(poly) { 
            //get the maximum power of each
            var mp1 = this.coeffs.length-1, 
                mp2 = poly.coeffs.length-1,
                T;
            //swap so we always have the greater power first
            if(mp1 < mp2) {
                return poly.gcd(this);
            }
            var a = this;

            while(!poly.isZero()) {   
                var t = poly.clone(); 
                a = a.clone(); 
                T = a.divide(t);
                poly = T[1]; 
                a = t; 
            }

            var gcd = core.Math2.QGCD.apply(null, a.coeffs);
            if(!gcd.equals(1)) { 
                var l = a.coeffs.length;
                for(var i=0; i<l; i++) {
                    a.coeffs[i] = a.coeffs[i].divide(gcd);
                }
            }
            return a;
        }
function ( poly ) { //get the maximum power of each
 var mp1 = this . coeffs . length - 1 , mp2 = poly . coeffs . length - 1 , T ; //swap so we always have the greater power first
 if ( mp1 < mp2 ) { return poly . gcd ( this ) ; } var a = this ; while ( ! poly . isZero ( ) ) { var t = poly . clone ( ) ; a = a . clone ( ) ; T = a . divide ( t ) ; poly = T [ 1 ] ; a = t ; } var gcd = core . Math2 . QGCD . apply ( null , a . coeffs ) ; if ( ! gcd . equals ( 1 ) ) { var l = a . coeffs . length ; for ( var i = 0 ; i < l ; i ++ ) { a . coeffs [ i ] = a . coeffs [ i ] . divide ( gcd ) ; } } return a ; }
Returns the GCD of two polynomials
@param {Polynomial} poly
@returns {Polynomial}
Returns the GCD of two polynomials