コード例 #1
0
    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));
    }
コード例 #2
0
ファイル: QuantityN.cs プロジェクト: elliot-winch/Kepler
    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);
    }
コード例 #3
0
ファイル: QuantityN.cs プロジェクト: elliot-winch/Kepler
    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);
    }