public IAccumulator Subtract(IValueStructure operand) { object other; if (ValueConverter <T> .TryConvertLosslessFrom(operand, out other)) { _value = _value.Subtract((T)other); return(this); } else { IAccumulator acc = Escalate(operand.TypeId, _value, false); return(acc.Subtract(operand)); } }
public static bool SimplifySummands(ISignalSet signals) { bool changed = CollectSummands(signals); if (signals.Count < 2) { return(changed); } IAccumulator acc = null; for (int i = signals.Count - 1; i > 0; i--) //don't touch first item! { Signal s = signals[i]; if (Std.IsConstantComplex(s)) { if (acc == null) { acc = Accumulator <IntegerValue, RationalValue> .Create(IntegerValue.AdditiveIdentity); } signals.RemoveAt(i); changed = true; acc = acc.Add(s.Value); } } if (acc != null && !acc.Value.Equals(IntegerValue.AdditiveIdentity)) { Signal first = signals[0]; if (Std.IsConstantComplex(first)) { acc = acc.Subtract(first.Value).Negate(); signals[0] = Std.DefineConstant(acc.Value); changed = true; } else { signals.Insert(1, Std.DefineConstant(acc.Value)); } } return(changed); }