diff --git a/README.md b/README.md index 4901c9084..9de7aca7a 100644 --- a/README.md +++ b/README.md @@ -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`, diff --git a/src/Compat.jl b/src/Compat.jl index 1bdf5ffba..6a60d1e79 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -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) diff --git a/src/deprecated.jl b/src/deprecated.jl index e76dc980f..4b1488b03 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -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 diff --git a/test/old.jl b/test/old.jl index c1da600ec..ccf68b21a 100644 --- a/test/old.jl +++ b/test/old.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 8b8d89d36..08f5e5cf1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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