Skip to content

Commit

Permalink
Make base a keyword for trunc, floor, ceil, round, signif (#500)
Browse files Browse the repository at this point in the history
* Make base a keyword for trunc, floor, ceil, round, signif
  • Loading branch information
jmkuhn authored and fredrikekre committed Mar 6, 2018
1 parent ffdfa1e commit 0402d82
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `Compat.range` supporting keyword arguments ([#25896]).

* `Compat.trunc`, `Compat.floor`, `Compat.ceil`, `Compat.round`, `Compat.signif` take a keyword argument for `base` ([#26156]).

## Renaming

* `Display` is now `AbstractDisplay` ([#24831]).
Expand Down Expand Up @@ -580,3 +582,4 @@ includes this fix. Find the minimum version from there.
[#25896]: https://github.com/JuliaLang/julia/issues/25896
[#25990]: https://github.com/JuliaLang/julia/issues/25990
[#26089]: https://github.com/JuliaLang/julia/issues/26089
[#26156]: https://github.com/JuliaLang/julia/issues/26156
13 changes: 11 additions & 2 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ if VERSION < v"0.7.0-DEV.2402"
inconsistent length.
"""
function Base.ceil(x::Compat.ConvertiblePeriod, precision::Compat.ConvertiblePeriod)
f = floor(x, precision)
f = Base.floor(x, precision)
return (x == f) ? f : f + precision
end

Expand All @@ -742,7 +742,7 @@ if VERSION < v"0.7.0-DEV.2402"
than calling both `floor` and `ceil` individually.
"""
function floorceil(x::Compat.ConvertiblePeriod, precision::Compat.ConvertiblePeriod)
f = floor(x, precision)
f = Base.floor(x, precision)
return f, (x == f) ? f : f + precision
end

Expand Down Expand Up @@ -1569,6 +1569,15 @@ else
end
end

# https://github.com/JuliaLang/julia/pull/26156
@static if VERSION < v"0.7.0-DEV.4062"
trunc(x, digits; base = base) = Base.trunc(x, digits, base)
floor(x, digits; base = base) = Base.floor(x, digits, base)
ceil(x, digits; base = base) = Base.ceil(x, digits, base)
round(x, digits; base = base) = Base.round(x, digits, base)
signif(x, digits; base = base) = Base.signif(x, digits, base)
end

# https://github.com/JuliaLang/julia/pull/25872
if VERSION < v"0.7.0-DEV.3734"
if isdefined(Base, :open_flags)
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,13 @@ end
@test :foo in Compat.names(TestNames)
@test :bar in Compat.names(TestNames, all=true)

# 0.7.0-DEV.4062
@test Compat.trunc(pi, 3, base = 2) == 3.125
@test Compat.floor(pi, 3, base = 2) == 3.125
@test Compat.ceil(pi, 3, base = 2) == 3.25
@test Compat.round(pi, 3, base = 2) == 3.125
@test Compat.signif(pi, 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 0402d82

Please sign in to comment.