Skip to content

Commit

Permalink
Drop compat code for Compat.round and friends #500, #530, and #537
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Oct 8, 2019
1 parent bc73673 commit 5508df6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 75 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ Currently, the `@compat` macro supports the following syntaxes:

* `Compat.range` supporting positional and keyword arguments flavors ([#25896]), ([#28708]).

* `Compat.trunc`, `Compat.floor`, `Compat.ceil`, `Compat.round`, take a keyword argument
for `base` and `digits`, `Compat.round` also takes `sigdigits` ([#26156], [#26670]).

* `Compat.mv` and `Compat.cp` with `force` keyword argument ([#26069]).

* `Compat.accumulate`, `Compat.accumulate!`, `Compat.all`, `Compat.any`,
Expand Down
52 changes: 0 additions & 52 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,58 +76,6 @@ end
end
end

# https://github.com/JuliaLang/julia/pull/26670
@static if VERSION < v"0.7.0-DEV.4062"
trunc(x; digits = 0, base = 10) = Base.trunc(x, digits, base)
floor(x; digits = 0, base = 10) = Base.floor(x, digits, base)
ceil(x; digits = 0, base = 10) = Base.ceil(x, digits, base)
function round(x; digits = nothing, sigdigits = nothing, base = 10)
if digits === nothing
if sigdigits === nothing
Base.round(x, 0, base)
else
Base.signif(x, sigdigits, base)
end
else
sigdigits === nothing || throw(AgrumentError("`round` cannot use both `digits` and `sigdigits` arguments"))
Base.round(x, digits, base)
end
end
elseif VERSION < v"0.7.0-DEV.4804"
trunc(x; digits = 0, base = 10) = Base.trunc(x, digits, base = base)
floor(x; digits = 0, base = 10) = Base.floor(x, digits, base = base)
ceil(x; digits = 0, base = 10) = Base.ceil(x, digits, base = base)
function round(x; digits = nothing, sigdigits = nothing, base = 10)
if digits === nothing
if sigdigits === nothing
Base.round(x, 0, base = base)
else
Base.signif(x, sigdigits, base = base)
end
else
sigdigits === nothing || throw(AgrumentError("`round` cannot use both `digits` and `sigdigits` arguments"))
Base.round(x, digits, base = base)
end
end
elseif VERSION < v"0.7.0-beta2.86"
# https://github.com/JuliaLang/julia/pull/28199
trunc(x; digits = 0, base = 10) = Base.trunc(x, digits = digits, base = base)
floor(x; digits = 0, base = 10) = Base.floor(x, digits = digits, base = base)
ceil(x; digits = 0, base = 10) = Base.ceil(x, digits = digits, base = base)
function round(x; digits = nothing, sigdigits = nothing, base = 10)
if digits === nothing && sigdigits === nothing
Base.round(x, digits = 0, base = base)
else
Base.round(x, digits = digits, sigdigits = sigdigits, base = base)
end
end
else
trunc(x; digits = 0, base = 10) = Base.trunc(x, digits = digits, base = base)
floor(x; digits = 0, base = 10) = Base.floor(x, digits = digits, base = base)
ceil(x; digits = 0, base = 10) = Base.ceil(x, digits = digits, base = base)
round(x; digits = nothing, sigdigits = nothing, base = 10) = Base.round(x, digits = digits, sigdigits = sigdigits, base = base)
end

# https://github.com/JuliaLang/julia/pull/25872
if VERSION < v"0.7.0-DEV.3734"
if isdefined(Base, :open_flags)
Expand Down
6 changes: 6 additions & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ Base.@deprecate floor(x, digits; base = 10) Compat.floor(x, digits = digits, bas
Base.@deprecate ceil(x, digits; base = 10) Compat.ceil(x, digits = digits, base = base) false
Base.@deprecate round(x, digits; base = 10) Compat.round(x, digits = digits, base = base) false
Base.@deprecate signif(x, digits; base = 10) Compat.round(x, sigdigits = digits, base = base) false
# standard methods from Base; can be removed (so that Compat just inherits the functions
# from Base) once above deprecations are removed
trunc(x; digits = 0, base = 10) = Base.trunc(x, digits = digits, base = base)
floor(x; digits = 0, base = 10) = Base.floor(x, digits = digits, base = base)
ceil(x; digits = 0, base = 10) = Base.ceil(x, digits = digits, base = base)
round(x; digits = nothing, sigdigits = nothing, base = 10) = Base.round(x, digits = digits, sigdigits = sigdigits, base = base)

if VERSION >= v"1.1.0-DEV.506"
# deprecation of range(start, stop) for earlier versions is done in Compat.jl
Expand Down
20 changes: 20 additions & 0 deletions test/old.jl
Original file line number Diff line number Diff line change
Expand Up @@ -794,3 +794,23 @@ module TestNames
end
@test :foo in Compat.names(TestNames)
@test :bar in Compat.names(TestNames, all=true)

# 0.7.0-DEV.4804
@test Compat.trunc(pi) == 3.0
@test Compat.floor(pi) == 3.0
@test Compat.ceil(pi) == 4.0
@test Compat.round(pi) == 3.0
@test Compat.trunc(pi, digits = 3) == 3.141
@test Compat.floor(pi, digits = 3) == 3.141
@test Compat.ceil(pi, digits = 3) == 3.142
@test Compat.round(pi, digits = 3) == 3.142
@test Compat.round(pi, sigdigits = 5) == 3.1416
@test Compat.trunc(pi, base = 2) == 3.0
@test Compat.floor(pi, base = 2) == 3.0
@test Compat.ceil(pi, base = 2) == 4.0
@test Compat.round(pi, base = 2) == 3.0
@test Compat.trunc(pi, digits = 3, base = 2) == 3.125
@test Compat.floor(pi, digits = 3, base = 2) == 3.125
@test Compat.ceil(pi, digits = 3, base = 2) == 3.25
@test Compat.round(pi, digits = 3, base = 2) == 3.125
@test Compat.round(pi, sigdigits = 5, base = 2) == 3.125
20 changes: 0 additions & 20 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,6 @@ end

@test codeunit("foo") == codeunit(SubString("fooαβγ",1,3)) == UInt8

# 0.7.0-DEV.4804
@test Compat.trunc(pi) == 3.0
@test Compat.floor(pi) == 3.0
@test Compat.ceil(pi) == 4.0
@test Compat.round(pi) == 3.0
@test Compat.trunc(pi, digits = 3) == 3.141
@test Compat.floor(pi, digits = 3) == 3.141
@test Compat.ceil(pi, digits = 3) == 3.142
@test Compat.round(pi, digits = 3) == 3.142
@test Compat.round(pi, sigdigits = 5) == 3.1416
@test Compat.trunc(pi, base = 2) == 3.0
@test Compat.floor(pi, base = 2) == 3.0
@test Compat.ceil(pi, base = 2) == 4.0
@test Compat.round(pi, base = 2) == 3.0
@test Compat.trunc(pi, digits = 3, base = 2) == 3.125
@test Compat.floor(pi, digits = 3, base = 2) == 3.125
@test Compat.ceil(pi, digits = 3, base = 2) == 3.25
@test Compat.round(pi, digits = 3, base = 2) == 3.125
@test Compat.round(pi, sigdigits = 5, base = 2) == 3.125

# 0.7.0-DEV.3734
let buf = Compat.IOBuffer(read=true, write=false, maxsize=25)
@test buf.readable
Expand Down

0 comments on commit 5508df6

Please sign in to comment.