Skip to content

Commit

Permalink
Merge pull request #171 from dpsanders/bigfloat_functions
Browse files Browse the repository at this point in the history
New names for BigFloat precision and rounding functions
  • Loading branch information
tkelman committed Feb 12, 2016
2 parents e7a4884 + e0ac909 commit 348c29b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ Currently, the `@compat` macro supports the following syntaxes:

* `readall` and `readbytes` are now `readstring` and `read` [#14660](https://github.com/JuliaLang/julia/pull/14660)

* `get_bigfloat_precision` is now `precision(BigFloat)`, `set_precision` is `setprecision` and `with_bigfloat_precision` is now also `setprecision`
[#13232](https://github.com/JuliaLang/julia/pull/13232)

* `get_rounding` is now `rounding`. `set_rounding` and `with_rounding` are now `setrounding` [#13232](https://github.com/JuliaLang/julia/pull/13232)




## New macros

Expand Down
21 changes: 21 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -823,4 +823,25 @@ 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
export setprecision
export setrounding
export rounding

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

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

setrounding(f, T, rounding_mode) =
with_rounding(f, T, rounding_mode)

setrounding(T, rounding_mode) = set_rounding(T, rounding_mode)

rounding(T) = get_rounding(T)

end

end # module
22 changes: 22 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -790,4 +790,26 @@ mktempdir() do dir
cleanup()
end


# https://github.com/JuliaLang/julia/pull/13232

setprecision(BigFloat, 100)
@test precision(BigFloat) == 100
setprecision(256)
@test precision(BigFloat) == 256

setprecision(BigFloat, 100) do
a = big(pi)
@test precision(a) == 100
end

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

setrounding(T, RoundUp) do
@test rounding(T) == RoundUp
end
end

end

0 comments on commit 348c29b

Please sign in to comment.