Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rem2pi and rem with BigFloats in _quadrant #633

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

lbenet
Copy link
Member

@lbenet lbenet commented Mar 10, 2024

This PR proposes to use rem2pi and rem with BigFloats, instead of the same methods for the specific AbsrtracFloats. The reason is that, in order to guarantee the precision one needs more "guard digits" than the actual precision; see J-M Muller, "Elementary Functions: Algorithms and implementations", Birkhäuser, 3rd ed (2005), chap. 11. While the solution to use BigFloats should have a performance impact, it seems to be at least safe, without implementing more elaborate range reduction methods.

The following illustrates such a case:

julia> x = 6381956970095103 * 2.0^797 # worst case for C = pi/2 for Float64
5.319372648326541e255

julia> xb = big(x) 5.319372648326541416707296656673541083813475031793921822105998164685326343987747e+255

julia> rem2pi(x, RoundNearest)
1.5707963267948966

julia> rem2pi(xb, RoundNearest)
-2.545982325227109106133284489709240971297101919468998568916440481134254101023789

As far as I have checked, or the tests show, there haven't been any issues with this change.

This approach could be adapted for the mod (or should it be rem?) function; cf #129, #145 and #178).

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.43%. Comparing base (5275e5c) to head (3b212a9).
Report is 2 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #633      +/-   ##
==========================================
- Coverage   82.92%   82.43%   -0.50%     
==========================================
  Files          26       26              
  Lines        2173     2277     +104     
==========================================
+ Hits         1802     1877      +75     
- Misses        371      400      +29     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@OlivierHnt
Copy link
Member

OlivierHnt commented Mar 10, 2024

Thx for looking into this! I will need to have a close look at the reference you provided as I know nothing about this topic.

Nota bene: at first glance Section 11.3.2 seems to give us a way to estimate the required number of guard digits, denoted by $-\log_\beta(\epsilon)$ in the text. Then we can infer the necessary precision needed for safely performing rem2pi, so that we can construct bx = BigFloat(x; precision = precision(x) + N).

@lbenet
Copy link
Member Author

lbenet commented Mar 10, 2024

Nota bene: at first glance Section 11.3.2 seems to give us a way to estimate the required number of guard digits, denoted by −logβ⁡(ϵ) in the text. Then we can infer the necessary precision needed for safely performing rem2pi, so that we can construct bx = BigFloat(x; precision = precision(x) + N).

I fully agree; it is much smaller the actual guard bits needed. Yet, I thought it was a bit more messy to get the minimum precision, compute whatever for that precision, and go back, than simply check that the BigFloat precision is large enough.

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.

3 participants