public T Scale <T>(T quantity) where T : QuantityN { SciNumber scaler = SciNumber.One; quantity.units.unitExponents.ForEach(x => scaler *= (unitScales.FirstOrDefault(y => y.unit == x.unit)?.scale ?? SciNumber.One)); return(QuantityN.CreateQuantityInstance <T>(quantity.values.Select(x => x * scaler).ToList(), quantity.units)); }
protected static bool CheckDimensionCount(QuantityN a, QuantityN b, bool throwException = true) { bool x = a.values.Count == b.values.Count; if (x == false && throwException) { throw new ArgumentException("Cannot perform this operation on Quantities with different number of values"); } return(x); }
protected static bool CheckMatchingUnits(QuantityN a, QuantityN b, bool throwException = true) { bool x = a.units.Equals(b.units); if (x == false && throwException) { throw new ArgumentException("Operation cannot be performed on values with units \n" + a.units + " and " + b.units); } return(x); }