/// <summary>
        /// Adding quantities with different storage types
        /// </summary>
        /// <typeparam name="Q">Second Quantity Type</typeparam>
        /// <param name="firstQuantity"></param>
        /// <param name="secondQuantity"></param>
        /// <returns></returns>
        public static AnyQuantity <T> Add <Q>(AnyQuantity <T> firstQuantity, AnyQuantity <Q> secondQuantity)
        {
            if (firstQuantity.Equals(secondQuantity))
            {
                AnyQuantity <T> AQ = null;
                try
                {
                    AQ = QuantityDimension.QuantityFrom <T>(firstQuantity.Dimension);
                    //exception happen when adding two derived quantities together
                }
                catch (QuantityNotFoundException)
                {
                    //keep the first quantity configuration.
                    AQ = (AnyQuantity <T>)firstQuantity.Clone();
                }


                T firstVal = (firstQuantity.Value);

                Q secondVal = (secondQuantity.Value);

                //correct the values according to left unit or first unit.
                //the resulted quantity has the values of the first unit.

                if (firstQuantity.Unit != null && secondQuantity.Unit != null)
                {
                    //factor from second unit to first unit
                    UnitPathStack stof = secondQuantity.Unit.PathToUnit(firstQuantity.Unit);

                    secondVal = MultiplyScalarByGeneric <Q>(stof.ConversionFactor, secondVal);
                }


                var expr = Expression.Add(Expression.Constant(firstVal), Expression.Constant(secondVal));

                // Construct Lambda function which return one object.
                Expression <Func <T> > cq = Expression.Lambda <Func <T> >(expr);

                // compile the function
                Func <T> aqf = cq.Compile();

                // execute the function
                T result = aqf();

                if (firstQuantity.Unit != null && secondQuantity.Unit != null)
                {
                    //assign the unit of first quantity to the result.
                    AQ.Unit = firstQuantity.Unit;
                }


                AQ.Value = result;

                return(AQ);
            }
            else
            {
                throw new QuantitiesNotDimensionallyEqualException();
            }
        }
        public static bool Inequality(AnyQuantity <T> firstQuantity, AnyQuantity <T> secondQuantity)
        {
            if (firstQuantity.Equals(secondQuantity))
            {
                if (typeof(T) == typeof(decimal) || typeof(T) == typeof(double) || typeof(T) == typeof(float) || typeof(T) == typeof(int) || typeof(T) == typeof(short))
                {
                    #region Premitive
                    //use direct calculations

                    double firstVal = (double)(object)firstQuantity.Value;

                    double secondVal = (double)(object)secondQuantity.Value;


                    //correct the values according to left unit or first unit.
                    //the resulted quantity has the values of the first unit.

                    if (firstQuantity.Unit != null && secondQuantity.Unit != null)
                    {
                        //factor from second unit to first unit
                        UnitPathStack stof = secondQuantity.Unit.PathToUnit(firstQuantity.Unit);

                        secondVal = stof.ConversionFactor * secondVal;
                    }

                    return(firstVal != secondVal);

                    #endregion
                }
                else
                {
                    #region Custom Types



                    T firstVal = (firstQuantity.Value);

                    T secondVal = (secondQuantity.Value);

                    //correct the values according to left unit or first unit.
                    //the resulted quantity has the values of the first unit.

                    if (firstQuantity.Unit != null && secondQuantity.Unit != null)
                    {
                        //factor from second unit to first unit
                        UnitPathStack stof = secondQuantity.Unit.PathToUnit(firstQuantity.Unit);


                        secondVal = MultiplyScalarByGeneric(stof.ConversionFactor, secondVal);
                    }

                    var expr = Expression.NotEqual(Expression.Constant(firstVal), Expression.Constant(secondVal));

                    // Construct Lambda function which return one object.
                    Expression <Func <bool> > cq = Expression.Lambda <Func <bool> >(expr);

                    // compile the function
                    Func <bool> aqf = cq.Compile();

                    // execute the function
                    bool result = aqf();

                    return(result);

                    #endregion
                }
            }
            else
            {
                throw new QuantitiesNotDimensionallyEqualException();
            }
        }
        public static AnyQuantity <T> Subtract(AnyQuantity <T> firstQuantity, AnyQuantity <T> secondQuantity)
        {
            if (firstQuantity.Equals(secondQuantity))
            {
                AnyQuantity <T> AQ = null;
                try
                {
                    AQ = QuantityDimension.QuantityFrom <T>(firstQuantity.Dimension);

                    //exception happen when adding two derived quantities together
                }
                catch (QuantityNotFoundException)
                {
                    //keep the first quantity configuration.
                    AQ = (AnyQuantity <T>)firstQuantity.Clone();
                }


                if (typeof(T) == typeof(decimal) || typeof(T) == typeof(double) || typeof(T) == typeof(float) || typeof(T) == typeof(int) || typeof(T) == typeof(short))
                {
                    //use direct calculations

                    double firstVal = (double)(object)firstQuantity.Value;

                    double secondVal = (double)(object)secondQuantity.Value;

                    //correct the values according to left unit or first unit.
                    //the resulted quantity has the values of the first unit.

                    if (firstQuantity.Unit != null && secondQuantity.Unit != null)
                    {
                        //factor from second unit to first unit
                        UnitPathStack stof = secondQuantity.Unit.PathToUnit(firstQuantity.Unit);

                        secondVal = stof.ConversionFactor * secondVal;
                    }



                    ////sum the values

                    double result = firstVal - secondVal;

                    if (firstQuantity.Unit != null && secondQuantity.Unit != null)
                    {
                        //assign the unit of first quantity to the result.
                        AQ.Unit = (Unit)firstQuantity.Unit.Clone();
                    }


                    AQ.Value = (T)(object)result;

                    return(AQ);
                }
                else
                {
                    T firstVal  = (firstQuantity.Value);
                    T secondVal = (secondQuantity.Value);

                    //correct the values according to left unit or first unit.
                    //the resulted quantity has the values of the first unit.

                    if (firstQuantity.Unit != null && secondQuantity.Unit != null)
                    {
                        //factor from second unit to first unit
                        UnitPathStack stof = secondQuantity.Unit.PathToUnit(firstQuantity.Unit);

                        secondVal = MultiplyScalarByGeneric(stof.ConversionFactor, secondVal);
                    }


                    var expr = Expression.Subtract(Expression.Constant(firstVal), Expression.Constant(secondVal));

                    // Construct Lambda function which return one object.
                    Expression <Func <T> > cq = Expression.Lambda <Func <T> >(expr);

                    // compile the function
                    Func <T> aqf = cq.Compile();

                    // execute the function
                    T result = aqf();


                    if (firstQuantity.Unit != null && secondQuantity.Unit != null)
                    {
                        //assign the unit of first quantity to the result.
                        AQ.Unit = firstQuantity.Unit;
                    }

                    AQ.Value = result;

                    return(AQ);
                }
            }
            else
            {
                throw new QuantitiesNotDimensionallyEqualException();
            }
        }