Skip to content

Respect NaN-safe mode in fma and muladd - #861

Open
devmotion wants to merge 1 commit into
masterfrom
dmw/nansafe-fma
Open

devmotion wants to merge 1 commit into
masterfrom
dmw/nansafe-fma

Conversation

@devmotion

Copy link
Copy Markdown
Member

Fixes #860.

With NaN-safe mode enabled, fma and muladd with three Dual arguments, or with Dual-Real-Dual arguments, computed the partials with plain fma/muladd. So Inf * 0 produced NaN partials, unlike the equivalent x * y + z.

The partials are now computed with _fma_partial and _muladd_partial. They are defined next to _mul_partial and _div_partial, following the same pattern. In NaN-safe mode, a zero partial leaves the accumulated partial unchanged. With NaN-safe mode disabled, they are plain fma/muladd. The only other change is that in the Dual-Real-Dual case the two factors are swapped. For floating-point numbers this gives the same result; for nested Duals it can change the last bit of the partials.

The new tests check that fma(x, y, z) and muladd(x, y, z) are isequal to x * y + z in both modes, for the examples in #860.

🤖 Generated with Claude Code

Fixes #860.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.29%. Comparing base (a3c0f4f) to head (f98da3c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #861      +/-   ##
==========================================
+ Coverage   91.23%   91.29%   +0.06%     
==========================================
  Files          11       11              
  Lines        1072     1080       +8     
==========================================
+ Hits          978      986       +8     
  Misses         94       94              

☔ 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.

This branch has not been deployed

No deployments
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.

fma and muladd ignore NaN-safe mode

1 participant