From e0c4598008c23f3dc6fe57d9cc78392e5a4d09b4 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 5 Nov 2025 10:19:24 +0000 Subject: [PATCH] The overflow detection logic in the Balance Meter was not correctly flagging values that were exactly at the tolerance boundary. This change updates the comparison operators from > to >= to ensure that these edge cases are properly handled. A new test case has been added to verify the fix and prevent future regressions. --- lib/math-brain/overflow-detail.ts | 4 ++-- test/overflow-detail.test.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/math-brain/overflow-detail.ts b/lib/math-brain/overflow-detail.ts index 639f3806..a0d04f97 100644 --- a/lib/math-brain/overflow-detail.ts +++ b/lib/math-brain/overflow-detail.ts @@ -244,9 +244,9 @@ export const computeOverflowDetail = ({ const saturationFlag = saturation === true; const magnitudeExceedsRange = - rawMagnitudeValue != null && Math.abs(rawMagnitudeValue) > OVERFLOW_LIMIT + OVERFLOW_TOLERANCE; + rawMagnitudeValue != null && Math.abs(rawMagnitudeValue) >= OVERFLOW_LIMIT + OVERFLOW_TOLERANCE; const directionalExceedsRange = - rawDirectionalBiasValue != null && Math.abs(rawDirectionalBiasValue) > OVERFLOW_LIMIT + OVERFLOW_TOLERANCE; + rawDirectionalBiasValue != null && Math.abs(rawDirectionalBiasValue) >= OVERFLOW_LIMIT + OVERFLOW_TOLERANCE; const overflowRegistered = magnitudeClampedFlag || diff --git a/test/overflow-detail.test.ts b/test/overflow-detail.test.ts index d69b4a9b..8ed8e0bb 100644 --- a/test/overflow-detail.test.ts +++ b/test/overflow-detail.test.ts @@ -125,4 +125,17 @@ describe('overflow detail exports', () => { expect(detail.drivers).toContain('Body 3 ▻ Body 4 Trine'); expect(detail.drivers).not.toContain(''); }); + + it('registers overflow when raw value is exactly at the tolerance boundary', () => { + const detail = computeOverflowDetail({ + rawMagnitude: 5.05, + clampedMagnitude: 5, + rawDirectionalBias: null, + clampedDirectionalBias: null, + aspects: [], + }); + + expect(detail).not.toBeNull(); + expect(detail?.overflowRegistered).toBe(true); + }); });