コード例 #1
0
    public override Algebraic[] div(Algebraic q1, Algebraic[] result)
    {
        if (result == null)
        {
            result = new Algebraic[2];
        }

        if (!(q1 is Zahl))
        {
            result[0] = Zahl.ZERO;
            result[1] = this;

            return(result);
        }

        Exakt q = ((Zahl)q1).exakt();

        if (!komplexq() && q.komplexq())
        {
            result[0] = Zahl.ZERO;
            result[1] = this;
            return(result);
        }

        if (komplexq() && !q.komplexq())
        {
            result[0] = div(q);
            result[1] = Zahl.ZERO;

            return(result);
        }

        if (komplexq() && q.komplexq())
        {
            result[0] = imagpart().div(q.imagpart());
            result[1] = sub(result[0].mult(q));

            return(result);
        }

        if (integerq() && q.integerq())
        {
            BigInteger[] d = real[0].divideAndRemainder(q.real[0]);

            result[0] = new Exakt(d[0]);
            result[1] = new Exakt(d[1]);

            return(result);
        }

        result[0] = div(q);
        result[1] = Zahl.ZERO;

        return(result);
    }
コード例 #2
0
    public virtual Exakt gcd(Exakt x)
    {
        if (Equals(Zahl.ZERO))
        {
            return(x);
        }
        else if (x.Equals(Zahl.ZERO))
        {
            return(this);
        }
        if (komplexq() && x.komplexq())
        {
            Exakt r = ((Exakt)realpart()).gcd((Exakt)x.realpart());
            Exakt i = ((Exakt)imagpart()).gcd((Exakt)x.imagpart());

            if (r.Equals(Zahl.ZERO))
            {
                return((Exakt)i.mult(Zahl.IONE));
            }

            if (realpart().div(r).Equals(imagpart().div(i)))
            {
                return((Exakt)r.add(i.mult(Zahl.IONE)));
            }
            else
            {
                return(Zahl.ONE.exakt());
            }
        }
        else if (komplexq() || x.komplexq())
        {
            return(Zahl.ONE.exakt());
        }
        else
        {
            return((Exakt)(new Exakt(real[0].multiply(x.real[1]).gcd(real[1].multiply(x.real[0])))).div(new Exakt(real[1].multiply(x.real[1]))));
        }
    }