Clamp after AdjustMoles() (#22907)
Clamping is needed because x - x can be negative with floating point numbers. If we don't clamp here, the caller always has to call GetMoles(), clamp, then SetMoles(), which makes this function not very useful.
This commit is contained in:
@@ -120,12 +120,9 @@ namespace Content.Server.Atmos
|
||||
if (!float.IsFinite(quantity))
|
||||
throw new ArgumentException($"Invalid quantity \"{quantity}\" specified!", nameof(quantity));
|
||||
|
||||
Moles[gasId] += quantity;
|
||||
|
||||
var moles = Moles[gasId];
|
||||
|
||||
if (!float.IsFinite(moles) || float.IsNegative(moles))
|
||||
throw new Exception($"Invalid mole quantity \"{moles}\" in gas Id {gasId} after adjusting moles with \"{quantity}\"!");
|
||||
// Clamping is needed because x - x can be negative with floating point numbers. If we don't
|
||||
// clamp here, the caller always has to call GetMoles(), clamp, then SetMoles().
|
||||
Moles[gasId] = MathF.Max(Moles[gasId] + quantity, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user