Use float.IsFinite in some appropriate places previously using IsNan || IsInfinity

This commit is contained in:
Pieter-Jan Briers
2021-12-23 01:21:57 +01:00
parent 20ca72512d
commit ebdd6e817c

View File

@@ -116,7 +116,7 @@ namespace Content.Server.Atmos
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetMoles(int gasId, float quantity) public void SetMoles(int gasId, float quantity)
{ {
if (float.IsInfinity(quantity) || float.IsNaN(quantity) || float.IsNegative(quantity)) if (!float.IsFinite(quantity) || float.IsNegative(quantity))
throw new ArgumentException($"Invalid quantity \"{quantity}\" specified!", nameof(quantity)); throw new ArgumentException($"Invalid quantity \"{quantity}\" specified!", nameof(quantity));
if (!Immutable) if (!Immutable)
@@ -134,14 +134,14 @@ namespace Content.Server.Atmos
{ {
if (!Immutable) if (!Immutable)
{ {
if (float.IsInfinity(quantity) || float.IsNaN(quantity)) if (!float.IsFinite(quantity))
throw new ArgumentException($"Invalid quantity \"{quantity}\" specified!", nameof(quantity)); throw new ArgumentException($"Invalid quantity \"{quantity}\" specified!", nameof(quantity));
Moles[gasId] += quantity; Moles[gasId] += quantity;
var moles = Moles[gasId]; var moles = Moles[gasId];
if (float.IsInfinity(moles) || float.IsNaN(moles) || float.IsNegative(moles)) if (!float.IsFinite(moles) || float.IsNegative(moles))
throw new Exception($"Invalid mole quantity \"{moles}\" in gas Id {gasId} after adjusting moles with \"{quantity}\"!"); throw new Exception($"Invalid mole quantity \"{moles}\" in gas Id {gasId} after adjusting moles with \"{quantity}\"!");
} }
} }