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

add base keyword to precision/setprecision #42428

Merged
merged 7 commits into from
Oct 13, 2021
Merged

add base keyword to precision/setprecision #42428

merged 7 commits into from
Oct 13, 2021

Conversation

stevengj
Copy link
Member

This is just a convenience feature, but I got tired of telling students things like "let's do setprecision(333), which corresponds to about 100 decimal digits". It's a lot easier to just do:

setprecision(100, base=10)

and let Julia multiply by log2(10) for you.

Given this, one also needs the corresponding base argument to precision, so that you can do e.g.

precision(Float64, base=10)

and it will return 15 (the maximum number of decimal digits represented exactly by a 53-bit significand).

@stevengj stevengj added the maths Mathematical functions label Sep 29, 2021
@stevengj
Copy link
Member Author

stevengj commented Sep 29, 2021

(This will also allow us to give a useful definition of precision for DecFP.jl — we can give the exact precision if base==10, and divide by log10(base) in other bases. cc @jmkuhn)

@stevengj
Copy link
Member Author

stevengj commented Sep 30, 2021

(Since we can't dispatch on the presence/absence of keyword arguments, this means that if external packages like Arblib or DoubleFloats or MultiFloats that want to support the new base keyword will want to overload Base._precision instead of Base.precision.)

@stevengj
Copy link
Member Author

stevengj commented Oct 1, 2021

Unrelated CI error on freebsd64:

Error in testset LinearAlgebra/matmul:
Error During Test at none:1
  Got exception outside of a @test
  ProcessExitedException(5)

Copy link
Member

@simeonschaub simeonschaub left a comment

Choose a reason for hiding this comment

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

Could you add a test case for setprecision with a different base as well? Otherwise LGTM.

base/mpfr.jl Outdated Show resolved Hide resolved
Co-authored-by: Simeon Schaub <[email protected]>
@stevengj
Copy link
Member Author

stevengj commented Oct 13, 2021

Could you add a test case for setprecision with a different base as well?

There's already a test: test/mpfr.jl has a test setprecision(100, base=10) do ... end (which calls setprecision(BigFloat, 100, base=100))

Or do you mean you want a test for another base besides base=10? Okay, I added a test with setprecision(50, base=100).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maths Mathematical functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants