Skip to content

Commit d116e94

Browse files
committed
Fix issue #63 - incorrect results with python format e
1 parent 88dff5c commit d116e94

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/fmtcore.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,14 @@ function _pfmt_e(out::IO, fs::FormatSpec, x::AbstractFloat)
264264
else
265265
rax = round(ax; sigdigits = fs.prec + 1)
266266
e = floor(Integer, log10(rax)) # exponent
267-
u = rax * exp10(-e) # significand
267+
u = round(rax * exp10(-e); sigdigits = fs.prec + 1) # significand
268268
i = 0
269269
v10 = 1
270270
while isinf(u)
271271
i += 1
272272
i > 18 && (u = 0.0; e = 0; break)
273273
v10 *= 10
274-
u = v10 * rax * exp10(-e - i)
274+
u = round(v10 * rax * exp10(-e - i); sigdigits = fs.prec + 1)
275275
end
276276
end
277277

test/fmtspec.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ end
150150
# Issue #110 (in Formatting.jl)
151151
f = FormatExpr("{:+d}")
152152
for T in (Int8, Int16, Int32, Int64, Int128)
153-
@test format(f, typemin(T)) = string(typemin(T))
153+
@test format(f, typemin(T)) == string(typemin(T))
154154
end
155155
end
156156

@@ -257,6 +257,9 @@ end
257257
@test pyfmt("+11.3e", 1.0e-309) == "+1.000e-309"
258258
@test pyfmt("+11.3e", 1.0e-313) == "+1.000e-313"
259259

260+
# issue #108 (from Formatting.jl)
261+
@test pyfmt(".1e", 0.0003) == "3.0e-04"
262+
@test pyfmt(".1e", 0.0006) == "6.0e-04"
260263
end
261264

262265
@testset "Format special floating point value" begin
@@ -279,6 +282,7 @@ end
279282
@test pyfmt("<5f", Inf) == "Inf "
280283
@test pyfmt("^5f", Inf) == " Inf "
281284
@test pyfmt(">5f", Inf) == " Inf"
285+
282286
@test pyfmt("*<5f", Inf) == "Inf**"
283287
@test pyfmt("⋆<5f", Inf) == "Inf⋆⋆"
284288
@test pyfmt("*^5f", Inf) == "*Inf*"

0 commit comments

Comments
 (0)