Ejemplo n.º 1
0
        private void Normalize()
        {
            var power10   = PrefixHelpers.Power10(Quantity);
            var newPrefix = PrefixHelpers.FindClosestPrefix(power10 / Power);

            if (newPrefix != 0)
            {
                Prefix = newPrefix;
                var pow = -((int)newPrefix * Power);
                Quantity *= Math.Pow(10, pow);
            }
        }
Ejemplo n.º 2
0
        private IDictionary <Unit, Unit> FindPossibleDerivedUnits()
        {
            var dict = new ConcurrentDictionary <Unit, Unit>();

            DerivedUnits.Where(x => x.Units.Count <= Units.Count).AsParallel().ForAll(derivedUnit =>
            {
                int factor = this.HasFactor(derivedUnit);

                if (factor != 0)
                {
                    Unit remain  = this / derivedUnit.Pow(factor);
                    var pow10    = PrefixHelpers.Power10(remain.Quantity);
                    var prfx     = PrefixHelpers.FindClosestPrefix(pow10 / factor);
                    var units    = derivedUnit.Units.SelectMany(x => x.Pow(1)).ToArray();
                    var quantity = remain.Quantity / Math.Pow(10, (int)prfx * factor);
                    Unit d       = new Unit(quantity, prfx, derivedUnit.UnitName, factor, units);
                    dict.AddOrUpdate(d, remain, (x, y) => y);
                }
            });
            return(dict);
        }