s := bufio.NewScanner(strings.NewReader(testfp))
for lineno := 1; s.Scan(); lineno++ {
line := s.Text()
- if len(line) == 0 || line[0] == '#' {
+ line, _, _ = strings.Cut(line, "#")
+ line = strings.TrimSpace(line)
+ if line == "" {
continue
}
a := strings.Split(line, " ")
if len(a) != 4 {
- t.Error("testdata/testfp.txt:", lineno, ": wrong field count")
+ t.Errorf("testdata/testfp.txt:%d: wrong field count", lineno)
continue
}
var s string
var ok bool
v, ok = myatof64(a[2])
if !ok {
- t.Error("testdata/testfp.txt:", lineno, ": cannot atof64 ", a[2])
+ t.Errorf("testdata/testfp.txt:%d: cannot atof64 %s", lineno, a[2])
continue
}
s = fmt.Sprintf(a[1], v)
case "float32":
v1, ok := myatof32(a[2])
if !ok {
- t.Error("testdata/testfp.txt:", lineno, ": cannot atof32 ", a[2])
+ t.Errorf("testdata/testfp.txt:%d: cannot atof32 %s", lineno, a[2])
continue
}
s = fmt.Sprintf(a[1], v1)
v = float64(v1)
}
if s != a[3] {
- t.Error("testdata/testfp.txt:", lineno, ": ", a[0], " ", a[1], " ", a[2], " (", v, ") ",
- "want ", a[3], " got ", s)
+ t.Errorf("testdata/testfp.txt:%d: %s %s %s %s: have %s want %s", lineno, a[0], a[1], a[2], a[3], s, a[3])
}
}
if s.Err() != nil {
package strconv_test
import (
+ . "internal/strconv"
"math"
"math/rand"
- . "internal/strconv"
"testing"
)
{"64Fixed1", 123456, 'e', 3, 64},
{"64Fixed2", 123.456, 'e', 3, 64},
+ {"64Fixed2.5", 1.2345e+06, 'e', 3, 64},
{"64Fixed3", 1.23456e+78, 'e', 3, 64},
{"64Fixed4", 1.23456e-78, 'e', 3, 64},
+ {"64Fixed5Hard", 4.096e+25, 'e', 5, 64}, // needs divisiblePow5(..., 20)
{"64Fixed12", 1.23456e-78, 'e', 12, 64},
{"64Fixed16", 1.23456e-78, 'e', 16, 64},
// From testdata/testfp.txt
{"64Fixed17Hard", math.Ldexp(8887055249355788, 665), 'e', 17, 64},
{"64Fixed18Hard", math.Ldexp(6994187472632449, 690), 'e', 18, 64},
+ {"64FixedF1", 123.456, 'f', 6, 64},
+ {"64FixedF2", 0.0123, 'f', 6, 64},
+ {"64FixedF3", 12.3456, 'f', 2, 64},
+
// Trigger slow path (see issue #15672).
// The shortest is: 8.034137530808823e+43
{"Slowpath64", 8.03413753080882349e+43, 'e', -1, 64},