Skip to content

Commit 9fdd690

Browse files
rscdr2chase
authored andcommitted
strconv: add tests that Java once mishandled
Change-Id: I372233d8494665b3300f9a186c883a4254435e1c Reviewed-on: https://go-review.googlesource.com/c/go/+/710617 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
1 parent 9b8742f commit 9fdd690

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/strconv/ftoa_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ var ftoatests = []ftoaTest{
172172
{3.999969482421875, 'x', 2, "0x1.00p+02"},
173173
{3.999969482421875, 'x', 1, "0x1.0p+02"},
174174
{3.999969482421875, 'x', 0, "0x1p+02"},
175+
176+
// Cases that Java once mishandled, from David Chase.
177+
{1.801439850948199e+16, 'g', -1, "1.801439850948199e+16"},
178+
{5.960464477539063e-08, 'g', -1, "5.960464477539063e-08"},
179+
{1.012e-320, 'g', -1, "1.012e-320"},
175180
}
176181

177182
func TestFtoa(t *testing.T) {
@@ -186,13 +191,20 @@ func TestFtoa(t *testing.T) {
186191
t.Error("AppendFloat testN=64", test.f, string(test.fmt), test.prec, "want", "abc"+test.s, "got", string(x))
187192
}
188193
if float64(float32(test.f)) == test.f && test.fmt != 'b' {
194+
test_s := test.s
195+
if test.f == 5.960464477539063e-08 {
196+
// This test is an exact float32 but asking for float64 precision in the string.
197+
// (All our other float64-only tests fail to exactness check above.)
198+
test_s = "5.9604645e-08"
199+
continue
200+
}
189201
s := FormatFloat(test.f, test.fmt, test.prec, 32)
190202
if s != test.s {
191-
t.Error("testN=32", test.f, string(test.fmt), test.prec, "want", test.s, "got", s)
203+
t.Error("testN=32", test.f, string(test.fmt), test.prec, "want", test_s, "got", s)
192204
}
193205
x := AppendFloat([]byte("abc"), test.f, test.fmt, test.prec, 32)
194-
if string(x) != "abc"+test.s {
195-
t.Error("AppendFloat testN=32", test.f, string(test.fmt), test.prec, "want", "abc"+test.s, "got", string(x))
206+
if string(x) != "abc"+test_s {
207+
t.Error("AppendFloat testN=32", test.f, string(test.fmt), test.prec, "want", "abc"+test_s, "got", string(x))
196208
}
197209
}
198210
}

0 commit comments

Comments
 (0)