Ejemplo n.º 1
0
        /// <summary>
        /// Compares the lhs to the rhs.
        /// </summary>
        /// <param name="lhs">The LHS quantity.</param>
        /// <param name="rhs">The RHS quantity.</param>
        /// <returns>The result of <see cref="int"/> Compare based the rhs converted to the same unit as lhs.</returns>
        public static int CompareTo(IQuantity lhs, IQuantity rhs)
        {
            var lhsUnit = lhs.Unit;
            var rhsUnit = rhs.Unit;

            if (!UnitEqualityHelper.AreBaseUnitsEqual(lhsUnit, rhsUnit))
            {
                throw new UnitMismatchException(OperationType.Compare, lhsUnit, rhsUnit);
            }

            var rhsValue = QuantityOperations.ConvertToUnit(rhs, lhs.Unit);

            return(lhs.Value.CompareTo(rhsValue));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if the lhs and the rhs are equal.
        /// </summary>
        /// <param name="lhs">The LHS quantity.</param>
        /// <param name="rhs">The RHS quantity.</param>
        /// <returns>
        /// A value indication whether the lhs and the rhs are equal.
        /// </returns>
        public static bool AreEqual(IQuantity lhs, IQuantity rhs)
        {
            if (lhs == null || rhs == null)
            {
                return(false);
            }

            var lhsUnit = lhs.Unit;
            var rhsUnit = rhs.Unit;

            if (!UnitEqualityHelper.AreBaseUnitsEqual(lhsUnit, rhsUnit))
            {
                return(false);
            }

            var rhsValue = QuantityOperations.ConvertToUnit(rhs, lhsUnit);

            return(lhs.Value.Equals(rhsValue));
        }