public DecayingDouble Add(TimeSpan halfLife, DecayingDouble amountToAdd) { if (!LastUpdatedUtc.HasValue) { return(new DecayingDouble(ValueAtTimeOfLastUpdate + amountToAdd.ValueAtTimeOfLastUpdate, amountToAdd.LastUpdatedUtc)); } else if (!amountToAdd.LastUpdatedUtc.HasValue) { return(new DecayingDouble(ValueAtTimeOfLastUpdate + amountToAdd.ValueAtTimeOfLastUpdate, LastUpdatedUtc)); } else if (LastUpdatedUtc.Value > amountToAdd.LastUpdatedUtc.Value) { return(new DecayingDouble( ValueAtTimeOfLastUpdate + amountToAdd.GetValue(halfLife, LastUpdatedUtc.Value), LastUpdatedUtc.Value)); } else { return(new DecayingDouble(amountToAdd.ValueAtTimeOfLastUpdate + GetValue(halfLife, amountToAdd.LastUpdatedUtc.Value), amountToAdd.LastUpdatedUtc.Value)); } }
public DecayingDouble Subtract(TimeSpan halfLife, DecayingDouble amountToRemove) { if (!LastUpdatedUtc.HasValue) { return(new DecayingDouble(ValueAtTimeOfLastUpdate - amountToRemove.ValueAtTimeOfLastUpdate, amountToRemove.LastUpdatedUtc)); } else if (!amountToRemove.LastUpdatedUtc.HasValue) { return(new DecayingDouble(ValueAtTimeOfLastUpdate - amountToRemove.ValueAtTimeOfLastUpdate, LastUpdatedUtc)); } else if (LastUpdatedUtc.Value > amountToRemove.LastUpdatedUtc.Value) { return (new DecayingDouble( ValueAtTimeOfLastUpdate - amountToRemove.GetValue(halfLife, LastUpdatedUtc.Value), LastUpdatedUtc.Value)); } else { return(new DecayingDouble(amountToRemove.ValueAtTimeOfLastUpdate - GetValue(halfLife, amountToRemove.LastUpdatedUtc.Value), amountToRemove.LastUpdatedUtc.Value)); } }