diff options
Diffstat (limited to 'src/lib/reflect')
| -rw-r--r-- | src/lib/reflect/test.go | 16 | ||||
| -rw-r--r-- | src/lib/reflect/tostring.go | 20 |
2 files changed, 18 insertions, 18 deletions
diff --git a/src/lib/reflect/test.go b/src/lib/reflect/test.go index 09b3b68410..8497380c78 100644 --- a/src/lib/reflect/test.go +++ b/src/lib/reflect/test.go @@ -72,9 +72,9 @@ func valuedump(s, t string) { case reflect.FloatKind: v.(reflect.FloatValue).Set(3200.0); case reflect.Float32Kind: - v.(reflect.Float32Value).Set(32.0); + v.(reflect.Float32Value).Set(32.1); case reflect.Float64Kind: - v.(reflect.Float64Value).Set(64.0); + v.(reflect.Float64Value).Set(64.2); case reflect.StringKind: v.(reflect.StringValue).Set("stringy cheese"); case reflect.BoolKind: @@ -136,8 +136,8 @@ func main() { valuedump("uint16", "16"); valuedump("uint32", "32"); valuedump("uint64", "64"); - valuedump("float32", "+3.200000e+01"); - valuedump("float64", "+6.400000e+01"); + valuedump("float32", "32.1"); + valuedump("float64", "64.2"); valuedump("string", "stringy cheese"); valuedump("bool", "true"); valuedump("*int8", "*int8(0)"); @@ -146,7 +146,7 @@ func main() { valuedump("**P.integer", "**P.integer(0)"); valuedump("*map[string]int32", "*map[string]int32(0)"); valuedump("*chan<-string", "*chan<-string(0)"); - valuedump("struct {c *chan *int32; d float32}", "struct{c *chan*int32; d float32}{*chan*int32(0), +0.000000e+00}"); + valuedump("struct {c *chan *int32; d float32}", "struct{c *chan*int32; d float32}{*chan*int32(0), 0}"); valuedump("*(a int8, b int32)", "*(a int8, b int32)(0)"); valuedump("struct {c *(? *chan *P.integer, ? *int8)}", "struct{c *(? *chan*P.integer, ? *int8)}{*(? *chan*P.integer, ? *int8)(0)}"); valuedump("struct {a int8; b int32}", "struct{a int8; b int32}{0, 0}"); @@ -158,7 +158,7 @@ func main() { } { var tmp = 123.4; value := reflect.NewValue(tmp); - assert(reflect.ValueToString(value), "+1.234000e+02"); + assert(reflect.ValueToString(value), "123.4"); } { var tmp = "abc"; value := reflect.NewValue(tmp); @@ -166,9 +166,9 @@ func main() { } { var i int = 7; - var tmp = &T{123, 456.0, "hello", &i}; + var tmp = &T{123, 456.75, "hello", &i}; value := reflect.NewValue(tmp); - assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "main.T{123, +4.560000e+02, hello, *int(@)}"); + assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "main.T{123, 456.75, hello, *int(@)}"); } { type C chan *T; // TODO: should not be necessary diff --git a/src/lib/reflect/tostring.go b/src/lib/reflect/tostring.go index 0a7004b311..f33f5272a2 100644 --- a/src/lib/reflect/tostring.go +++ b/src/lib/reflect/tostring.go @@ -9,7 +9,7 @@ package reflect import ( "reflect"; - "strings"; + "strconv"; ) export func TypeToString(typ Type, expand bool) string @@ -81,7 +81,7 @@ func TypeToString(typ Type, expand bool) string { if a.Open() { str = "[]" } else { - str = "[" + strings.ltoa(int64(a.Len())) + "]" + str = "[" + strconv.itoa64(int64(a.Len())) + "]" } return str + TypeToString(a.Elem(), false); case MapKind: @@ -120,11 +120,7 @@ func TypeToString(typ Type, expand bool) string { // TODO: want an unsigned one too func integer(v int64) string { - return strings.ltoa(v); -} - -func floatingpoint(v float64) string { - return strings.f64toa(v); + return strconv.itoa64(v); } func ValueToString(val Value) string { @@ -154,11 +150,15 @@ func ValueToString(val Value) string { case Uint64Kind: return integer(int64(val.(Uint64Value).Get())); case FloatKind: - return floatingpoint(float64(val.(FloatValue).Get())); + if strconv.floatsize == 32 { + return strconv.ftoa32(float32(val.(FloatValue).Get()), 'g', -1); + } else { + return strconv.ftoa64(float64(val.(FloatValue).Get()), 'g', -1); + } case Float32Kind: - return floatingpoint(float64(val.(Float32Value).Get())); + return strconv.ftoa32(val.(Float32Value).Get(), 'g', -1); case Float64Kind: - return floatingpoint(float64(val.(Float64Value).Get())); + return strconv.ftoa64(val.(Float64Value).Get(), 'g', -1); case Float80Kind: return "float80"; case StringKind: |
