Пример #1
0
        public BigIntFraction Add(BigIntFraction number)
        {
            BigInteger newNumerator;
            BigInteger newDenominator;

            //gdy różny mianownik
            if (!Equals(denominator, number.denominator))
            {
                newDenominator = Nww(denominator, number.denominator);

                //wzór na sumę liczników zamienionych na wspólny mianownik
                BigInteger newNumerator1 = BigInteger.Multiply(numerator, BigInteger.Divide(newDenominator, denominator));
                BigInteger newNumerator2 = BigInteger.Multiply(number.numerator, BigInteger.Divide(newDenominator, number.denominator));
                newNumerator = BigInteger.Add(newNumerator1, newNumerator2);
            }
            else
            {
                //gdy równy mianownik
                newNumerator   = BigInteger.Add(numerator, number.numerator);
                newDenominator = denominator;
            }

            BigIntFraction newFraction = new BigIntFraction(newNumerator, newDenominator);

            return(newFraction);
        }
Пример #2
0
        public static int Compare(BigIntFraction f1, BigIntFraction f2)
        {
            BigInteger nwd           = Nwd(f1.denominator, f2.denominator);
            BigInteger newNumerator1 = BigInteger.Multiply(f1.numerator, BigInteger.Divide(nwd, f1.denominator));
            BigInteger newNumerator2 = BigInteger.Multiply(f2.numerator, BigInteger.Divide(nwd, f2.denominator));

            return(newNumerator1.CompareTo(newNumerator2));
        }
Пример #3
0
        public BigIntFraction Divide(BigIntFraction number)
        {
            BigInteger newNumerator, newDenominator;

            newNumerator   = BigInteger.Multiply(numerator, number.denominator);
            newDenominator = BigInteger.Multiply(denominator, number.numerator);
            BigIntFraction newFraction = new BigIntFraction(newNumerator, newDenominator);

            return(newFraction);
        }
Пример #4
0
        public BigIntFraction Subtract(BigIntFraction number)
        {
            BigInteger newNumerator;
            BigInteger newDenominator;

            // gdy różny mianownik
            if (!Equals(denominator, number.denominator))
            {
                newDenominator = Nww(this.denominator, number.denominator);

                // poniżej wzór na różnicę liczników zamienionych na wspólny mianownik
                BigInteger newNumerator1 = BigInteger.Multiply(numerator, BigInteger.Divide(newDenominator, denominator));
                BigInteger newNumerator2 = BigInteger.Multiply(number.numerator, BigInteger.Divide(newDenominator, number.denominator));
                newNumerator = BigInteger.Subtract(newNumerator1, newNumerator2);
            }
            else
            {
                // gdy równy mianownik
                newNumerator   = BigInteger.Subtract(numerator, number.numerator);
                newDenominator = this.denominator;
            }

            return(new BigIntFraction(newNumerator, newDenominator));
        }
Пример #5
0
 public BigIntFraction(BigIntFraction prototype)
 {
     numerator   = prototype.numerator;
     denominator = prototype.denominator;
     Simplify();
 }