Skip to content

fix: correct xMaxAbsoluteValue sign and guard numeric edge cases#383

Merged
lpatiny merged 1 commit into
mainfrom
fix-x-numeric-edge-cases
Jul 9, 2026
Merged

fix: correct xMaxAbsoluteValue sign and guard numeric edge cases#383
lpatiny merged 1 commit into
mainfrom
fix-x-numeric-edge-cases

Conversation

@lpatiny

@lpatiny lpatiny commented Jul 8, 2026

Copy link
Copy Markdown
Member

Audit of the x/ helpers surfaced one real bug and several edge cases.

Bugs

  • xMaxAbsoluteValue seeded its accumulator with the raw first element instead of Math.abs, so a negative largest-magnitude value (incl. at index 0) was wrong — e.g. [-5, -3] returned 3.
  • xSequentialFillFromTo({ size: 1 }) and xSampling(array, { length: 1 }) divided by zero and returned [NaN]; they now return [from] / the first element.

Perf

  • xDotProduct no longer allocates an intermediate array via xMultiply — single zero-allocation loop.
  • xApplyFunctionStr allocates the output instead of copying values that are immediately overwritten.

Regression tests added for each bug.

- xMaxAbsoluteValue: seed the accumulator with Math.abs so a negative
  largest-magnitude element (including at index 0) is handled correctly
- xSequentialFillFromTo: size 1 returned [NaN], now returns [from]
- xSampling: length 1 returned [NaN], now returns the first element
- xDotProduct: fuse into a single zero-allocation loop instead of
  allocating an intermediate array via xMultiply
- xApplyFunctionStr: allocate the output instead of copying values that
  are immediately overwritten
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.13%. Comparing base (9fed281) to head (524d575).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #383   +/-   ##
=======================================
  Coverage   97.13%   97.13%           
=======================================
  Files         207      207           
  Lines        4147     4147           
  Branches     1036     1038    +2     
=======================================
  Hits         4028     4028           
  Misses        115      115           
  Partials        4        4           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lpatiny lpatiny merged commit 1b2ddd0 into main Jul 9, 2026
10 checks passed
@lpatiny lpatiny deleted the fix-x-numeric-edge-cases branch July 9, 2026 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant