Skip to content

Fix surfit y-bounds, percur zero-pivot, and NaN-safe tests#48

Merged
perazz merged 1 commit intomainfrom
fix/surfit-percur-bugs
Feb 18, 2026
Merged

Fix surfit y-bounds, percur zero-pivot, and NaN-safe tests#48
perazz merged 1 commit intomainfrom
fix/surfit-percur-bugs

Conversation

@perazz
Copy link
Owner

@perazz perazz commented Feb 18, 2026

Summary

  • surfit y-bounds check: y values were validated against xb/xe instead of yb/ye, causing spurious "invalid input" errors when x and y data ranges differed
  • fp_rotate_row_2mat zero-pivot guard: Added if(piv==0) guard matching original Netlib fpperi.f — without it, fpgivs computes 0/0 = NaN when both pivot and target are zero, silently corrupting periodic spline fits
  • percur workspace formula: new_points used curfit's nest*(7+3*k) but percur needs nest*(8+5*k)
  • NaN-safe test comparisons: Changed 6 test assertions from expr > tol to .not.(expr <= tol) so NaN values are caught (IEEE 754: NaN > x is always false)

Test plan

  • fpm test — 59/59 tests pass
  • All 8 example programs run without NaN or errors
  • Periodic curve example now produces correct output (was producing NaN before)
  • Surface example with different x/y ranges now works (was "invalid input" before)

Three bug fixes:

1. surfit: y-values were checked against x-bounds instead of y-bounds,
   causing spurious "invalid input" errors when x/y ranges differed.

2. fp_rotate_row_2mat / fp_rotate_row_2mat_vec: add zero-pivot guards
   matching original Netlib fpperi.f. Without these, fpgivs computes
   0/0 = NaN when both pivot and target are zero.

3. fitpack_curves new_points: use percur workspace formula
   nest*(8+5*k) instead of curfit's nest*(7+3*k).

4. Test comparisons: use `.not.(expr <= tol)` instead of `expr > tol`
   so NaN values are caught (IEEE 754: NaN > x is always false).
@perazz perazz merged commit 78f9706 into main Feb 18, 2026
18 checks passed
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