diff options
author | Russ Cox <rsc@golang.org> | 2011-01-19 23:09:00 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-01-19 23:09:00 -0500 |
commit | ed3592f95664c555d787d87b28ff783b846257e6 (patch) | |
tree | 9bfdc7720f6c491c1c293a4bd367abec2a1221f4 /src/pkg/strconv | |
parent | 8d36be6d5ae904467a0be5e7dc3965581a3dbf73 (diff) | |
download | go-ed3592f95664c555d787d87b28ff783b846257e6.tar.gz |
delete float, complex - code changes
also:
cmplx -> complex
float64(1.0) -> 1.0
float64(1) -> 1.0
R=gri, r, gri1, r2
CC=golang-dev
http://codereview.appspot.com/3991043
Diffstat (limited to 'src/pkg/strconv')
-rw-r--r-- | src/pkg/strconv/atof.go | 13 | ||||
-rw-r--r-- | src/pkg/strconv/atof_test.go | 25 | ||||
-rw-r--r-- | src/pkg/strconv/ftoa.go | 22 | ||||
-rw-r--r-- | src/pkg/strconv/ftoa_test.go | 4 |
4 files changed, 9 insertions, 55 deletions
diff --git a/src/pkg/strconv/atof.go b/src/pkg/strconv/atof.go index bcb138f7a..72f162c51 100644 --- a/src/pkg/strconv/atof.go +++ b/src/pkg/strconv/atof.go @@ -243,7 +243,7 @@ out: // Compute exact floating-point integer from d's digits. // Caller is responsible for avoiding overflow. func decimalAtof64Int(neg bool, d *decimal) float64 { - f := float64(0) + f := 0.0 for i := 0; i < d.nd; i++ { f = f*10 + float64(d.d[i]-'0') } @@ -400,17 +400,6 @@ func Atof64(s string) (f float64, err os.Error) { return f, err } -// Atof is like Atof32 or Atof64, depending on the size of float. -func Atof(s string) (f float, err os.Error) { - if FloatSize == 32 { - f1, err1 := Atof32(s) - return float(f1), err1 - } - f1, err1 := Atof64(s) - return float(f1), err1 -} - - // AtofN converts the string s to a 64-bit floating-point number, // but it rounds the result assuming that it will be stored in a value // of n bits (32 or 64). diff --git a/src/pkg/strconv/atof_test.go b/src/pkg/strconv/atof_test.go index 68c50bfbe..6cc60e549 100644 --- a/src/pkg/strconv/atof_test.go +++ b/src/pkg/strconv/atof_test.go @@ -150,15 +150,6 @@ func testAtof(t *testing.T, opt bool) { test.in, out32, err, test.out, test.err, out) } } - - if FloatSize == 64 || float64(float32(out)) == out { - outf, err := Atof(test.in) - outs := Ftoa(outf, 'g', -1) - if outs != test.out || !reflect.DeepEqual(err, test.err) { - t.Errorf("Ftoa(%v) = %v, %v want %v, %v # %v", - test.in, outf, err, test.out, test.err, out) - } - } } SetOptimize(oldopt) } @@ -167,26 +158,26 @@ func TestAtof(t *testing.T) { testAtof(t, true) } func TestAtofSlow(t *testing.T) { testAtof(t, false) } -func BenchmarkAtofDecimal(b *testing.B) { +func BenchmarkAtof64Decimal(b *testing.B) { for i := 0; i < b.N; i++ { - Atof("33909") + Atof64("33909") } } -func BenchmarkAtofFloat(b *testing.B) { +func BenchmarkAtof64Float(b *testing.B) { for i := 0; i < b.N; i++ { - Atof("339.7784") + Atof64("339.7784") } } -func BenchmarkAtofFloatExp(b *testing.B) { +func BenchmarkAtof64FloatExp(b *testing.B) { for i := 0; i < b.N; i++ { - Atof("-5.09e75") + Atof64("-5.09e75") } } -func BenchmarkAtofBig(b *testing.B) { +func BenchmarkAtof64Big(b *testing.B) { for i := 0; i < b.N; i++ { - Atof("123456789123456789123456789") + Atof64("123456789123456789123456789") } } diff --git a/src/pkg/strconv/ftoa.go b/src/pkg/strconv/ftoa.go index a6091fc6c..4ec3cdbb9 100644 --- a/src/pkg/strconv/ftoa.go +++ b/src/pkg/strconv/ftoa.go @@ -22,20 +22,6 @@ type floatInfo struct { var float32info = floatInfo{23, 8, -127} var float64info = floatInfo{52, 11, -1023} -func floatsize() int { - // Figure out whether float is float32 or float64. - // 1e-35 is representable in both, but 1e-70 - // is too small for a float32. - var f float = 1e-35 - if f*f == 0 { - return 32 - } - return 64 -} - -// Floatsize gives the size of the float type, either 32 or 64. -var FloatSize = floatsize() - // Ftoa32 converts the 32-bit floating-point number f to a string, // according to the format fmt and precision prec. // @@ -77,14 +63,6 @@ func FtoaN(f float64, fmt byte, prec int, n int) string { return Ftoa64(f, fmt, prec) } -// Ftoa behaves as Ftoa32 or Ftoa64, depending on the size of the float type. -func Ftoa(f float, fmt byte, prec int) string { - if FloatSize == 32 { - return Ftoa32(float32(f), fmt, prec) - } - return Ftoa64(float64(f), fmt, prec) -} - func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string { neg := bits>>flt.expbits>>flt.mantbits != 0 exp := int(bits>>flt.mantbits) & (1<<flt.expbits - 1) diff --git a/src/pkg/strconv/ftoa_test.go b/src/pkg/strconv/ftoa_test.go index 6044afdae..3a862a2be 100644 --- a/src/pkg/strconv/ftoa_test.go +++ b/src/pkg/strconv/ftoa_test.go @@ -121,10 +121,6 @@ var ftoatests = []ftoaTest{ } func TestFtoa(t *testing.T) { - if FloatSize != 32 { - println("floatsize: ", FloatSize) - panic("floatsize") - } for i := 0; i < len(ftoatests); i++ { test := &ftoatests[i] s := Ftoa64(test.f, test.fmt, test.prec) |