示例#1
0
        protected SumDifferenceSet combinePowers(SumDifferenceSet newSet)
        {
            for (int i = 0; i < newSet.Count - 1; i++)
            {
                bool  baseAIsNegative = newSet._unitOperatorPair[i].Unit.GetSign().IsNegative();
                IBase baseA           = newSet._unitOperatorPair[i].Unit.GetBase();
                IBase powerA          = newSet._unitOperatorPair[i].Unit.GetPower() ?? new PrimitiveUnit(1);
                IBase baseB           = newSet._unitOperatorPair[i + 1].Unit.GetBase();
                IBase powerB          = newSet._unitOperatorPair[i + 1].Unit.GetPower() ?? new PrimitiveUnit(1);
                bool  baseSignIsSame  = newSet._unitOperatorPair[i].Unit.GetSign().Equals(newSet._unitOperatorPair[i + 1].Unit.GetSign());

                bool isSum           = (newSet._unitOperatorPair[i + 1].OperatorEquals(Query.ADD));
                bool baseIsSame      = baseA.GetBase().Equals(baseB.GetBase());
                bool exponentIsSame  = powerA.GetBase().Equals(powerB.GetBase());
                bool powerSignIsSame = powerA.GetSign().Equals(powerB.GetSign());

                // (1a) Same Base, Same exponent, Same exponent sign
                if (baseIsSame && exponentIsSame && powerSignIsSame)
                {
                    if ((isSum && baseSignIsSame) ||
                        (!isSum && !baseSignIsSame))
                    { // Add Exponent Same Sign
                        ProductQuotientSet newBasePower = new ProductQuotientSet(2);
                        newBasePower.MultiplyItem(new ProductQuotientSet(baseA, powerA));
                        newSet = new SumDifferenceSet(newBasePower, null, baseAIsNegative);
                    }
                    else
                    { // Subtract Exponent Same Sign
                        newSet = new SumDifferenceSet(0);
                    }
                }

                // (1b) Same Base, Same exponent, Different sign
                // (2) Same Base, Different exponent (ignore sign)
                // (3) Different Base, Same exponent (ignore sign)
                // (4) Different Base, Different exponent (ignore sign)
                if (!baseIsSame && !exponentIsSame)
                {
                    // Do Nothing
                }
            }

            // Calculate if numeric
            IBase power = newSet.GetPower();

            if (power == null || !power.IsNumber())
            {
                return(newSet);
            }

            power  = new PrimitiveUnit(power.Calculate());
            newSet = new SumDifferenceSet(
                new ProductQuotientSet(newSet.GetBase(), power, newSet.SignIsNegative())
                );

            return(newSet);
        }
示例#2
0
        /// <summary>
        /// Calculates the specified base value.
        /// </summary>
        /// <param name="baseValue">The base value.</param>
        /// <returns>System.Double.</returns>
        protected double calculate(double baseValue)
        {
            if (_power == null)
            {
                return(_sign * baseValue);
            }

            double powerValue = _power.Calculate();

            return((Math.Abs(baseValue) < Tolerance && Math.Abs(powerValue) < Tolerance) ?
                   double.NaN :
                   Math.Pow(_sign * baseValue, powerValue));
        }