Exemple #1
0
        public static Rational GetReducedForm(Rational rationalNumber)
        {
            if (rationalNumber.isDefinitelyIrreducible)
            {
                return(rationalNumber);
            }

            var greatesCommonDivisor = EulerUtilities.GreatestCommonDivisor(rationalNumber.numerator, rationalNumber.denominator);

            return(new Rational(rationalNumber.numerator / greatesCommonDivisor, rationalNumber.Denominator / greatesCommonDivisor, true));
        }
Exemple #2
0
        public static bool IsIrreducible(Rational rationalNumber)
        {
            if (rationalNumber.isDefinitelyIrreducible)
            {
                return(true);
            }

            if (rationalNumber.Denominator == 1 ||
                (rationalNumber.Denominator == 0 && (rationalNumber.numerator == 1 || rationalNumber.numerator == -1 || rationalNumber.numerator == 0)) ||
                EulerUtilities.GreatestCommonDivisor(rationalNumber.numerator, rationalNumber.denominator) == 1)
            {
                return(true);
            }

            return(false);
        }