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

Make precision a keyword argument, improve handling of rounding mode. #29157

Merged
merged 12 commits into from
Nov 19, 2018
Next Next commit
Improve handling of precision and rounding mode arguments in BigFloat…
… constructors.

This makes a few changes to avoid unnecessarily calling `setrounding` and `setprecision`. It also changes `precision` to be a keyword argument (though does not yet deprecate the old behaviour).
  • Loading branch information
simonbyrne committed Oct 7, 2018
commit a65f06ae4657950b46e4ef7dd3f2473d02ec7ad9
12 changes: 8 additions & 4 deletions base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,18 @@ macro irrational(sym, val, def)
esym = esc(sym)
qsym = esc(Expr(:quote, sym))
bigconvert = isa(def,Symbol) ? quote
function Base.BigFloat(::Irrational{$qsym})
c = BigFloat()
function Base.BigFloat(::Irrational{$qsym}, r::MPFR.MPFRRoundingMode=MPFR.ROUNDING_MODE[]; precision=precision(BigFloat))
c = BigFloat(;precision=precision)
ccall(($(string("mpfr_const_", def)), :libmpfr),
Cint, (Ref{BigFloat}, Int32), c, MPFR.ROUNDING_MODE[])
Cint, (Ref{BigFloat}, MPFR.MPFRRoundingMode), c, r)
return c
end
end : quote
Base.BigFloat(::Irrational{$qsym}) = $(esc(def))
function Base.BigFloat(::Irrational{$qsym}; precision=precision(BigFloat))
setprecision(BigFloat, precision) do
$(esc(def))
end
end
end
quote
const $esym = Irrational{$qsym}()
Expand Down
Loading