Skip to content

Commit 6801cb8

Browse files
committed
fix consistency of trimtrailingzeros (Ryu)
1 parent 24d9eab commit 6801cb8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

base/ryu/fixed.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ function writefixed(buf, pos, v::T,
1010
if x == 0
1111
buf[pos] = UInt8('0')
1212
pos += 1
13-
if precision > 0
13+
if precision > 0 && !trimtrailingzeros
1414
buf[pos] = decchar
1515
pos += 1
16-
if trimtrailingzeros
17-
precision = 1
18-
end
1916
for _ = 1:precision
2017
buf[pos] = UInt8('0')
2118
pos += 1

test/ryu.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,11 @@ end # Float16
544544
@test Ryu.writefixed(7.018232e-82, 6) == "0.000000"
545545
end
546546

547+
@testset "Consistency of trimtrailingzeros" begin
548+
Ryu.writefixed(0.0, 1, false, false, false, UInt8('.'), true) == "0"
549+
Ryu.writefixed(1.0, 1, false, false, false, UInt8('.'), true) == "1"
550+
Ryu.writefixed(2.0, 1, false, false, false, UInt8('.'), true) == "2"
551+
end
547552
end # fixed
548553

549554
@testset "Ryu.writeexp" begin

0 commit comments

Comments
 (0)