Skip to content

Commit

Permalink
Merge pull request JuliaLang#36819 from JuliaLang/jq/36234
Browse files Browse the repository at this point in the history
Fix compact float printing when output contains exactly 6 digits
  • Loading branch information
quinnj committed Jul 27, 2020
2 parents 3b67e47 + ada82ac commit bb90d64
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion base/ryu/shortest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ end
olength = decimallength(output)
exp_form = true
pt = nexp + olength
if -4 < pt <= (precision == -1 ? (T == Float16 ? 3 : 6) : precision)
if -4 < pt <= (precision == -1 ? (T == Float16 ? 3 : 6) : precision) &&
!(pt >= olength && abs(mod(x + 0.05, 10^(pt - olength)) - 0.05) > 0.05)
exp_form = false
if pt <= 0
buf[pos] = UInt8('0')
Expand Down
6 changes: 4 additions & 2 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,16 @@ end
@test repr(-NaN) == "NaN"
@test repr(Float64(pi)) == "3.141592653589793"
# issue 6608
@test sprint(show, 666666.6, context=:compact => true) == "666667.0"
@test sprint(show, 666666.6, context=:compact => true) == "6.66667e5"
@test sprint(show, 666666.049, context=:compact => true) == "666666.0"
@test sprint(show, 666665.951, context=:compact => true) == "666666.0"
@test sprint(show, 66.66666, context=:compact => true) == "66.6667"
@test sprint(show, -666666.6, context=:compact => true) == "-666667.0"
@test sprint(show, -666666.6, context=:compact => true) == "-6.66667e5"
@test sprint(show, -666666.049, context=:compact => true) == "-666666.0"
@test sprint(show, -666665.951, context=:compact => true) == "-666666.0"
@test sprint(show, -66.66666, context=:compact => true) == "-66.6667"
@test sprint(show, -498796.2749933266, context=:compact => true) == "-4.98796e5"
@test sprint(show, 123456.78, context=:compact=>true) == "1.23457e5"

@test repr(1.0f0) == "1.0f0"
@test repr(-1.0f0) == "-1.0f0"
Expand Down

0 comments on commit bb90d64

Please sign in to comment.