LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package strconv_test | 5 package strconv_test |
6 | 6 |
7 import ( | 7 import ( |
8 "math" | 8 "math" |
9 "math/rand" | 9 "math/rand" |
10 . "strconv" | 10 . "strconv" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 {0.05, 'f', 1, "0.1"}, | 117 {0.05, 'f', 1, "0.1"}, |
118 {0.05, 'f', 0, "0"}, | 118 {0.05, 'f', 0, "0"}, |
119 {0.5, 'f', 1, "0.5"}, | 119 {0.5, 'f', 1, "0.5"}, |
120 {0.5, 'f', 0, "0"}, | 120 {0.5, 'f', 0, "0"}, |
121 {1.5, 'f', 0, "2"}, | 121 {1.5, 'f', 0, "2"}, |
122 | 122 |
123 // http://www.exploringbinary.com/java-hangs-when-converting-2-225073858
5072012e-308/ | 123 // http://www.exploringbinary.com/java-hangs-when-converting-2-225073858
5072012e-308/ |
124 {2.2250738585072012e-308, 'g', -1, "2.2250738585072014e-308"}, | 124 {2.2250738585072012e-308, 'g', -1, "2.2250738585072014e-308"}, |
125 // http://www.exploringbinary.com/php-hangs-on-numeric-value-2-225073858
5072011e-308/ | 125 // http://www.exploringbinary.com/php-hangs-on-numeric-value-2-225073858
5072011e-308/ |
126 {2.2250738585072011e-308, 'g', -1, "2.225073858507201e-308"}, | 126 {2.2250738585072011e-308, 'g', -1, "2.225073858507201e-308"}, |
| 127 |
| 128 // Issue 2625. |
| 129 {383260575764816448, 'f', 0, "383260575764816448"}, |
| 130 {383260575764816448, 'g', -1, "3.8326057576481645e+17"}, |
127 } | 131 } |
128 | 132 |
129 func TestFtoa(t *testing.T) { | 133 func TestFtoa(t *testing.T) { |
130 for i := 0; i < len(ftoatests); i++ { | 134 for i := 0; i < len(ftoatests); i++ { |
131 test := &ftoatests[i] | 135 test := &ftoatests[i] |
132 s := FormatFloat(test.f, test.fmt, test.prec, 64) | 136 s := FormatFloat(test.f, test.fmt, test.prec, 64) |
133 if s != test.s { | 137 if s != test.s { |
134 t.Error("testN=64", test.f, string(test.fmt), test.prec,
"want", test.s, "got", s) | 138 t.Error("testN=64", test.f, string(test.fmt), test.prec,
"want", test.s, "got", s) |
135 } | 139 } |
136 x := AppendFloat([]byte("abc"), test.f, test.fmt, test.prec, 64) | 140 x := AppendFloat([]byte("abc"), test.f, test.fmt, test.prec, 64) |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 AppendFloat(dst, -5.11e-95, 'g', -1, 64) | 247 AppendFloat(dst, -5.11e-95, 'g', -1, 64) |
244 } | 248 } |
245 } | 249 } |
246 | 250 |
247 func BenchmarkAppendFloatBig(b *testing.B) { | 251 func BenchmarkAppendFloatBig(b *testing.B) { |
248 dst := make([]byte, 0, 30) | 252 dst := make([]byte, 0, 30) |
249 for i := 0; i < b.N; i++ { | 253 for i := 0; i < b.N; i++ { |
250 AppendFloat(dst, 123456789123456789123456789, 'g', -1, 64) | 254 AppendFloat(dst, 123456789123456789123456789, 'g', -1, 64) |
251 } | 255 } |
252 } | 256 } |
LEFT | RIGHT |