aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2008-11-17 12:34:03 -0800
committerRuss Cox <rsc@golang.org>2008-11-17 12:34:03 -0800
commit079c00a475d11f71a69fe848dd67e8fe34ac88a8 (patch)
treeaeb58cc993873dadfe1a2adbc63521879b2dd66a /test
parentf333f4685cc667dda0be6ecd5500ff8fa10f4a2a (diff)
downloadgo-079c00a475d11f71a69fe848dd67e8fe34ac88a8.tar.xz
correctly rounded floating-point conversions
in new package strconv. move atoi etc to strconv too. update fmt, etc to use strconv. R=r DELTA=2232 (1691 added, 424 deleted, 117 changed) OCL=19286 CL=19380
Diffstat (limited to 'test')
-rw-r--r--test/chan/goroutines.go4
-rw-r--r--test/fmt_test.go22
-rw-r--r--test/stringslib.go29
3 files changed, 29 insertions, 26 deletions
diff --git a/test/chan/goroutines.go b/test/chan/goroutines.go
index b86ed8848d..b480e5085f 100644
--- a/test/chan/goroutines.go
+++ b/test/chan/goroutines.go
@@ -10,7 +10,7 @@
package main
import (
- "strings";
+ "strconv";
)
func f(left, right *chan int) {
@@ -21,7 +21,7 @@ func main() {
var n = 10000;
if sys.argc() > 1 {
var ok bool;
- n, ok = strings.atoi(sys.argv(1));
+ n, ok = strconv.atoi(sys.argv(1));
if !ok {
print("bad arg\n");
sys.exit(1);
diff --git a/test/fmt_test.go b/test/fmt_test.go
index f694a55af9..dfc7fdd886 100644
--- a/test/fmt_test.go
+++ b/test/fmt_test.go
@@ -44,8 +44,8 @@ func main() {
E(f.s("\tb ").b(7), "\tb 111");
E(f.s("\tb64 ").b64(B64), "\tb64 1111111111111111111111111111111111111111111111111111111111111111");
E(f.s("\te ").e64(1.), "\te 1.000000e+00");
- E(f.s("\te ").e64(1234.5678e3), "\te 1.234567e+06");
- E(f.s("\te ").e64(1234.5678e-8), "\te 1.234567e-05");
+ E(f.s("\te ").e64(1234.5678e3), "\te 1.234568e+06");
+ E(f.s("\te ").e64(1234.5678e-8), "\te 1.234568e-05");
E(f.s("\te ").e64(-7.0), "\te -7.000000e+00");
E(f.s("\te ").e64(-1e-9), "\te -1.000000e-09");
E(f.s("\tf ").f64(1234.5678e3), "\tf 1234567.800000");
@@ -53,9 +53,9 @@ func main() {
E(f.s("\tf ").f64(-7.0), "\tf -7.000000");
E(f.s("\tf ").f64(-1e-9), "\tf -0.000000");
E(f.s("\tg ").g64(1234.5678e3), "\tg 1234567.8");
- E(f.s("\tg ").g64(1234.5678e-8), "\tg 0.000012");
- E(f.s("\tg ").g64(-7.0), "\tg -7.");
- E(f.s("\tg ").g64(-1e-9), "\tg -0.");
+ E(f.s("\tg ").g64(1234.5678e-8), "\tg 1.2345678e-05");
+ E(f.s("\tg ").g64(-7.0), "\tg -7");
+ E(f.s("\tg ").g64(-1e-9), "\tg -1e-09");
E(f.s("\tc ").c('x'), "\tc x");
E(f.s("\tc ").c(0xe4), "\tc ä");
E(f.s("\tc ").c(0x672c), "\tc 本");
@@ -74,9 +74,9 @@ func main() {
E(f.s("\t-20.5s\t|").wp(-20,5).s("qwertyuiop").s("|"), "\t-20.5s\t|qwert |");
E(f.s("\t20c\t|").w(20).c('x').s("|"), "\t20c\t| x|");
E(f.s("\t-20c\t|").w(-20).c('x').s("|"), "\t-20c\t|x |");
- E(f.s("\t20e\t|").w(20).e(1.2345e3).s("|"), "\t20e\t| 1.234500e+03|");
- E(f.s("\t20e\t|").w(20).e(1.2345e-3).s("|"), "\t20e\t| 1.234500e-03|");
- E(f.s("\t-20e\t|").w(-20).e(1.2345e3).s("|"), "\t-20e\t|1.234500e+03 |");
+ E(f.s("\t20e\t|").wp(20, 6).e(1.2345e3).s("|"), "\t20e\t| 1.234500e+03|");
+ E(f.s("\t20e\t|").wp(20, 6).e(1.2345e-3).s("|"), "\t20e\t| 1.234500e-03|");
+ E(f.s("\t-20e\t|").wp(-20, 6).e(1.2345e3).s("|"), "\t-20e\t|1.234500e+03 |");
E(f.s("\t20.8e\t|").wp(20,8).e(1.2345e3).s("|"), "\t20.8e\t| 1.23450000e+03|");
E(f.s("\t20f\t|").w(20).f64(1.23456789e3).s("|"), "\t20f\t| 1234.567890|");
E(f.s("\t20f\t|").w(20).f64(1.23456789e-3).s("|"), "\t20f\t| 0.001235|");
@@ -85,10 +85,10 @@ func main() {
E(f.s("\t20.8f\t|").wp(20,8).f64(1.23456789e3).s("|"), "\t20.8f\t| 1234.56789000|");
E(f.s("\t20.8f\t|").wp(20,8).f64(1.23456789e-3).s("|"), "\t20.8f\t| 0.00123457|");
E(f.s("\tg\t|").g64(1.23456789e3).s("|"), "\tg\t|1234.56789|");
- E(f.s("\tg\t|").g64(1.23456789e-3).s("|"), "\tg\t|0.001235|");
- E(f.s("\tg\t|").g64(1.23456789e20).s("|"), "\tg\t|1.234567e+20|");
+ E(f.s("\tg\t|").g64(1.23456789e-3).s("|"), "\tg\t|0.00123456789|");
+ E(f.s("\tg\t|").g64(1.23456789e20).s("|"), "\tg\t|1.23456789e+20|");
- E(f.s("\tE\t|").w(20).g64(sys.Inf(1)).s("|"), "\tE\t| Inf|");
+ E(f.s("\tE\t|").w(20).g64(sys.Inf(1)).s("|"), "\tE\t| +Inf|");
E(f.s("\tF\t|").w(-20).g64(sys.Inf(-1)).s("|"), "\tF\t|-Inf |");
E(f.s("\tG\t|").w(20).g64(sys.NaN()).s("|"), "\tG\t| NaN|");
}
diff --git a/test/stringslib.go b/test/stringslib.go
index e9a919cad6..d02890bc0d 100644
--- a/test/stringslib.go
+++ b/test/stringslib.go
@@ -6,7 +6,10 @@
package main
-import strings "strings"
+import (
+ "strconv";
+ "strings";
+)
func split(s, sep string) *[]string {
a := strings.split(s, sep);
@@ -31,8 +34,8 @@ func explode(s string) *[]string {
}
func itoa(i int) string {
- s := strings.itoa(i);
- n, ok := strings.atoi(s);
+ s := strconv.itoa(i);
+ n, ok := strconv.atoi(s);
if n != i {
print("itoa: ", i, " ", s, "\n");
panic("itoa")
@@ -91,17 +94,17 @@ func main() {
}
{
- n, ok := strings.atoi("0"); if n != 0 || !ok { panic("atoi 0") }
- n, ok = strings.atoi("-1"); if n != -1 || !ok { panic("atoi -1") }
- n, ok = strings.atoi("+345"); if n != 345 || !ok { panic("atoi +345") }
- n, ok = strings.atoi("9999"); if n != 9999 || !ok { panic("atoi 9999") }
- n, ok = strings.atoi("20ba"); if n != 0 || ok { panic("atoi 20ba") }
- n, ok = strings.atoi("hello"); if n != 0 || ok { panic("hello") }
+ n, ok := strconv.atoi("0"); if n != 0 || !ok { panic("atoi 0") }
+ n, ok = strconv.atoi("-1"); if n != -1 || !ok { panic("atoi -1") }
+ n, ok = strconv.atoi("+345"); if n != 345 || !ok { panic("atoi +345") }
+ n, ok = strconv.atoi("9999"); if n != 9999 || !ok { panic("atoi 9999") }
+ n, ok = strconv.atoi("20ba"); if n != 0 || ok { panic("atoi 20ba") }
+ n, ok = strconv.atoi("hello"); if n != 0 || ok { panic("hello") }
}
- if strings.ftoa(1e6) != "+1.000000e+06" { panic("ftoa 1e6") }
- if strings.ftoa(-1e-6) != "-1.000000e-06" { panic("ftoa -1e-6") }
- if strings.ftoa(-1.234567e-6) != "-1.234567e-06" { panic("ftoa -1.234567e-6") }
+ if strconv.ftoa(1e6, 'e', 6) != "1.000000e+06" { panic("ftoa 1e6") }
+ if strconv.ftoa(-1e-6, 'e', 6) != "-1.000000e-06" { panic("ftoa -1e-6") }
+ if strconv.ftoa(-1.234567e-6, 'e', 6) != "-1.234567e-06" { panic("ftoa -1.234567e-6") }
if itoa(0) != "0" { panic("itoa 0") }
if itoa(12345) != "12345" { panic("itoa 12345") }
@@ -111,7 +114,7 @@ func main() {
// if itoa(-1<<63) != "-9223372036854775808" { panic("itoa 1<<63") }
{
- a, ok := strings.atof64("-1.2345e4");
+ a, overflow, ok := strconv.atof64("-1.2345e4");
if !ok || a != -12345. { panic(a, "atof64 -1.2345e4") }
}
}