Skip to content

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

Open
antoine-levitt wants to merge 1 commit into
JuliaDiff:masterfrom
antoine-levitt:fix-pow-real-base-precision
Open

Don't widen the primal when differentiating x^y with a real base#824
antoine-levitt wants to merge 1 commit 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 (5f21679).

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.

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