public static Unit operator -(Unit u1, Unit u2) { if (u1.IsComparable(u2)) { var averagePrefix = PrefixHelpers.AveragePrefix(u1.Prefix, u2.Prefix); var quantity = u1.Quantity * Math.Pow(10, u1.Power10Difference(averagePrefix)) - u2.Quantity * Math.Pow(10, u2.Power10Difference(averagePrefix)); var newUnit = new Unit(quantity, averagePrefix, u1.BaseUnit, u1.Power); return(newUnit); } else { throw new GrandmothersAndFrogsException(u1, u2, "You can't mix them. You just can't"); } }
public static Unit operator *(Unit u1, Unit u2) { if (u1.BaseUnit == u2.BaseUnit && u1.BaseUnit != 0) { var averagePrefix = PrefixHelpers.AveragePrefix(u1.Prefix, u2.Prefix); var power10 = u1.Power10Difference(averagePrefix) + u2.Power10Difference(averagePrefix); var quantity = u1.Quantity * u2.Quantity * Math.Pow(10, power10); var newUnit = new Unit(quantity, averagePrefix, u1.BaseUnit, u1.Power + u2.Power); return(newUnit); } else { return(Unit.Multiply(u1, u2)); } }