Skip to content

Commit

Permalink
Fix a few errors from #26670 (#26760)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne authored and JeffBezanson committed Apr 10, 2018
1 parent c3730bb commit 4984321
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,17 @@ function _round(x, r::RoundingMode, digits::Integer, sigdigits::Nothing, base)
end

hidigit(x::Integer, base) = ndigits0z(x, base)
function hidigit(x::Real, base)
function hidigit(x::AbstractFloat, base)
iszero(x) && return 0
fx = float(x)
if base == 10
return 1 + floor(Int, log10(abs(fx)))
return 1 + floor(Int, log10(abs(x)))
elseif base == 2
return 1 + exponent(x)
else
return 1 + floor(Int, log(base, abs(fx)))
return 1 + floor(Int, log(base, abs(x)))
end
end
hidigit(x::Real, base) = hidigit(float(x), base)

function _round(x, r::RoundingMode, digits::Nothing, sigdigits::Integer, base)
h = hidigit(x, base)
Expand Down
2 changes: 2 additions & 0 deletions base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ for op in Symbol[:+, :-, :*, :/, :^]
end
*(x::Bool, y::AbstractIrrational) = ifelse(x, Float64(y), 0.0)

_round(x::Irrational, r::RoundingMode) = _round(float(x), r)

macro irrational(sym, val, def)
esym = esc(sym)
qsym = esc(Expr(:quote, sym))
Expand Down
5 changes: 5 additions & 0 deletions test/rounding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,13 @@ end

# custom rounding and significant-digit ops
@testset "rounding to digits relative to the decimal point" begin
@test round(pi) 3.
@test round(pi, digits=0) 3.
@test round(pi, digits=1) 3.1
@test round(pi, digits=3, base=2) 3.125
@test round(pi, sigdigits=1) 3.
@test round(pi, sigdigits=3) 3.14
@test round(pi, sigdigits=4, base=2) 3.25
@test round(10*pi, digits=-1) 30.
@test round(.1, digits=0) == 0.
@test round(-.1, digits=0) == -0.
Expand Down

0 comments on commit 4984321

Please sign in to comment.