public static UnitValue DivUU(Value a, Value b) { var left = (UnitValue)a; var right = (UnitValue)b; var unit = new CombinedUnit(left.Unit).Divide(right.Unit).Simplify(); return(new UnitValue(unit.Factor * left / right, unit.Unpack())); }
public CombinedUnit CreateFrom(string unit) { var name = Unpack(); var obj = new CombinedUnit(name, factor); obj.factor *= GetWeight(unit); return(obj); }
static UnitValue MulUU(Value a, Value b) { var left = (UnitValue)a; var right = (UnitValue)b; var unit = new CombinedUnit(left.Unit).Multiply(right.Unit).Simplify(); return(new UnitValue(unit.Factor * left * right, unit.Unpack())); }
/// <summary> /// Divides the given combined unit by another unit. /// </summary> /// <param name="unit">The combined unit to divide the current unit.</param> /// <returns>The (current) modified unit.</returns> public CombinedUnit Divide(CombinedUnit unit) { foreach (var element in unit.ElementaryUnits) { AddUnit(units, element.Key, -element.Value); } return(this); }
/// <summary> /// Multiplies the given combined unit with another combined unit. /// </summary> /// <param name="unit">The combined unit which is multiplied to the current unit.</param> /// <returns>The (current) modified unit.</returns> public CombinedUnit Multiply(CombinedUnit unit) { foreach (var element in unit.ElementaryUnits) { AddUnit(_units, element.Key, element.Value); } return(this); }
public static UnitValue Convert(UnitValue fromValue, String targetUnit) { var cu = new CombinedUnit(fromValue.Unit); var conversions = cu.ConvertTo(targetUnit); var re = fromValue.Re; foreach (var conversation in conversions) { re = conversation(re); } return(new UnitValue(cu.Factor * re, cu.Unit)); }
public static UnitValue Convert(UnitValue fromValue, String targetUnit) { var cu = new CombinedUnit(fromValue.Unit); var conversions = cu.ConvertTo(targetUnit); var re = fromValue.Re; foreach (var conversation in conversions) { re = conversation(re); } return new UnitValue(cu.Factor * re, cu.Unit); }
double GetChanges(CombinedUnit unit, out bool reversed) { var misses = 0.0; var posCatches = 0.0; var negCatches = 0.0; reversed = false; foreach (var b in unit.units) { var found = false; foreach (var a in units) { if (a.Key == b.Key) { found = true; posCatches += Math.Abs(b.Value - a.Value); negCatches += Math.Abs(b.Value + a.Value); break; } } if (!found) { misses += Math.Abs(b.Value); } } if (negCatches < posCatches) { reversed = true; return(misses + negCatches); } return(misses + posCatches); }
Double GetChanges(CombinedUnit unit, out Boolean reversed) { var misses = 0.0; var posCatches = 0.0; var negCatches = 0.0; reversed = false; foreach (var b in unit._units) { var found = false; foreach (var a in _units) { if (a.Key == b.Key) { found = true; posCatches += Math.Abs(b.Value - a.Value); negCatches += Math.Abs(b.Value + a.Value); break; } } if (!found) { misses += Math.Abs(b.Value); } } if (negCatches < posCatches) { reversed = true; return misses + negCatches; } return misses + posCatches; }
/// <summary> /// Multiplies the given combined unit with another combined unit. /// </summary> /// <param name="unit">The combined unit which is multiplied to the current unit.</param> /// <returns>The (current) modified unit.</returns> public CombinedUnit Multiply(CombinedUnit unit) { foreach (var element in unit.ElementaryUnits) { AddUnit(_units, element.Key, element.Value); } return this; }
public CombinedUnit CreateFrom(String unit) { var name = Unpack(); var obj = new CombinedUnit(name, _factor); obj._factor *= GetWeight(unit); return obj; }
static UnitValue MulUU(Value a, Value b) { var left = (UnitValue)a; var right = (UnitValue)b; var unit = new CombinedUnit(left.Unit).Multiply(right.Unit).Simplify(); return new UnitValue(unit.Factor * left * right, unit.Unpack()); }
static UnitValue DivUU(Value a, Value b) { var left = (UnitValue)a; var right = (UnitValue)b; var unit = new CombinedUnit(left.Unit).Divide(right.Unit).Simplify(); return new UnitValue(unit.Factor * left / right, unit.Unpack()); }