Пример #1
0
        //Multiplication Operators
        private static DerivedQuantity multiplyDerivedQuantities(DerivedQuantity a, DerivedQuantity b)
        {
            var expression = new DerivedQuantityDimension(a.Dimension.Members
                                                          .Concat(b.Dimension.Members).ToArray());

            return(new DerivedQuantity(expression));
        }
Пример #2
0
        private static DerivedQuantity multiplyBaseQuantities(BaseQuantity a, BaseQuantity b)
        {
            var derivedA = new DerivedQuantity(a, 1);
            var derivedB = new DerivedQuantity(b, 1);

            return(multiplyDerivedQuantities(derivedA, derivedB));
        }
Пример #3
0
        private static DerivedQuantity exponentiateDerivedQuantity(DerivedQuantity a, double b)
        {
            var members = a.Dimension.Members.Select(m => new DerivedQuantityDimensionMember(m.BaseQuantity,
                                                                                             m.Exponent * b)).ToArray();
            var expression = new DerivedQuantityDimension(members);

            return(new DerivedQuantity(expression));
        }
Пример #4
0
        static Quantity()
        {
            //Multiplication Operators
            Func <DerivedQuantity, DerivedQuantity, DerivedQuantity> multiplyDerivedQuantities = (a, b) =>
            {
                var expression = new DerivedQuantityDimension(a.Dimension.Members
                                                              .Concat(b.Dimension.Members).ToArray());
                return(new DerivedQuantity(expression));
            };

            Func <BaseQuantity, BaseQuantity, DerivedQuantity> multiplyBaseQuantities = (a, b) =>
            {
                var derivedA = new DerivedQuantity(a, 1);
                var derivedB = new DerivedQuantity(b, 1);
                return(multiplyDerivedQuantities(derivedA, derivedB));
            };

            Func <BaseQuantity, DerivedQuantity, DerivedQuantity> multiplyBaseByDerivedQuantities = (a, b) =>
            {
                var derivedA = new DerivedQuantity(a, 1);
                return(multiplyDerivedQuantities(derivedA, b));
            };

            Func <DerivedQuantity, BaseQuantity, DerivedQuantity> multiplyDerivedByBaseQuantities = (a, b) =>
            {
                var derivedB = new DerivedQuantity(b, 1);
                return(multiplyDerivedQuantities(a, derivedB));
            };

            //Exponentiation Operators
            Func <BaseQuantity, double, DerivedQuantity> exponentiateBaseQuantity = (a, b) => new DerivedQuantity(a, b);

            Func <DerivedQuantity, double, DerivedQuantity> exponentiateDerivedQuantity = (a, b) =>
            {
                var members = a.Dimension.Members.Select(m => new DerivedQuantityDimensionMember(m.BaseQuantity,
                                                                                                 m.Exponent * b)).ToArray();
                var expression = new DerivedQuantityDimension(members);
                return(new DerivedQuantity(expression));
            };

            MathOperationManager.RegisterMany(new MathOperation[] {
                new Multiplication <BaseQuantity, BaseQuantity, DerivedQuantity>(multiplyBaseQuantities),
                new Multiplication <DerivedQuantity, DerivedQuantity, DerivedQuantity>(multiplyDerivedQuantities),
                new Multiplication <BaseQuantity, DerivedQuantity, DerivedQuantity>(multiplyBaseByDerivedQuantities),
                new Multiplication <DerivedQuantity, BaseQuantity, DerivedQuantity>(multiplyDerivedByBaseQuantities),
                new Exponentiation <BaseQuantity, double, DerivedQuantity>(exponentiateBaseQuantity),
                new Exponentiation <DerivedQuantity, double, DerivedQuantity>(exponentiateDerivedQuantity)
            });
        }
Пример #5
0
        private static DerivedQuantity multiplyBaseByDerivedQuantities(BaseQuantity a, DerivedQuantity b)
        {
            var derivedA = new DerivedQuantity(a, 1);

            return(multiplyDerivedQuantities(derivedA, b));
        }