Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compact float printing when output contains exactly 6 digits #36819

Merged
merged 1 commit into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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