예제 #1
0
        public static MyFloat operator -(MyFloat a1, MyFloat b1)
        {
            var a = new MyFloat(Convert.ToString(a1._mantissa) + "e" + Convert.ToString(a1._order));
            var b = new MyFloat(Convert.ToString((-1) * b1._mantissa) + "e" + Convert.ToString(b1._order));

            return(a + b);
        }
예제 #2
0
        public static bool operator ==(MyFloat a1, MyFloat b1)
        {
            var a = new MyFloat(Convert.ToString(a1._mantissa) + "e" + Convert.ToString(a1._order));
            var b = new MyFloat(Convert.ToString(b1._mantissa) + "e" + Convert.ToString(b1._order));

            helpToGetSameOrder(a, b);
            return(a._mantissa == b._mantissa && a._order == b._order);
        }
예제 #3
0
        public static MyFloat operator +(MyFloat a1, MyFloat b1)
        {
            var a = new MyFloat(Convert.ToString(a1._mantissa) + "e" + Convert.ToString(a1._order));
            var b = new MyFloat(Convert.ToString(b1._mantissa) + "e" + Convert.ToString(b1._order));

            helpToGetSameOrder(a, b);


            return(new MyFloat(Convert.ToString(a._mantissa + b._mantissa) + "e" + Convert.ToString(a._order)));
        }
예제 #4
0
        public static void Main(string[] args)
        {
            var num1 = new MyFloat("130e4");
            var num2 = new MyFloat("13e5");
            var sum  = num1 + num2;

            Console.WriteLine("There are 2 numbers: " + num1.Value() + " and " + num2.Value());
            Console.WriteLine("Sum equals to " + sum.Value());
            Console.WriteLine($"({num1.Value()}) < ({num2.Value()}) : {(num1 < num2)}");
            Console.WriteLine($"({num1.Value()}) > ({num2.Value()}) : {(num1 > num2)}");
            Console.WriteLine($"({num1.Value()}) == ({num2.Value()}) : {(num1 == num2)}");

            Console.WriteLine($"{num1.Value()} equals to {num2.Value()} : {num1.Equals(num2)}");
        }
예제 #5
0
        public static bool operator <(MyFloat a1, MyFloat b1)
        {
            var a = new MyFloat(Convert.ToString(a1._mantissa) + "e" + Convert.ToString(a1._order));
            var b = new MyFloat(Convert.ToString(b1._mantissa) + "e" + Convert.ToString(b1._order));

            helpToGetSameOrder(a, b);

            if ((a._mantissa < 0 && b._mantissa > 0) || (a._mantissa > 0 && b._mantissa < 0)) // они разных знаков
            {
                return(a._mantissa < b._mantissa);
            }
            else // они одного знака
            {
                if (a._mantissa > 0) // => оба больше нуля
                {
                    if (a._order < b._order)
                    {
                        return(true);
                    }
                    else if (a._order > b._order)
                    {
                        return(false);
                    }
                    else
                    {
                        return(a._mantissa < b._mantissa);
                    }
                }
                else // => оба меньше нуля
                {
                    if (a._order > b._order)
                    {
                        return(true);
                    }
                    else if (a._order < b._order)
                    {
                        return(false);
                    }
                    else
                    {
                        return(a._mantissa > b._mantissa);
                    }
                }
            }
        }
예제 #6
0
        private static void helpToGetSameOrder(MyFloat a, MyFloat b)
        {
            var maxOrder   = (a._order > b._order ? a._order : b._order);
            var minOrder   = (a._order < b._order ? a._order : b._order);
            var difference = (maxOrder - minOrder);

            if (a._order > b._order)
            {
                a._mantissa *= Convert.ToInt64(Math.Pow(10, difference));
                a._order     = minOrder;
            }
            else
            {
                b._order     = minOrder;
                b._mantissa *= Convert.ToInt64(Math.Pow(10, difference));
            }

            return;
        }