Skip to content

Commit 0402d82

Browse files
jmkuhnfredrikekre
authored andcommitted
Make base a keyword for trunc, floor, ceil, round, signif (#500)
* Make base a keyword for trunc, floor, ceil, round, signif
1 parent ffdfa1e commit 0402d82

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ Currently, the `@compat` macro supports the following syntaxes:
280280

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

283+
* `Compat.trunc`, `Compat.floor`, `Compat.ceil`, `Compat.round`, `Compat.signif` take a keyword argument for `base` ([#26156]).
284+
283285
## Renaming
284286

285287
* `Display` is now `AbstractDisplay` ([#24831]).
@@ -580,3 +582,4 @@ includes this fix. Find the minimum version from there.
580582
[#25896]: https://github.com/JuliaLang/julia/issues/25896
581583
[#25990]: https://github.com/JuliaLang/julia/issues/25990
582584
[#26089]: https://github.com/JuliaLang/julia/issues/26089
585+
[#26156]: https://github.com/JuliaLang/julia/issues/26156

src/Compat.jl

+11-2
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ if VERSION < v"0.7.0-DEV.2402"
731731
inconsistent length.
732732
"""
733733
function Base.ceil(x::Compat.ConvertiblePeriod, precision::Compat.ConvertiblePeriod)
734-
f = floor(x, precision)
734+
f = Base.floor(x, precision)
735735
return (x == f) ? f : f + precision
736736
end
737737

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

@@ -1569,6 +1569,15 @@ else
15691569
end
15701570
end
15711571

1572+
# https://github.com/JuliaLang/julia/pull/26156
1573+
@static if VERSION < v"0.7.0-DEV.4062"
1574+
trunc(x, digits; base = base) = Base.trunc(x, digits, base)
1575+
floor(x, digits; base = base) = Base.floor(x, digits, base)
1576+
ceil(x, digits; base = base) = Base.ceil(x, digits, base)
1577+
round(x, digits; base = base) = Base.round(x, digits, base)
1578+
signif(x, digits; base = base) = Base.signif(x, digits, base)
1579+
end
1580+
15721581
# https://github.com/JuliaLang/julia/pull/25872
15731582
if VERSION < v"0.7.0-DEV.3734"
15741583
if isdefined(Base, :open_flags)

test/runtests.jl

+7
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,13 @@ end
14351435
@test :foo in Compat.names(TestNames)
14361436
@test :bar in Compat.names(TestNames, all=true)
14371437

1438+
# 0.7.0-DEV.4062
1439+
@test Compat.trunc(pi, 3, base = 2) == 3.125
1440+
@test Compat.floor(pi, 3, base = 2) == 3.125
1441+
@test Compat.ceil(pi, 3, base = 2) == 3.25
1442+
@test Compat.round(pi, 3, base = 2) == 3.125
1443+
@test Compat.signif(pi, 5, base = 2) == 3.125
1444+
14381445
# 0.7.0-DEV.3734
14391446
let buf = Compat.IOBuffer(read=true, write=false, maxsize=25)
14401447
@test buf.readable

0 commit comments

Comments
 (0)