Example #1
0
        /// <summary>
        /// Execute divison operator and put result into operands stack
        /// </summary>
        /// <param name="operands">stack with operands</param>
        /// <param name="mode">mode to operate in</param>
        /// <returns>true/false if execution went well</returns>
        public override bool Execute(Stack<Operand> operands, CalculatorMode mode)
        {
            try
            {
                // b / a
                Operand a = operands.Pop();
                Operand b = operands.Pop();
                Operand c; // result

                // if we are in programming mode and both operands are integers
                // do a integer division
                if (mode == CalculatorMode.Programming &&
                    a.Value == (Int32)a.Value &&
                    b.Value == (Int32)b.Value)
                {
                    c = new Operand((Int32)b.Value / (Int32)a.Value);
                }
                else
                {
                    c = new Operand(b.Value / a.Value);
                }
                operands.Push(c);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Example #2
0
 /// <summary>
 /// Execute not operator and push answer onto operands stack
 /// </summary>
 /// <param name="operands">stack with operands</param>
 /// <param name="mode">mode to operate in</param>
 /// <returns>true/false if execution went well</returns>
 public override bool Execute(Stack<Operand> operands, CalculatorMode mode)
 {
     try
     {
         // ~a
         Operand a = operands.Pop();
         Operand b = new Operand(~(Int64)a.Value);
         operands.Push(b);
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
Example #3
0
 /// <summary>
 /// Execute plus operator and push answer onto operands stack
 /// </summary>
 /// <param name="operands">stack with operands</param>
 /// <param name="mode">mode to operate in</param>
 /// <returns>true/false if execution went well</returns>
 public override bool Execute(Stack<Operand> operands, CalculatorMode mode)
 {
     try
     {
         Operand a = operands.Pop();
         Operand b = operands.Pop();
         Operand c = new Operand(a.Value + b.Value);
         operands.Push(c);
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
Example #4
0
        private static void Main()
        {
            AllPhysicUnits allPhysicUnits = new AllPhysicUnits();
            Operand o1 = new Operand(10, allPhysicUnits.GetPhysicUnit(Unit.Gram));
            Operand o2 = new Operand(5, allPhysicUnits.GetPhysicUnit(Unit.KilometreInHour));
            Operand o3 = new Operand(2, allPhysicUnits.GetPhysicUnit(Unit.MetreInSecond));
            Operand o4 = new Operand(4, allPhysicUnits.GetPhysicUnit(Unit.KilometreInHour));
            Operand o5 = new Operand(6, allPhysicUnits.GetPhysicUnit(Unit.Hour));
            Operand o6 = new Operand(1, allPhysicUnits.GetPhysicUnit(Unit.Second));
            Operand o7 = new Operand(1, allPhysicUnits.GetPhysicUnit(Unit.Second));
            Operand o8 = new Operand(8, allPhysicUnits.GetPhysicUnit(Unit.Kilogram));
            Operand o9 = new Operand(10, allPhysicUnits.GetPhysicUnit(Unit.Second));

            Operand pulse = o1*(o2 + o3);
            Operand distance = (o4*(o5 + o6)/o7*o8 + pulse)/o9;

            Console.WriteLine(pulse);
            Console.WriteLine(distance);
            Console.ReadKey();
        }
Example #5
0
        public static Operand ApplyOperation(this Operand o1, Operand o2, Operation operation)
        {
            switch (o1.PhysicUnit.SiPhysicUnit.Key.UnitType)
            {
                case UnitType.Mass:
                    switch (o2.PhysicUnit.SiPhysicUnit.Key.UnitType)
                    {
                        case UnitType.Mass:
                            switch (operation)
                            {
                                case Operation.Add:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.Gram:
                                            if (o2.PhysicUnit.Unit == Unit.Gram)
                                            {
                                                return new Operand(o1.Value + o2.Value, o1.PhysicUnit);
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Kilogram)
                                            {
                                                return new Operand(o1.Value + o2.Value/o1.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                        case Unit.Kilogram:
                                            if (o2.PhysicUnit.Unit == Unit.Gram)
                                            {
                                                return new Operand(o1.Value + o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Kilogram)
                                            {
                                                return new Operand(o1.Value + o2.Value, o1.PhysicUnit);
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Subtract:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.Gram:
                                            if (o2.PhysicUnit.Unit == Unit.Gram)
                                            {
                                                return new Operand(o1.Value - o2.Value, o1.PhysicUnit);
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Kilogram)
                                            {
                                                return new Operand(o1.Value - o2.Value/o1.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                        case Unit.Kilogram:
                                            if (o2.PhysicUnit.Unit == Unit.Gram)
                                            {
                                                return new Operand(o1.Value - o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }
                                            if (o2.PhysicUnit.Unit == Unit.Kilogram)
                                            {
                                                return new Operand(o1.Value - o2.Value, o1.PhysicUnit);
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Distance:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Time:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Speed:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.Gram:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond)
                                            {
                                                return new Operand(o1.Value*o1.PhysicUnit.SiPhysicUnit.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.KilometreInHour)
                                            {
                                                return
                                                    new Operand(
                                                        o1.Value*o1.PhysicUnit.SiPhysicUnit.Value*o2.Value*
                                                        o2.PhysicUnit.SiPhysicUnit.Value,
                                                        AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond));
                                            }
                                            return null;
                                        case Unit.Kilogram:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond)
                                            {
                                                return new Operand(o1.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.KilometreInHour)
                                            {
                                                return new Operand(
                                                    o1.Value*o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond));
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Impulse:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Acceleration:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.Gram:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond2)
                                            {
                                                return new Operand(o1.Value*o1.PhysicUnit.SiPhysicUnit.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond2));
                                            }
                                            return null;
                                        case Unit.Kilogram:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond2)
                                            {
                                                return new Operand(o1.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond2));
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Power:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;
                    }
                    break;

            //------------------------------------------

                case UnitType.Distance:
                    switch (o2.PhysicUnit.SiPhysicUnit.Key.UnitType)
                    {
                        case UnitType.Mass:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Distance:
                            switch (operation)
                            {
                                case Operation.Add:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.Metre:
                                            if (o2.PhysicUnit.Unit == Unit.Metre)
                                            {
                                                return new Operand(o1.Value + o2.Value, o1.PhysicUnit);
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Kilometre)
                                            {
                                                return new Operand(o1.Value + o2.Value*o1.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                        case Unit.Kilometre:
                                            if (o2.PhysicUnit.Unit == Unit.Metre)
                                            {
                                                return new Operand(o1.Value + o2.Value/o1.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Kilometre)
                                            {
                                                return new Operand(o1.Value + o2.Value, o1.PhysicUnit);
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Subtract:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.Metre:
                                            if (o2.PhysicUnit.Unit == Unit.Metre)
                                            {
                                                return new Operand(o1.Value - o2.Value, o1.PhysicUnit);
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Kilometre)
                                            {
                                                return new Operand(o1.Value - o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                        case Unit.Kilometre:
                                            if (o2.PhysicUnit.Unit == Unit.Metre)
                                            {
                                                return new Operand(o1.Value - o2.Value/o1.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }
                                            if (o2.PhysicUnit.Unit == Unit.Kilometre)
                                            {
                                                return new Operand(o1.Value - o2.Value, o1.PhysicUnit);
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Time:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.Metre:
                                            if (o2.PhysicUnit.Unit == Unit.Second)
                                            {
                                                return new Operand(o1.Value/o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Hour)
                                            {
                                                return new Operand(o1.Value/o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond));
                                            }
                                            return null;
                                        case Unit.Kilometre:
                                            if (o2.PhysicUnit.Unit == Unit.Second)
                                            {
                                                return
                                                    new Operand(
                                                        o1.Value*o1.PhysicUnit.SiPhysicUnit.Value/o2.Value/
                                                        o1.PhysicUnit.SiPhysicUnit.Value,
                                                        AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond));
                                            }
                                            if (o2.PhysicUnit.Unit == Unit.Hour)
                                            {
                                                return new Operand(o1.Value/o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilometreInHour));
                                            }
                                            return null;
                                    }
                                    break;
                            }
                            break;

                        case UnitType.Speed:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.Metre:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond)
                                            {
                                                return new Operand(o1.Value/o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Second));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.KilometreInHour)
                                            {
                                                return new Operand(o1.Value/o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Second));
                                            }
                                            return null;
                                        case Unit.Kilometre:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond)
                                            {
                                                return
                                                    new Operand(
                                                        o1.Value*o1.PhysicUnit.SiPhysicUnit.Value/o2.Value,
                                                        AllPhysicUnits.GetPhysicUnit(Unit.Second));
                                            }
                                            if (o2.PhysicUnit.Unit == Unit.KilometreInHour)
                                            {
                                                return new Operand(o1.Value/o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Hour));
                                            }
                                            return null;
                                    }
                                    break;
                            }
                            break;

                        case UnitType.Impulse:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Acceleration:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Power:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null; // работа А=F*S
                                case Operation.Divide:
                                    return null;
                            }
                            break;
                    }
                    break;

            //------------------------------------------

                case UnitType.Time:
                    switch (o2.PhysicUnit.SiPhysicUnit.Key.UnitType)
                    {
                        case UnitType.Mass:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Time:
                            switch (operation)
                            {
                                case Operation.Add:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.Second:
                                            if (o2.PhysicUnit.Unit == Unit.Second)
                                            {
                                                return new Operand(o1.Value + o2.Value, o1.PhysicUnit);
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Hour)
                                            {
                                                return new Operand(o1.Value + o2.Value*o1.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                        case Unit.Hour:
                                            if (o2.PhysicUnit.Unit == Unit.Second)
                                            {
                                                return new Operand(o1.Value + o2.Value/o1.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Hour)
                                            {
                                                return new Operand(o1.Value + o2.Value, o1.PhysicUnit);
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Subtract:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.Second:
                                            if (o2.PhysicUnit.Unit == Unit.Second)
                                            {
                                                return new Operand(o1.Value - o2.Value, o1.PhysicUnit);
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Hour)
                                            {
                                                return new Operand(o1.Value - o2.Value*o1.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                        case Unit.Hour:
                                            if (o2.PhysicUnit.Unit == Unit.Second)
                                            {
                                                return new Operand(o1.Value - o2.Value/o1.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Hour)
                                            {
                                                return new Operand(o1.Value - o2.Value, o1.PhysicUnit);
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Distance:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Speed:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.Second:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond)
                                            {
                                                return new Operand(o1.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Metre));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.KilometreInHour)
                                            {
                                                return new Operand(o1.Value*o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Metre));
                                            }
                                            return null;
                                        case Unit.Hour:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond)
                                            {
                                                return
                                                    new Operand(
                                                        o1.Value*o1.PhysicUnit.SiPhysicUnit.Value*o2.Value,
                                                        AllPhysicUnits.GetPhysicUnit(Unit.Metre));
                                            }
                                            if (o2.PhysicUnit.Unit == Unit.KilometreInHour)
                                            {
                                                return new Operand(o1.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Kilometre));
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Impulse:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Acceleration:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.Second:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond2)
                                            {
                                                return new Operand(o1.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond));
                                            }
                                            return null;
                                        case Unit.Hour:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond2)
                                            {
                                                return
                                                    new Operand(
                                                        o1.Value*o1.PhysicUnit.SiPhysicUnit.Value*o2.Value,
                                                        AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond));
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Power:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.Second:
                                            if (o2.PhysicUnit.Unit == Unit.KilogramOnMetreInSecond2)
                                            {
                                                return new Operand(o1.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond));
                                            }
                                            return null;
                                        case Unit.Hour:
                                            if (o2.PhysicUnit.Unit == Unit.KilogramOnMetreInSecond2)
                                            {
                                                return
                                                    new Operand(
                                                        o1.Value*o1.PhysicUnit.SiPhysicUnit.Value*o2.Value,
                                                        AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond));
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Divide:
                                    return null;
                            }
                            break;
                    }
                    break;

                //------------------------------------------

                case UnitType.Speed:
                    switch (o2.PhysicUnit.SiPhysicUnit.Key.UnitType)
                    {
                        case UnitType.Mass:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.MetreInSecond:
                                            if (o2.PhysicUnit.Unit == Unit.Kilogram)
                                            {
                                                return new Operand(o1.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Gram)
                                            {
                                                return new Operand(o1.Value*o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond));
                                            }
                                            return null;
                                        case Unit.KilometreInHour:
                                            if (o2.PhysicUnit.Unit == Unit.Kilogram)
                                            {
                                                return
                                                    new Operand(
                                                        o1.Value*o1.PhysicUnit.SiPhysicUnit.Value*o2.Value,
                                                        AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond));
                                            }
                                            if (o2.PhysicUnit.Unit == Unit.Gram)
                                            {
                                                return
                                                    new Operand(
                                                        o1.Value*o1.PhysicUnit.SiPhysicUnit.Value*o2.Value*
                                                        o2.PhysicUnit.SiPhysicUnit.Value,
                                                        AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond));
                                            }
                                            return null;
                                    }
                                    break;

                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Time:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.MetreInSecond:
                                            if (o2.PhysicUnit.Unit == Unit.Second)
                                            {
                                                return new Operand(o1.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Metre));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Hour)
                                            {
                                                return new Operand(o1.Value*o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Metre));
                                            }
                                            return null;
                                        case Unit.KilometreInHour:
                                            if (o2.PhysicUnit.Unit == Unit.Second)
                                            {
                                                return new Operand(o1.Value*o1.PhysicUnit.SiPhysicUnit.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Metre));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Hour)
                                            {
                                                return new Operand(o1.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Kilometre));
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Divide:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.MetreInSecond:
                                            if (o2.PhysicUnit.Unit == Unit.Second)
                                            {
                                                return new Operand(o1.Value/o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond2));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Hour)
                                            {
                                                return new Operand(o1.Value/o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond2));
                                            }
                                            return null;
                                        case Unit.KilometreInHour:
                                            if (o2.PhysicUnit.Unit == Unit.Second)
                                            {
                                                return new Operand(o1.Value*o1.PhysicUnit.SiPhysicUnit.Value/o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond2));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Hour)
                                            {
                                                return
                                                    new Operand(
                                                        o1.Value*o1.PhysicUnit.SiPhysicUnit.Value/o2.Value*
                                                        o2.PhysicUnit.SiPhysicUnit.Value,
                                                        AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond2));
                                            }
                                            return null;
                                    }
                                    break;
                            }
                            break;

                        case UnitType.Distance:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Speed:
                            switch (operation)
                            {
                                case Operation.Add:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.MetreInSecond:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond)
                                            {
                                                return new Operand(o1.Value + o2.Value,
                                                    o1.PhysicUnit);
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.KilometreInHour)
                                            {
                                                return new Operand(o1.Value + o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                        case Unit.KilometreInHour:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond)
                                            {
                                                return new Operand(o1.Value + o2.Value/o1.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.KilometreInHour)
                                            {
                                                return new Operand(o1.Value + o2.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Subtract:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.MetreInSecond:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond)
                                            {
                                                return new Operand(o1.Value - o2.Value,
                                                    o1.PhysicUnit);
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.KilometreInHour)
                                            {
                                                return new Operand(o1.Value - o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                        case Unit.KilometreInHour:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond)
                                            {
                                                return new Operand(o1.Value - o2.Value/o1.PhysicUnit.SiPhysicUnit.Value,
                                                    o1.PhysicUnit);
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.KilometreInHour)
                                            {
                                                return new Operand(o1.Value - o2.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Impulse:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Acceleration:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.MetreInSecond:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond2)
                                            {
                                                return new Operand(o1.Value/o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Second));
                                            }
                                            return null;
                                        case Unit.KilometreInHour:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond2)
                                            {
                                                return
                                                    new Operand(
                                                        o1.Value*o1.PhysicUnit.SiPhysicUnit.Value/o2.Value,
                                                        AllPhysicUnits.GetPhysicUnit(Unit.Second));
                                            }
                                            return null;
                                    }
                                    break;
                            }
                            break;

                        case UnitType.Power:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;
                    }
                    break;

                //------------------------------------------

                case UnitType.Impulse:
                    switch (o2.PhysicUnit.SiPhysicUnit.Key.UnitType)
                    {
                        case UnitType.Mass:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.KilogramOnMetreInSecond:
                                            if (o2.PhysicUnit.Unit == Unit.Kilogram)
                                            {
                                                return new Operand(o1.Value/o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Gram)
                                            {
                                                return new Operand(o1.Value/o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond));
                                            }
                                            return null;
                                    }
                                    break;

                            }
                            break;

                        case UnitType.Time:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.KilogramOnMetreInSecond:
                                            if (o2.PhysicUnit.Unit == Unit.Second)
                                            {
                                                return new Operand(o1.Value/o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond2));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Hour)
                                            {
                                                return new Operand(o1.Value/o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond2));
                                            }
                                            return null;
                                    }
                                    break;
                            }
                            break;

                        case UnitType.Distance:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Speed:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.KilogramOnMetreInSecond:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond)
                                            {
                                                return new Operand(o1.Value/o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Kilogram));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.KilometreInHour)
                                            {
                                                return new Operand(o1.Value/o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Kilogram));
                                            }
                                            return null;
                                    }
                                    break;
                            }
                            break;

                        case UnitType.Impulse:
                            switch (operation)
                            {
                                case Operation.Add:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.KilogramOnMetreInSecond:
                                            if (o2.PhysicUnit.Unit == Unit.KilogramOnMetreInSecond)
                                            {
                                                return new Operand(o1.Value + o2.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Subtract:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.KilogramOnMetreInSecond:
                                            if (o2.PhysicUnit.Unit == Unit.KilogramOnMetreInSecond)
                                            {
                                                return new Operand(o1.Value - o2.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Acceleration:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Power:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.KilogramOnMetreInSecond:
                                            if (o2.PhysicUnit.Unit == Unit.KilogramOnMetreInSecond2)
                                            {
                                                return new Operand(o1.Value/o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Second));
                                            }
                                            return null;
                                    }
                                    break;

                            }
                            break;
                    }
                    break;

            //------------------------------------------

                case UnitType.Acceleration:
                    switch (o2.PhysicUnit.SiPhysicUnit.Key.UnitType)
                    {
                        case UnitType.Mass:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.MetreInSecond2:
                                            if (o2.PhysicUnit.Unit == Unit.Kilogram)
                                            {
                                                return new Operand(o1.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond2));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Gram)
                                            {
                                                return new Operand(o1.Value*o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond2));
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Divide:
                                    return null;

                            }
                            break;

                        case UnitType.Time:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.MetreInSecond2:
                                            if (o2.PhysicUnit.Unit == Unit.Second)
                                            {
                                                return new Operand(o1.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Hour)
                                            {
                                                return new Operand(o1.Value*o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond));
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Distance:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Speed:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Impulse:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Acceleration:
                            switch (operation)
                            {
                                case Operation.Add:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.MetreInSecond2:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond2)
                                            {
                                                return new Operand(o1.Value + o2.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Subtract:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.MetreInSecond2:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond2)
                                            {
                                                return new Operand(o1.Value - o2.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Power:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;
                    }
                    break;

                //------------------------------------------

                case UnitType.Power:
                    switch (o2.PhysicUnit.SiPhysicUnit.Key.UnitType)
                    {
                        case UnitType.Mass:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.KilogramOnMetreInSecond2:
                                            if (o2.PhysicUnit.Unit == Unit.Kilogram)
                                            {
                                                return new Operand(o1.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond2));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Gram)
                                            {
                                                return new Operand(o1.Value*o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.MetreInSecond2));
                                            }
                                            return null;
                                    }
                                    break;

                            }
                            break;

                        case UnitType.Time:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.KilogramOnMetreInSecond2:
                                            if (o2.PhysicUnit.Unit == Unit.Second)
                                            {
                                                return new Operand(o1.Value*o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond));
                                            }

                                            if (o2.PhysicUnit.Unit == Unit.Hour)
                                            {
                                                return new Operand(o1.Value*o2.Value*o2.PhysicUnit.SiPhysicUnit.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.KilogramOnMetreInSecond));
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Distance:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Speed:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Impulse:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;

                        case UnitType.Acceleration:
                            switch (operation)
                            {
                                case Operation.Add:
                                    return null;
                                case Operation.Subtract:
                                    return null;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.KilogramOnMetreInSecond2:
                                            if (o2.PhysicUnit.Unit == Unit.MetreInSecond2)
                                            {
                                                return new Operand(o1.Value/o2.Value,
                                                    AllPhysicUnits.GetPhysicUnit(Unit.Kilogram));
                                            }
                                            return null;
                                    }
                                    break;
                            }
                            break;

                        case UnitType.Power:
                            switch (operation)
                            {
                                case Operation.Add:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.KilogramOnMetreInSecond2:
                                            if (o2.PhysicUnit.Unit == Unit.KilogramOnMetreInSecond2)
                                            {
                                                return new Operand(o1.Value + o2.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Subtract:
                                    switch (o1.PhysicUnit.Unit)
                                    {
                                        case Unit.KilogramOnMetreInSecond2:
                                            if (o2.PhysicUnit.Unit == Unit.KilogramOnMetreInSecond2)
                                            {
                                                return new Operand(o1.Value - o2.Value,
                                                    o1.PhysicUnit);
                                            }
                                            return null;
                                    }
                                    break;
                                case Operation.Multiply:
                                    return null;
                                case Operation.Divide:
                                    return null;
                            }
                            break;
                    }
                    break;
            }
            return null;
        }