Skip to content

Commit

Permalink
Merge pull request #173 from dpsanders/rounding2
Browse files Browse the repository at this point in the history
Add missing method for setrounding
  • Loading branch information
tkelman committed Feb 15, 2016
2 parents 348c29b + 7d290fb commit fb05f8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -823,15 +823,26 @@ if VERSION < v"0.5.0-dev+2228"

end

if VERSION < v"0.5.0-dev+1182"
# Pull Request https://github.com/JuliaLang/julia/pull/13232

# Pull Request https://github.com/JuliaLang/julia/pull/13232
# Rounding and precision functions:

if VERSION >= v"0.5.0-dev+1182"
import Base:
setprecision, setrounding, rounding

else # if VERSION < v"0.5.0-dev+1182"

export setprecision
export setrounding
export rounding

setprecision(f, ::Type{BigFloat}, prec) = with_bigfloat_precision(f, prec)
setprecision(::Type{BigFloat}, prec) = set_bigfloat_precision(prec)

# assume BigFloat if type not explicit:
setprecision(prec) = setprecision(BigFloat, prec)
setprecision(f, prec) = setprecision(f, BigFloat, prec)

Base.precision(::Type{BigFloat}) = get_bigfloat_precision()

Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,11 @@ setprecision(BigFloat, 100) do
@test precision(a) == 100
end

setprecision(130) do
a = big(pi)
@test precision(a) == 130
end

for T in (BigFloat, Float64)
setrounding(T, RoundDown)
@test rounding(T) == RoundDown
Expand Down

0 comments on commit fb05f8c

Please sign in to comment.