/// <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));
        }
        /// <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));
        }
 /// <summary>
 /// Returns a hash code for this instance.
 /// </summary>
 /// <param name="quantity">The quantity.</param>
 /// <returns>
 /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 /// </returns>
 public static int GetHashCode(IQuantity quantity)
 {
     return(QuantityOperations.ConvertToUnit(quantity, IdentityUnit).GetHashCode());
 }
Пример #4
0
 /// <summary>
 /// Converts this object to a <see cref="double" /> using the specified unit.
 /// </summary>
 /// <param name="unit">The quantity unit.</param>
 /// <returns>
 /// The converted <see cref="double" />.
 /// </returns>
 public double ToDouble(IUnit unit)
 {
     return QuantityOperations.ConvertToUnit(this, unit);
 }
Пример #5
0
 /// <summary>
 /// Divides the specified lhs by the specified rhs.
 /// </summary>
 /// <param name="lhs">The LHS.</param>
 /// <param name="rhs">The RHS.</param>
 /// <returns>
 /// A <see cref="Quantity"/>.
 /// </returns>
 public static double operator /(Quantity lhs, Quantity rhs)
 {
     return QuantityOperations.Divide(lhs, rhs).Value;
 }
Пример #6
0
 /// <summary>
 /// Multiplies the specified lhs by the specified rhs.
 /// </summary>
 /// <param name="lhs">The LHS.</param>
 /// <param name="rhs">The RHS.</param>
 /// <returns>
 /// A <see cref="Quantity"/>.
 /// </returns>
 public static Quantity operator *(Quantity lhs, Quantity rhs)
 {
     return new Quantity(QuantityOperations.Multiply(lhs, rhs));
 }
Пример #7
0
 /// <summary>
 /// Subtracts the specified rhs from the specified lhs.
 /// </summary>
 /// <param name="lhs">The LHS.</param>
 /// <param name="rhs">The RHS.</param>
 /// <returns>
 /// A <see cref="Quantity"/>.
 /// </returns>
 public static Quantity operator -(Quantity lhs, Quantity rhs)
 {
     return new Quantity(QuantityOperations.Subtract(lhs, rhs));
 }
Пример #8
0
 /// <summary>
 /// Adds the specified rhs to the specified lhs.
 /// </summary>
 /// <param name="lhs">The LHS.</param>
 /// <param name="rhs">The RHS.</param>
 /// <returns>
 /// A <see cref="Quantity"/>.
 /// </returns>
 public static Quantity operator +(Quantity lhs, Quantity rhs)
 {
     return new Quantity(QuantityOperations.Add(lhs, rhs));
 }