Esempio n. 1
0
        public static bool operator >(Rational <T, C> one, Rational <T, C> two)
        {
            if (one is NotANumber || two is NotANumber)
            {
                return(false);
            }
            else if (one is Positive_Infinity || two is Negative_Infinity)
            {
                return(true);
            }
            else if (two is Positive_Infinity || one is Negative_Infinity)
            {
                return(false);
            }

            T denomLcm = WhiteMath <T, C> .LowestCommonMultiple(one.denom, two.denom, WhiteMath <T, C> .GreatestCommonDivisor(one.denom, two.denom));

            return(calc.mor(calc.mul(one.num, calc.div(denomLcm, one.denom)), calc.mul(two.num, calc.div(denomLcm, two.denom))));
        }
Esempio n. 2
0
        ///-----------------------------------
        ///----ARITHMETIC OPERATORS-----------
        ///-----------------------------------

        public static Rational <T, C> operator +(Rational <T, C> one, Rational <T, C> two)
        {
            if (one is Infinities)
            {
                if (two is Infinities)
                {
                    if (one.GetType().Equals(two.GetType()))
                    {
                        return(one);
                    }
                    else
                    {
                        return(NaN);
                    }
                }

                return(one);
            }
            else if (two is Infinities)
            {
                return(two + one);
            }

            Rational <T, C> tmp = new Rational <T, C>();

            tmp.denom = WhiteMath <T, C> .LowestCommonMultiple(one.denom, two.denom, WhiteMath <T, C> .GreatestCommonDivisor(one.denom, two.denom));

            tmp.num = calc.sum(calc.mul(one.num, calc.div(tmp.denom, one.denom)), calc.mul(two.num, calc.div(tmp.denom, two.denom)));

            if (checkInf(ref tmp))
            {
                tmp.normalize();
            }

            return(tmp);
        }
Esempio n. 3
0
        public static Rational <T, C> operator -(Rational <T, C> one, Rational <T, C> two)
        {
            if (one is Infinities || two is Infinities)
            {
                if (one is NotANumber || two is NotANumber)
                {
                    return(NaN);
                }
                else if (one is Positive_Infinity)
                {
                    if (two is Infinities)
                    {
                        if (two is Negative_Infinity)
                        {
                            return(one);
                        }
                        else
                        {
                            return(NaN);
                        }
                    }

                    return(one);
                }
                else if (two is Positive_Infinity)
                {
                    if (one is Infinities)
                    {
                        if (one is Negative_Infinity)
                        {
                            return(one);
                        }
                        else
                        {
                            return(NaN);
                        }
                    }

                    return(NegativeInfinity);
                }
                else if (one is Negative_Infinity)
                {
                    if (two is Infinities)
                    {
                        if (two is Positive_Infinity)
                        {
                            return(one);
                        }
                        else
                        {
                            return(NaN);
                        }
                    }

                    return(one);
                }
                else if (two is Negative_Infinity)
                {
                    if (one is Infinities)
                    {
                        if (one is Positive_Infinity)
                        {
                            return(one);
                        }
                        else
                        {
                            return(NaN);
                        }
                    }

                    return(PositiveInfinity);
                }
            }

            Rational <T, C> tmp = new Rational <T, C>();

            tmp.denom = WhiteMath <T, C> .LowestCommonMultiple(one.denom, two.denom, WhiteMath <T, C> .GreatestCommonDivisor(one.denom, two.denom));

            tmp.num = calc.dif(calc.mul(one.num, calc.div(tmp.denom, one.denom)), calc.mul(two.num, calc.div(tmp.denom, two.denom)));

            if (checkInf(ref tmp))
            {
                tmp.normalize();
            }
            return(tmp);
        }