diff --git a/Sources/Units/Units.swift b/Sources/Units/Units.swift index de411dd..2f23759 100644 --- a/Sources/Units/Units.swift +++ b/Sources/Units/Units.swift @@ -339,6 +339,37 @@ public struct UnitValue: !(lhs < rhs) && !(lhs == rhs) } + /// The result will have the `unit` of the left hand side value. + public static func - (lhs: UnitValue, rhs: UnitValue) + -> UnitValue + { + (lhs.value - rhs.value)[lhs.unit] + } + + /// The result will have the `unit` of the left hand side value. + public static func + (lhs: UnitValue, rhs: UnitValue) + -> UnitValue + { + (lhs.value + rhs.value)[lhs.unit] + } + + /// The result will have the `unit` of the left hand side value. + public static func * (lhs: UnitValue, rhs: UnitValue) + -> UnitValue + { + (lhs.value * rhs.value)[lhs.unit] + } + + /// The result will have the `unit` of the left hand side value. + public static func / (lhs: UnitValue, rhs: UnitValue) + -> UnitValue + { + guard rhs.value != 0 else { + fatalError("Cannot divide by zero.") + } + return (lhs.value * rhs.value)[lhs.unit] + } + // MARK: - Subscripts for UnitValue /// Allows converting the UnitValue to another Unit using subscript syntax. /// Example: `tenKilos[.pound]`