Skip to content

fix precision of non-integer power#227

Merged
JeffreySarnoff merged 5 commits intoJuliaMath:mainfrom
araujoms:power
Feb 9, 2026
Merged

fix precision of non-integer power#227
JeffreySarnoff merged 5 commits intoJuliaMath:mainfrom
araujoms:power

Conversation

@araujoms
Copy link
Contributor

@araujoms araujoms commented Feb 7, 2026

When raising an integer to DoubleFloat power precision was lost, because the log was computed as a Float64. This PR fixes this.

Before the PR:

julia> 2^Double64(0.5) - sqrt(big(2))
-1.639813727959775997377421317343763431286407155713134856781850122263015902218541e-17

After the PR:

julia> 2^Double64(0.5) - sqrt(big(2))
-4.138675308699413612074474846792288426668019534744073764445159044568402999352625e-33

A bit unrelated, but why are you converting to Float64 before converting to Int64 here?

@codecov
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.17%. Comparing base (2ef0305) to head (95c89e1).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #227      +/-   ##
==========================================
- Coverage   49.20%   49.17%   -0.04%     
==========================================
  Files          63       63              
  Lines        3410     3406       -4     
==========================================
- Hits         1678     1675       -3     
+ Misses       1732     1731       -1     

☔ View full report in Codecov by Sentry.
📢 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.

@JeffreySarnoff
Copy link
Member

thank you.
If you could, be very specific (file, lines) about
"A bit unrelated, but why are you converting to Float64 before converting to Int64 here?"

@JeffreySarnoff JeffreySarnoff merged commit d7c3101 into JuliaMath:main Feb 9, 2026
7 checks passed
@araujoms
Copy link
Contributor Author

araujoms commented Feb 9, 2026

It was in the line 124 of the file src/math/elementary/explog.jl:

   return r^Int64(Float64(n)) # convert n to Float64 first

it is not there anymore because I deleted it, as it became unnecessary due to the cutoff I introduced in the size of the exponent. Now I just take n.hi.

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