@@ -16,6 +16,13 @@ internal class NetworkDeltaPositionTests
1616 // Lossy as a half float, and two of them still fit under the collapse threshold.
1717 private const float k_LossyStep = 0.7f ;
1818
19+ // The largest finite half float.
20+ private const float k_LargestFiniteHalf = 65504.0f ;
21+
22+ // Finite, but far enough past the half float range that the conversion itself rounds to infinity,
23+ // which reaches the guard by a different path than handing it an infinity outright.
24+ private const float k_RoundsToInfinity = 70000.0f ;
25+
1926 // Past the threshold and exactly representable, so the collapse cannot hinge on rounding.
2027 private const float k_CollapsingStep = NetworkDeltaPosition . MaxDeltaBeforeAdjustment + 0.5f ;
2128
@@ -307,11 +314,9 @@ public void QuantumIsTheSmallestChangeTheEncodingCanSee()
307314 [ Test ]
308315 public void QuantumIsGuardedAtTheTopOfTheRange ( )
309316 {
310- // 70000f is the finite one: the conversion itself rounds to infinity, which reaches the guard
311- // by a different path than handing it an infinity outright.
312317 var values = new [ ]
313318 {
314- 65504.0f , - 65504.0f , 70000.0f ,
319+ k_LargestFiniteHalf , - k_LargestFiniteHalf , k_RoundsToInfinity ,
315320 float . PositiveInfinity , float . NegativeInfinity , float . NaN ,
316321 } ;
317322
@@ -328,13 +333,14 @@ public void QuantumIsNeverNonFiniteOrZero()
328333 {
329334 // Why the guard exists: an infinite step size would make the "has it moved?" comparison in
330335 // UpdateFrom false for every input, silently stopping the rounding loss from being applied.
331- var unguarded = Mathf . HalfToFloat ( 0x7BFF + 1 ) - Mathf . HalfToFloat ( 0x7BFF ) ;
336+ const ushort topOfRange = NetworkDeltaPosition . LargestFiniteHalfBits ;
337+ var unguarded = Mathf . HalfToFloat ( topOfRange + 1 ) - Mathf . HalfToFloat ( topOfRange ) ;
332338 Assert . IsTrue ( float . IsInfinity ( unguarded ) || float . IsNaN ( unguarded ) ,
333339 "The unguarded computation at the top of the range should be non-finite, which is why the guard exists." ) ;
334340
335341 var values = new [ ]
336342 {
337- 0.0f , float . Epsilon , 1e-7f , 0.5f , 1.0f , 100.0f , 65503.0f , 65504.0f , - 65504.0f , 70000.0f ,
343+ 0.0f , float . Epsilon , 1e-7f , 0.5f , 1.0f , 100.0f , 65503.0f , k_LargestFiniteHalf , - k_LargestFiniteHalf , k_RoundsToInfinity ,
338344 float . PositiveInfinity , float . NegativeInfinity , float . NaN ,
339345 } ;
340346
0 commit comments