Skip to content

Don't widen the primal when differentiating x^y with a real base - #824

Merged
devmotion merged 2 commits into
JuliaDiff:masterfrom
antoine-levitt:fix-pow-real-base-precision
Jul 27, 2026
Merged

Don't widen the primal when differentiating x^y with a real base#824
devmotion merged 2 commits into
JuliaDiff:masterfrom
antoine-levitt:fix-pow-real-base-precision

Conversation

@antoine-levitt

Copy link
Copy Markdown
Contributor

2^x is Float32 for a Float32 x, but 2^Dual{T,Float32,N} came back Dual{T,Float64,N}. Came up on JuliaMolSim/DftFunctionals.jl#33

`2^x` is `Float32` for a `Float32` `x`, but `2^Dual{T,Float32,N}` came back
`Dual{T,Float64,N}`: `expv = x^v` honours Base's promotion, while `log(x)` was
evaluated from `x` alone, so an integer base gave a Float64 partial and the
`Dual` constructor unified value and partials upward. Differentiating should
not change the primal's type.

Take the log in `expv`'s type instead, which is the promotion `^` already chose
for this base/exponent pair. Float64 results are bit-identical; only bases
narrower than the exponent's own promotion (e.g. `Integer`) change, and only in
type. `NaNMath.pow` shares the definition and is fixed too.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017an8Gie5b1ULeSjhep3Sjb
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.74%. Comparing base (090ddbb) to head (5e05ba5).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #824   +/-   ##
=======================================
  Coverage   90.74%   90.74%           
=======================================
  Files          11       11           
  Lines        1070     1070           
=======================================
  Hits          971      971           
  Misses         99       99           

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

@devmotion devmotion left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@devmotion
devmotion merged commit 85dc526 into JuliaDiff:master Jul 27, 2026
20 of 27 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.

2 participants