From f2b5a07453277de6bc500dc283799441cc375239 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 19 Jan 2011 23:09:00 -0500 Subject: [PATCH] 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 https://golang.org/cl/3991043 --- src/pkg/cmath/asin.go | 32 +- src/pkg/cmath/cmath_test.go | 62 +- src/pkg/cmath/conj.go | 2 +- src/pkg/cmath/exp.go | 2 +- src/pkg/cmath/isinf.go | 4 +- src/pkg/cmath/isnan.go | 2 +- src/pkg/cmath/log.go | 2 +- src/pkg/cmath/pow.go | 4 +- src/pkg/cmath/rect.go | 2 +- src/pkg/cmath/sin.go | 8 +- src/pkg/cmath/sqrt.go | 14 +- src/pkg/cmath/tan.go | 16 +- src/pkg/container/vector/numbers_test.go | 6 +- src/pkg/encoding/binary/binary.go | 6 +- src/pkg/encoding/binary/binary_test.go | 6 +- src/pkg/exp/datafmt/datafmt_test.go | 6 +- src/pkg/exp/eval/Makefile | 2 +- src/pkg/exp/eval/bridge.go | 2 - src/pkg/exp/eval/eval_test.go | 6 +- src/pkg/exp/eval/expr.go | 2 +- src/pkg/exp/eval/expr1.go | 37 +- src/pkg/exp/eval/gen.go | 2 +- src/pkg/exp/eval/stmt.go | 2 +- src/pkg/exp/eval/type.go | 10 - src/pkg/exp/eval/value.go | 10 - src/pkg/exp/ogle/rtype.go | 3 - src/pkg/expvar/expvar_test.go | 2 +- src/pkg/flag/flag.go | 30 - src/pkg/flag/flag_test.go | 15 +- src/pkg/fmt/fmt_test.go | 68 +- src/pkg/fmt/format.go | 33 - src/pkg/fmt/print.go | 14 - src/pkg/fmt/scan.go | 9 +- src/pkg/fmt/scan_test.go | 24 +- src/pkg/fmt/stringer_test.go | 4 +- src/pkg/go/doc/doc.go | 2 +- src/pkg/go/printer/nodes.go | 2 +- src/pkg/gob/codec_test.go | 76 +- src/pkg/gob/decode.go | 18 +- src/pkg/gob/encode.go | 22 - src/pkg/gob/encoder_test.go | 16 +- src/pkg/gob/type.go | 6 +- src/pkg/gob/type_test.go | 4 +- src/pkg/json/decode.go | 2 +- src/pkg/json/decode_test.go | 12 +- src/pkg/json/stream_test.go | 4 +- src/pkg/math/all_test.go | 2 +- src/pkg/math/gamma.go | 2 +- src/pkg/math/jn.go | 4 +- src/pkg/math/lgamma.go | 2 +- src/pkg/math/pow.go | 2 +- src/pkg/rand/rand.go | 6 - src/pkg/rand/rand_test.go | 6 +- src/pkg/rand/zipf.go | 2 +- src/pkg/reflect/all_test.go | 31 +- src/pkg/reflect/type.go | 5 +- src/pkg/reflect/value.go | 8 - src/pkg/runtime/type.go | 2 - src/pkg/runtime/type.h | 2 - src/pkg/sort/search.go | 12 +- src/pkg/sort/search_test.go | 6 +- src/pkg/sort/sort.go | 20 +- src/pkg/sort/sort_test.go | 20 +- src/pkg/strconv/atof.go | 13 +- src/pkg/strconv/atof_test.go | 25 +- src/pkg/strconv/ftoa.go | 22 - src/pkg/strconv/ftoa_test.go | 4 - src/pkg/testing/quick/quick.go | 16 +- src/pkg/testing/quick/quick_test.go | 7 +- src/pkg/xml/xml_test.go | 2 - test/append.go | 2 +- test/blank.go | 51 +- test/cmplx.go | 21 +- test/cmplxdivide.c | 2 +- test/cmplxdivide1.go | 4803 +++++++++++----------- test/complit.go | 70 +- test/const1.go | 111 +- test/convlit.go | 44 +- test/decl.go | 12 +- test/declbad.go | 22 +- test/fixedbugs/bug006.go | 15 +- test/fixedbugs/bug007.go | 4 +- test/fixedbugs/bug010.go | 10 +- test/fixedbugs/bug011.go | 16 +- test/fixedbugs/bug035.go | 8 +- test/fixedbugs/bug047.go | 18 +- test/fixedbugs/bug080.go | 14 +- test/fixedbugs/bug109.go | 9 +- test/fixedbugs/bug167.go | 14 +- test/fixedbugs/bug193.go | 12 +- test/fixedbugs/bug220.go | 8 +- test/fixedbugs/bug230.go | 7 +- test/fixedbugs/bug238.go | 2 +- test/fixedbugs/bug248.dir/bug2.go | 2 +- test/fixedbugs/bug248.dir/bug3.go | 2 +- test/fixedbugs/bug299.go | 4 +- test/fixedbugs/bug307.go | 4 +- test/fixedbugs/bug315.go | 2 +- test/fixedbugs/bug316.go | 2 +- test/func.go | 14 +- test/func1.go | 4 +- test/golden.out | 1 - test/interface/explicit.go | 20 +- test/iota.go | 12 +- test/ken/cplx0.go | 2 +- test/ken/cplx1.go | 2 +- test/ken/cplx2.go | 4 +- test/ken/cplx3.go | 12 +- test/ken/cplx4.go | 8 +- test/ken/cplx5.go | 32 +- test/ken/robfunc.go | 96 +- test/ken/simpconv.go | 27 +- test/ken/slicearray.go | 8 +- test/ken/sliceslice.go | 10 +- test/literal.go | 36 +- test/map.go | 167 +- test/named.go | 2 +- test/nil.go | 7 +- test/recover2.go | 2 +- test/test0.go | 40 +- test/typeswitch.go | 13 +- test/zerodivide.go | 188 +- 122 files changed, 3309 insertions(+), 3523 deletions(-) diff --git a/src/pkg/cmath/asin.go b/src/pkg/cmath/asin.go index eb87ba5e5bd..d6a3ca48026 100644 --- a/src/pkg/cmath/asin.go +++ b/src/pkg/cmath/asin.go @@ -51,16 +51,16 @@ import "math" func Asin(x complex128) complex128 { if imag(x) == 0 { if math.Fabs(real(x)) > 1 { - return cmplx(math.Pi/2, 0) // DOMAIN error + return complex(math.Pi/2, 0) // DOMAIN error } - return cmplx(math.Asin(real(x)), 0) + return complex(math.Asin(real(x)), 0) } - ct := cmplx(-imag(x), real(x)) // i * x + ct := complex(-imag(x), real(x)) // i * x xx := x * x - x1 := cmplx(1-real(xx), -imag(xx)) // 1 - x*x - x2 := Sqrt(x1) // x2 = sqrt(1 - x*x) + x1 := complex(1-real(xx), -imag(xx)) // 1 - x*x + x2 := Sqrt(x1) // x2 = sqrt(1 - x*x) w := Log(ct + x2) - return cmplx(imag(w), -real(w)) // -i * w + return complex(imag(w), -real(w)) // -i * w } // Asinh returns the inverse hyperbolic sine of x. @@ -68,13 +68,13 @@ func Asinh(x complex128) complex128 { // TODO check range if imag(x) == 0 { if math.Fabs(real(x)) > 1 { - return cmplx(math.Pi/2, 0) // DOMAIN error + return complex(math.Pi/2, 0) // DOMAIN error } - return cmplx(math.Asinh(real(x)), 0) + return complex(math.Asinh(real(x)), 0) } xx := x * x - x1 := cmplx(1+real(xx), imag(xx)) // 1 + x*x - return Log(x + Sqrt(x1)) // log(x + sqrt(1 + x*x)) + x1 := complex(1+real(xx), imag(xx)) // 1 + x*x + return Log(x + Sqrt(x1)) // log(x + sqrt(1 + x*x)) } // Complex circular arc cosine @@ -93,16 +93,16 @@ func Asinh(x complex128) complex128 { // Acos returns the inverse cosine of x. func Acos(x complex128) complex128 { w := Asin(x) - return cmplx(math.Pi/2-real(w), -imag(w)) + return complex(math.Pi/2-real(w), -imag(w)) } // Acosh returns the inverse hyperbolic cosine of x. func Acosh(x complex128) complex128 { w := Acos(x) if imag(w) <= 0 { - return cmplx(-imag(w), real(w)) // i * w + return complex(-imag(w), real(w)) // i * w } - return cmplx(imag(w), -real(w)) // -i * w + return complex(imag(w), -real(w)) // -i * w } // Complex circular arc tangent @@ -159,12 +159,12 @@ func Atan(x complex128) complex128 { } t = imag(x) + 1 c := (x2 + t*t) / b - return cmplx(w, 0.25*math.Log(c)) + return complex(w, 0.25*math.Log(c)) } // Atanh returns the inverse hyperbolic tangent of x. func Atanh(x complex128) complex128 { - z := cmplx(-imag(x), real(x)) // z = i * x + z := complex(-imag(x), real(x)) // z = i * x z = Atan(z) - return cmplx(imag(z), -real(z)) // z = -i * z + return complex(imag(z), -real(z)) // z = -i * z } diff --git a/src/pkg/cmath/cmath_test.go b/src/pkg/cmath/cmath_test.go index bf1a9605df7..6a595b0a609 100644 --- a/src/pkg/cmath/cmath_test.go +++ b/src/pkg/cmath/cmath_test.go @@ -355,15 +355,15 @@ var expSC = []complex128{ NaN(), } var vcIsNaNSC = []complex128{ - cmplx(math.Inf(-1), math.Inf(-1)), - cmplx(math.Inf(-1), math.NaN()), - cmplx(math.NaN(), math.Inf(-1)), - cmplx(0, math.NaN()), - cmplx(math.NaN(), 0), - cmplx(math.Inf(1), math.Inf(1)), - cmplx(math.Inf(1), math.NaN()), - cmplx(math.NaN(), math.Inf(1)), - cmplx(math.NaN(), math.NaN()), + complex(math.Inf(-1), math.Inf(-1)), + complex(math.Inf(-1), math.NaN()), + complex(math.NaN(), math.Inf(-1)), + complex(0, math.NaN()), + complex(math.NaN(), 0), + complex(math.Inf(1), math.Inf(1)), + complex(math.Inf(1), math.NaN()), + complex(math.NaN(), math.Inf(1)), + complex(math.NaN(), math.NaN()), } var isNaNSC = []bool{ false, @@ -656,7 +656,7 @@ func TestPolar(t *testing.T) { } } func TestPow(t *testing.T) { - var a = cmplx(float64(3), float64(3)) + var a = complex(3.0, 3.0) for i := 0; i < len(vc); i++ { if f := Pow(a, vc[i]); !cSoclose(pow[i], f, 4e-15) { t.Errorf("Pow(%g, %g) = %g, want %g", a, vc[i], f, pow[i]) @@ -743,82 +743,82 @@ func TestTanh(t *testing.T) { func BenchmarkAbs(b *testing.B) { for i := 0; i < b.N; i++ { - Abs(cmplx(2.5, 3.5)) + Abs(complex(2.5, 3.5)) } } func BenchmarkAcos(b *testing.B) { for i := 0; i < b.N; i++ { - Acos(cmplx(2.5, 3.5)) + Acos(complex(2.5, 3.5)) } } func BenchmarkAcosh(b *testing.B) { for i := 0; i < b.N; i++ { - Acosh(cmplx(2.5, 3.5)) + Acosh(complex(2.5, 3.5)) } } func BenchmarkAsin(b *testing.B) { for i := 0; i < b.N; i++ { - Asin(cmplx(2.5, 3.5)) + Asin(complex(2.5, 3.5)) } } func BenchmarkAsinh(b *testing.B) { for i := 0; i < b.N; i++ { - Asinh(cmplx(2.5, 3.5)) + Asinh(complex(2.5, 3.5)) } } func BenchmarkAtan(b *testing.B) { for i := 0; i < b.N; i++ { - Atan(cmplx(2.5, 3.5)) + Atan(complex(2.5, 3.5)) } } func BenchmarkAtanh(b *testing.B) { for i := 0; i < b.N; i++ { - Atanh(cmplx(2.5, 3.5)) + Atanh(complex(2.5, 3.5)) } } func BenchmarkConj(b *testing.B) { for i := 0; i < b.N; i++ { - Conj(cmplx(2.5, 3.5)) + Conj(complex(2.5, 3.5)) } } func BenchmarkCos(b *testing.B) { for i := 0; i < b.N; i++ { - Cos(cmplx(2.5, 3.5)) + Cos(complex(2.5, 3.5)) } } func BenchmarkCosh(b *testing.B) { for i := 0; i < b.N; i++ { - Cosh(cmplx(2.5, 3.5)) + Cosh(complex(2.5, 3.5)) } } func BenchmarkExp(b *testing.B) { for i := 0; i < b.N; i++ { - Exp(cmplx(2.5, 3.5)) + Exp(complex(2.5, 3.5)) } } func BenchmarkLog(b *testing.B) { for i := 0; i < b.N; i++ { - Log(cmplx(2.5, 3.5)) + Log(complex(2.5, 3.5)) } } func BenchmarkLog10(b *testing.B) { for i := 0; i < b.N; i++ { - Log10(cmplx(2.5, 3.5)) + Log10(complex(2.5, 3.5)) } } func BenchmarkPhase(b *testing.B) { for i := 0; i < b.N; i++ { - Phase(cmplx(2.5, 3.5)) + Phase(complex(2.5, 3.5)) } } func BenchmarkPolar(b *testing.B) { for i := 0; i < b.N; i++ { - Polar(cmplx(2.5, 3.5)) + Polar(complex(2.5, 3.5)) } } func BenchmarkPow(b *testing.B) { for i := 0; i < b.N; i++ { - Pow(cmplx(2.5, 3.5), cmplx(2.5, 3.5)) + Pow(complex(2.5, 3.5), complex(2.5, 3.5)) } } func BenchmarkRect(b *testing.B) { @@ -828,26 +828,26 @@ func BenchmarkRect(b *testing.B) { } func BenchmarkSin(b *testing.B) { for i := 0; i < b.N; i++ { - Sin(cmplx(2.5, 3.5)) + Sin(complex(2.5, 3.5)) } } func BenchmarkSinh(b *testing.B) { for i := 0; i < b.N; i++ { - Sinh(cmplx(2.5, 3.5)) + Sinh(complex(2.5, 3.5)) } } func BenchmarkSqrt(b *testing.B) { for i := 0; i < b.N; i++ { - Sqrt(cmplx(2.5, 3.5)) + Sqrt(complex(2.5, 3.5)) } } func BenchmarkTan(b *testing.B) { for i := 0; i < b.N; i++ { - Tan(cmplx(2.5, 3.5)) + Tan(complex(2.5, 3.5)) } } func BenchmarkTanh(b *testing.B) { for i := 0; i < b.N; i++ { - Tanh(cmplx(2.5, 3.5)) + Tanh(complex(2.5, 3.5)) } } diff --git a/src/pkg/cmath/conj.go b/src/pkg/cmath/conj.go index 7a19e863111..776b57da7b7 100644 --- a/src/pkg/cmath/conj.go +++ b/src/pkg/cmath/conj.go @@ -5,4 +5,4 @@ package cmath // Conj returns the complex conjugate of x. -func Conj(x complex128) complex128 { return cmplx(real(x), -imag(x)) } +func Conj(x complex128) complex128 { return complex(real(x), -imag(x)) } diff --git a/src/pkg/cmath/exp.go b/src/pkg/cmath/exp.go index 1a639c5969e..64c1ef40939 100644 --- a/src/pkg/cmath/exp.go +++ b/src/pkg/cmath/exp.go @@ -51,5 +51,5 @@ import "math" func Exp(x complex128) complex128 { r := math.Exp(real(x)) s, c := math.Sincos(imag(x)) - return cmplx(r*c, r*s) + return complex(r*c, r*s) } diff --git a/src/pkg/cmath/isinf.go b/src/pkg/cmath/isinf.go index f17a752ecb0..f23d2dea787 100644 --- a/src/pkg/cmath/isinf.go +++ b/src/pkg/cmath/isinf.go @@ -14,8 +14,8 @@ func IsInf(x complex128) bool { return false } -// Inf returns a complex infinity, cmplx(+Inf, +Inf). +// Inf returns a complex infinity, complex(+Inf, +Inf). func Inf() complex128 { inf := math.Inf(1) - return cmplx(inf, inf) + return complex(inf, inf) } diff --git a/src/pkg/cmath/isnan.go b/src/pkg/cmath/isnan.go index 8e971dbd3c4..2063bb83566 100644 --- a/src/pkg/cmath/isnan.go +++ b/src/pkg/cmath/isnan.go @@ -21,5 +21,5 @@ func IsNaN(x complex128) bool { // NaN returns a complex ``not-a-number'' value. func NaN() complex128 { nan := math.NaN() - return cmplx(nan, nan) + return complex(nan, nan) } diff --git a/src/pkg/cmath/log.go b/src/pkg/cmath/log.go index b42062b2ab9..8e6964fee89 100644 --- a/src/pkg/cmath/log.go +++ b/src/pkg/cmath/log.go @@ -55,7 +55,7 @@ import "math" // Log returns the natural logarithm of x. func Log(x complex128) complex128 { - return cmplx(math.Log(Abs(x)), Phase(x)) + return complex(math.Log(Abs(x)), Phase(x)) } // Log10 returns the decimal logarithm of x. diff --git a/src/pkg/cmath/pow.go b/src/pkg/cmath/pow.go index de2c4db56ea..68e1207c674 100644 --- a/src/pkg/cmath/pow.go +++ b/src/pkg/cmath/pow.go @@ -46,7 +46,7 @@ import "math" func Pow(x, y complex128) complex128 { modulus := Abs(x) if modulus == 0 { - return cmplx(0, 0) + return complex(0, 0) } r := math.Pow(modulus, real(y)) arg := Phase(x) @@ -56,5 +56,5 @@ func Pow(x, y complex128) complex128 { theta += imag(y) * math.Log(modulus) } s, c := math.Sincos(theta) - return cmplx(r*c, r*s) + return complex(r*c, r*s) } diff --git a/src/pkg/cmath/rect.go b/src/pkg/cmath/rect.go index 1a88d867925..b955f0bf7d5 100644 --- a/src/pkg/cmath/rect.go +++ b/src/pkg/cmath/rect.go @@ -9,5 +9,5 @@ import "math" // Rect returns the complex number x with polar coordinates r, θ. func Rect(r, θ float64) complex128 { s, c := math.Sincos(θ) - return cmplx(r*c, r*s) + return complex(r*c, r*s) } diff --git a/src/pkg/cmath/sin.go b/src/pkg/cmath/sin.go index 1b79da493d9..8900ecddea3 100644 --- a/src/pkg/cmath/sin.go +++ b/src/pkg/cmath/sin.go @@ -53,7 +53,7 @@ import "math" func Sin(x complex128) complex128 { s, c := math.Sincos(real(x)) sh, ch := sinhcosh(imag(x)) - return cmplx(s*ch, c*sh) + return complex(s*ch, c*sh) } // Complex hyperbolic sine @@ -73,7 +73,7 @@ func Sin(x complex128) complex128 { func Sinh(x complex128) complex128 { s, c := math.Sincos(imag(x)) sh, ch := sinhcosh(real(x)) - return cmplx(c*sh, s*ch) + return complex(c*sh, s*ch) } // Complex circular cosine @@ -98,7 +98,7 @@ func Sinh(x complex128) complex128 { func Cos(x complex128) complex128 { s, c := math.Sincos(real(x)) sh, ch := sinhcosh(imag(x)) - return cmplx(c*ch, -s*sh) + return complex(c*ch, -s*sh) } // Complex hyperbolic cosine @@ -117,7 +117,7 @@ func Cos(x complex128) complex128 { func Cosh(x complex128) complex128 { s, c := math.Sincos(imag(x)) sh, ch := sinhcosh(real(x)) - return cmplx(c*ch, s*sh) + return complex(c*ch, s*sh) } // calculate sinh and cosh diff --git a/src/pkg/cmath/sqrt.go b/src/pkg/cmath/sqrt.go index 58bc4b691d0..e77a9b9df21 100644 --- a/src/pkg/cmath/sqrt.go +++ b/src/pkg/cmath/sqrt.go @@ -57,20 +57,20 @@ import "math" func Sqrt(x complex128) complex128 { if imag(x) == 0 { if real(x) == 0 { - return cmplx(0, 0) + return complex(0, 0) } if real(x) < 0 { - return cmplx(0, math.Sqrt(-real(x))) + return complex(0, math.Sqrt(-real(x))) } - return cmplx(math.Sqrt(real(x)), 0) + return complex(math.Sqrt(real(x)), 0) } if real(x) == 0 { if imag(x) < 0 { r := math.Sqrt(-0.5 * imag(x)) - return cmplx(r, -r) + return complex(r, -r) } r := math.Sqrt(0.5 * imag(x)) - return cmplx(r, r) + return complex(r, r) } a := real(x) b := imag(x) @@ -97,7 +97,7 @@ func Sqrt(x complex128) complex128 { r *= scale } if b < 0 { - return cmplx(t, -r) + return complex(t, -r) } - return cmplx(t, r) + return complex(t, r) } diff --git a/src/pkg/cmath/tan.go b/src/pkg/cmath/tan.go index d1945cd7900..94b517521ec 100644 --- a/src/pkg/cmath/tan.go +++ b/src/pkg/cmath/tan.go @@ -64,7 +64,7 @@ func Tan(x complex128) complex128 { if d == 0 { return Inf() } - return cmplx(math.Sin(2*real(x))/d, math.Sinh(2*imag(x))/d) + return complex(math.Sin(2*real(x))/d, math.Sinh(2*imag(x))/d) } // Complex hyperbolic tangent @@ -85,7 +85,7 @@ func Tanh(x complex128) complex128 { if d == 0 { return Inf() } - return cmplx(math.Sinh(2*real(x))/d, math.Sin(2*imag(x))/d) + return complex(math.Sinh(2*real(x))/d, math.Sin(2*imag(x))/d) } // Program to subtract nearest integer multiple of PI @@ -114,11 +114,11 @@ func tanSeries(z complex128) float64 { x = reducePi(x) x = x * x y = y * y - x2 := float64(1) - y2 := float64(1) - f := float64(1) - rn := float64(0) - d := float64(0) + x2 := 1.0 + y2 := 1.0 + f := 1.0 + rn := 0.0 + d := 0.0 for { rn += 1 f *= rn @@ -180,5 +180,5 @@ func Cot(x complex128) complex128 { if d == 0 { return Inf() } - return cmplx(math.Sin(2*real(x))/d, -math.Sinh(2*imag(x))/d) + return complex(math.Sin(2*real(x))/d, -math.Sinh(2*imag(x))/d) } diff --git a/src/pkg/container/vector/numbers_test.go b/src/pkg/container/vector/numbers_test.go index 93335ca60f2..d540ace0502 100644 --- a/src/pkg/container/vector/numbers_test.go +++ b/src/pkg/container/vector/numbers_test.go @@ -46,7 +46,7 @@ func TestVectorNums(t *testing.T) { v.Resize(0, 0) runtime.GC() n := m.Alloc - m0.Alloc - t.Logf("%T.Push(%#v), n = %s: Alloc/n = %.2f\n", v, c, s(memTestN), float(n)/memTestN) + t.Logf("%T.Push(%#v), n = %s: Alloc/n = %.2f\n", v, c, s(memTestN), float64(n)/memTestN) } @@ -64,7 +64,7 @@ func TestIntVectorNums(t *testing.T) { v.Resize(0, 0) runtime.GC() n := m.Alloc - m0.Alloc - t.Logf("%T.Push(%#v), n = %s: Alloc/n = %.2f\n", v, c, s(memTestN), float(n)/memTestN) + t.Logf("%T.Push(%#v), n = %s: Alloc/n = %.2f\n", v, c, s(memTestN), float64(n)/memTestN) } @@ -82,7 +82,7 @@ func TestStringVectorNums(t *testing.T) { v.Resize(0, 0) runtime.GC() n := m.Alloc - m0.Alloc - t.Logf("%T.Push(%#v), n = %s: Alloc/n = %.2f\n", v, c, s(memTestN), float(n)/memTestN) + t.Logf("%T.Push(%#v), n = %s: Alloc/n = %.2f\n", v, c, s(memTestN), float64(n)/memTestN) } diff --git a/src/pkg/encoding/binary/binary.go b/src/pkg/encoding/binary/binary.go index 6bbe7eb8959..77ff3a9f3ef 100644 --- a/src/pkg/encoding/binary/binary.go +++ b/src/pkg/encoding/binary/binary.go @@ -199,7 +199,7 @@ func sizeof(v reflect.Type) int { case *reflect.UintType, *reflect.IntType, *reflect.FloatType, *reflect.ComplexType: switch t := t.Kind(); t { - case reflect.Int, reflect.Uint, reflect.Uintptr, reflect.Float, reflect.Complex: + case reflect.Int, reflect.Uint, reflect.Uintptr: return -1 } return int(v.Size()) @@ -331,12 +331,12 @@ func (d *decoder) value(v reflect.Value) { case *reflect.ComplexValue: switch v.Type().Kind() { case reflect.Complex64: - v.Set(cmplx( + v.Set(complex( float64(math.Float32frombits(d.uint32())), float64(math.Float32frombits(d.uint32())), )) case reflect.Complex128: - v.Set(cmplx( + v.Set(complex( math.Float64frombits(d.uint64()), math.Float64frombits(d.uint64()), )) diff --git a/src/pkg/encoding/binary/binary_test.go b/src/pkg/encoding/binary/binary_test.go index c378413f102..e09ec489fd4 100644 --- a/src/pkg/encoding/binary/binary_test.go +++ b/src/pkg/encoding/binary/binary_test.go @@ -31,8 +31,6 @@ type Struct struct { type T struct { Int int Uint uint - Float float - Complex complex Uintptr uintptr Array [4]int } @@ -49,11 +47,11 @@ var s = Struct{ math.Float32frombits(0x1f202122), math.Float64frombits(0x232425262728292a), - cmplx( + complex( math.Float32frombits(0x2b2c2d2e), math.Float32frombits(0x2f303132), ), - cmplx( + complex( math.Float64frombits(0x333435363738393a), math.Float64frombits(0x3b3c3d3e3f404142), ), diff --git a/src/pkg/exp/datafmt/datafmt_test.go b/src/pkg/exp/datafmt/datafmt_test.go index f6a09f820c8..d7c70b21dec 100644 --- a/src/pkg/exp/datafmt/datafmt_test.go +++ b/src/pkg/exp/datafmt/datafmt_test.go @@ -80,10 +80,10 @@ func TestCustomFormatters(t *testing.T) { f = parse(t, ``, fmap1) verify(t, f, `even odd even odd `, 0, 1, 2, 3) - f = parse(t, `/ =@:blank; float="#"`, fmap1) + f = parse(t, `/ =@:blank; float64="#"`, fmap1) verify(t, f, `# # #`, 0.0, 1.0, 2.0) - f = parse(t, `float=@:nil`, fmap1) + f = parse(t, `float64=@:nil`, fmap1) verify(t, f, ``, 0.0, 1.0, 2.0) f = parse(t, `testing "testing"; ptr=*`, fmap2) @@ -139,7 +139,7 @@ func TestBasicTypes(t *testing.T) { const f = 3.141592 const fs = `3.141592` - check(t, `float ="%g"`, fs, f) + check(t, `float64="%g"`, fs, f) check(t, `float32="%g"`, fs, float32(f)) check(t, `float64="%g"`, fs, float64(f)) } diff --git a/src/pkg/exp/eval/Makefile b/src/pkg/exp/eval/Makefile index 2b716b14c47..872316cadc0 100644 --- a/src/pkg/exp/eval/Makefile +++ b/src/pkg/exp/eval/Makefile @@ -30,7 +30,7 @@ eval: main.$O gen.$O: gen.go $(GC) $< -generate: gen.$O $(pkgdir)/$(TARG).a +generate: gen.$O $(LD) -o $@ $<;\ ./generate > expr1.go;\ gofmt -w expr1.go diff --git a/src/pkg/exp/eval/bridge.go b/src/pkg/exp/eval/bridge.go index 3fa498d6882..12835c4c028 100644 --- a/src/pkg/exp/eval/bridge.go +++ b/src/pkg/exp/eval/bridge.go @@ -43,8 +43,6 @@ func TypeFromNative(t reflect.Type) Type { et = Float32Type case reflect.Float64: et = Float64Type - case reflect.Float: - et = FloatType } case *reflect.IntType: switch t.Kind() { diff --git a/src/pkg/exp/eval/eval_test.go b/src/pkg/exp/eval/eval_test.go index 6bfe9089db8..ff28cf1a908 100644 --- a/src/pkg/exp/eval/eval_test.go +++ b/src/pkg/exp/eval/eval_test.go @@ -173,8 +173,8 @@ func toValue(val interface{}) Value { return &r case *big.Int: return &idealIntV{val} - case float: - r := floatV(val) + case float64: + r := float64V(val) return &r case *big.Rat: return &idealFloatV{val} @@ -244,7 +244,7 @@ func newTestWorld() *World { def("i", IntType, 1) def("i2", IntType, 2) def("u", UintType, uint(1)) - def("f", FloatType, 1.0) + def("f", Float64Type, 1.0) def("s", StringType, "abc") def("t", NewStructType([]StructField{{"a", IntType, false}}), vstruct{1}) def("ai", NewArrayType(2, IntType), varray{1, 2}) diff --git a/src/pkg/exp/eval/expr.go b/src/pkg/exp/eval/expr.go index 70f63cf2d9b..e65f47617bd 100644 --- a/src/pkg/exp/eval/expr.go +++ b/src/pkg/exp/eval/expr.go @@ -1981,7 +1981,7 @@ func (a *expr) extractEffect(b *block, errOp string) (func(*Thread), *expr) { case tempType.isInteger(): tempType = IntType case tempType.isFloat(): - tempType = FloatType + tempType = Float64Type default: log.Panicf("unexpected ideal type %v", tempType) } diff --git a/src/pkg/exp/eval/expr1.go b/src/pkg/exp/eval/expr1.go index ae0cfc72374..5d0e5000032 100755 --- a/src/pkg/exp/eval/expr1.go +++ b/src/pkg/exp/eval/expr1.go @@ -9,8 +9,8 @@ import ( ) /* -* "As" functions. These retrieve evaluator functions from an -* expr, panicking if the requested evaluator has the wrong type. + * "As" functions. These retrieve evaluator functions from an + * expr, panicking if the requested evaluator has the wrong type. */ func (a *expr) asBool() func(*Thread) bool { return a.eval.(func(*Thread) bool) @@ -90,7 +90,7 @@ func (a *expr) asInterface() func(*Thread) interface{} { } /* -* Operator generators. + * Operator generators. */ func (a *expr) genConstant(v Value) { @@ -392,13 +392,6 @@ func (a *expr) genBinOpAdd(l, r *expr) { ret = l + r return float64(float64(ret)) } - case 0: - a.eval = func(t *Thread) float64 { - l, r := lf(t), rf(t) - var ret float64 - ret = l + r - return float64(float(ret)) - } default: log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos) } @@ -528,13 +521,6 @@ func (a *expr) genBinOpSub(l, r *expr) { ret = l - r return float64(float64(ret)) } - case 0: - a.eval = func(t *Thread) float64 { - l, r := lf(t), rf(t) - var ret float64 - ret = l - r - return float64(float(ret)) - } default: log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos) } @@ -657,13 +643,6 @@ func (a *expr) genBinOpMul(l, r *expr) { ret = l * r return float64(float64(ret)) } - case 0: - a.eval = func(t *Thread) float64 { - l, r := lf(t), rf(t) - var ret float64 - ret = l * r - return float64(float(ret)) - } default: log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos) } @@ -822,16 +801,6 @@ func (a *expr) genBinOpQuo(l, r *expr) { ret = l / r return float64(float64(ret)) } - case 0: - a.eval = func(t *Thread) float64 { - l, r := lf(t), rf(t) - var ret float64 - if r == 0 { - t.Abort(DivByZeroError{}) - } - ret = l / r - return float64(float(ret)) - } default: log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos) } diff --git a/src/pkg/exp/eval/gen.go b/src/pkg/exp/eval/gen.go index 81863dd6fe6..a2b11984658 100644 --- a/src/pkg/exp/eval/gen.go +++ b/src/pkg/exp/eval/gen.go @@ -47,7 +47,7 @@ var ( } idealIntType = &Type{Repr: "*idealIntType", Value: "IdealIntValue", Native: "*big.Int", As: "asIdealInt", IsIdeal: true} floatType = &Type{Repr: "*floatType", Value: "FloatValue", Native: "float64", As: "asFloat", - Sizes: []Size{{32, "float32"}, {64, "float64"}, {0, "float"}}, + Sizes: []Size{{32, "float32"}, {64, "float64"}}, } idealFloatType = &Type{Repr: "*idealFloatType", Value: "IdealFloatValue", Native: "*big.Rat", As: "asIdealFloat", IsIdeal: true} stringType = &Type{Repr: "*stringType", Value: "StringValue", Native: "string", As: "asString"} diff --git a/src/pkg/exp/eval/stmt.go b/src/pkg/exp/eval/stmt.go index b9ffa94fa24..77ff066d09c 100644 --- a/src/pkg/exp/eval/stmt.go +++ b/src/pkg/exp/eval/stmt.go @@ -602,7 +602,7 @@ func (a *stmtCompiler) doAssign(lhs []ast.Expr, rhs []ast.Expr, tok token.Token, case ac.rmt.Elems[i].isInteger(): lt = IntType case ac.rmt.Elems[i].isFloat(): - lt = FloatType + lt = Float64Type default: log.Panicf("unexpected ideal type %v", rs[i].t) } diff --git a/src/pkg/exp/eval/type.go b/src/pkg/exp/eval/type.go index db77ab198de..3f272ce4b6c 100644 --- a/src/pkg/exp/eval/type.go +++ b/src/pkg/exp/eval/type.go @@ -372,7 +372,6 @@ type floatType struct { var ( Float32Type = universe.DefineType("float32", universePos, &floatType{commonType{}, 32, "float32"}) Float64Type = universe.DefineType("float64", universePos, &floatType{commonType{}, 64, "float64"}) - FloatType = universe.DefineType("float", universePos, &floatType{commonType{}, 0, "float"}) ) func (t *floatType) compat(o Type, conv bool) bool { @@ -394,9 +393,6 @@ func (t *floatType) Zero() Value { case 64: res := float64V(0) return &res - case 0: - res := floatV(0) - return &res } panic("unexpected float bit count") } @@ -408,9 +404,6 @@ var minFloat64Val *big.Rat func (t *floatType) minVal() *big.Rat { bits := t.Bits - if bits == 0 { - bits = uint(8 * unsafe.Sizeof(float(0))) - } switch bits { case 32: return minFloat32Val @@ -423,9 +416,6 @@ func (t *floatType) minVal() *big.Rat { func (t *floatType) maxVal() *big.Rat { bits := t.Bits - if bits == 0 { - bits = uint(8 * unsafe.Sizeof(float(0))) - } switch bits { case 32: return maxFloat32Val diff --git a/src/pkg/exp/eval/value.go b/src/pkg/exp/eval/value.go index cace2fd37b7..daa69189792 100644 --- a/src/pkg/exp/eval/value.go +++ b/src/pkg/exp/eval/value.go @@ -307,16 +307,6 @@ func (v *float64V) Get(*Thread) float64 { return float64(*v) } func (v *float64V) Set(t *Thread, x float64) { *v = float64V(x) } -type floatV float - -func (v *floatV) String() string { return fmt.Sprint(*v) } - -func (v *floatV) Assign(t *Thread, o Value) { *v = floatV(o.(FloatValue).Get(t)) } - -func (v *floatV) Get(*Thread) float64 { return float64(*v) } - -func (v *floatV) Set(t *Thread, x float64) { *v = floatV(x) } - /* * Ideal float */ diff --git a/src/pkg/exp/ogle/rtype.go b/src/pkg/exp/ogle/rtype.go index fd77f1bc248..b3c35575af4 100644 --- a/src/pkg/exp/ogle/rtype.go +++ b/src/pkg/exp/ogle/rtype.go @@ -209,9 +209,6 @@ func parseRemoteType(a aborter, rs remoteStruct) *remoteType { case p.runtime.PFloat64Type: t = eval.Float64Type mk = mkFloat64 - case p.runtime.PFloatType: - t = eval.FloatType - mk = mkFloat case p.runtime.PStringType: t = eval.StringType mk = mkString diff --git a/src/pkg/expvar/expvar_test.go b/src/pkg/expvar/expvar_test.go index 2659434438b..a8b1a96a93c 100644 --- a/src/pkg/expvar/expvar_test.go +++ b/src/pkg/expvar/expvar_test.go @@ -128,7 +128,7 @@ func TestIntFunc(t *testing.T) { } func TestFloatFunc(t *testing.T) { - x := float64(8.5) + x := 8.5 ix := FloatFunc(func() float64 { return x }) if s := ix.String(); s != "8.5" { t.Errorf("ix.String() = %v, want 3.14", s) diff --git a/src/pkg/flag/flag.go b/src/pkg/flag/flag.go index 04fe2fa05b6..143a1061150 100644 --- a/src/pkg/flag/flag.go +++ b/src/pkg/flag/flag.go @@ -166,22 +166,6 @@ func (s *stringValue) Set(val string) bool { func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) } -// -- Float Value -type floatValue float - -func newFloatValue(val float, p *float) *floatValue { - *p = val - return (*floatValue)(p) -} - -func (f *floatValue) Set(s string) bool { - v, err := strconv.Atof(s) - *f = floatValue(v) - return err == nil -} - -func (f *floatValue) String() string { return fmt.Sprintf("%v", *f) } - // -- Float64 Value type float64Value float64 @@ -385,20 +369,6 @@ func String(name, value string, usage string) *string { return p } -// FloatVar defines a float flag with specified name, default value, and usage string. -// The argument p points to a float variable in which to store the value of the flag. -func FloatVar(p *float, name string, value float, usage string) { - Var(newFloatValue(value, p), name, usage) -} - -// Float defines a float flag with specified name, default value, and usage string. -// The return value is the address of a float variable that stores the value of the flag. -func Float(name string, value float, usage string) *float { - p := new(float) - FloatVar(p, name, value, usage) - return p -} - // Float64Var defines a float64 flag with specified name, default value, and usage string. // The argument p points to a float64 variable in which to store the value of the flag. func Float64Var(p *float64, name string, value float64, usage string) { diff --git a/src/pkg/flag/flag_test.go b/src/pkg/flag/flag_test.go index 4ebb7380582..b91a8b56795 100644 --- a/src/pkg/flag/flag_test.go +++ b/src/pkg/flag/flag_test.go @@ -18,8 +18,7 @@ var ( test_uint = Uint("test_uint", 0, "uint value") test_uint64 = Uint64("test_uint64", 0, "uint64 value") test_string = String("test_string", "0", "string value") - test_float = Float("test_float", 0, "float value") - test_float64 = Float("test_float64", 0, "float64 value") + test_float64 = Float64("test_float64", 0, "float64 value") ) func boolString(s string) string { @@ -48,7 +47,7 @@ func TestEverything(t *testing.T) { } } VisitAll(visitor) - if len(m) != 8 { + if len(m) != 7 { t.Error("VisitAll misses some flags") for k, v := range m { t.Log(k, *v) @@ -69,11 +68,10 @@ func TestEverything(t *testing.T) { Set("test_uint", "1") Set("test_uint64", "1") Set("test_string", "1") - Set("test_float", "1") Set("test_float64", "1") desired = "1" Visit(visitor) - if len(m) != 8 { + if len(m) != 7 { t.Error("Visit fails after set") for k, v := range m { t.Log(k, *v) @@ -101,8 +99,7 @@ func TestParse(t *testing.T) { uintFlag := Uint("uint", 0, "uint value") uint64Flag := Uint64("uint64", 0, "uint64 value") stringFlag := String("string", "0", "string value") - floatFlag := Float("float", 0, "float value") - float64Flag := Float("float64", 0, "float64 value") + float64Flag := Float64("float64", 0, "float64 value") extra := "one-extra-argument" args := []string{ "a.out", @@ -113,7 +110,6 @@ func TestParse(t *testing.T) { "-uint", "24", "--uint64", "25", "-string", "hello", - "--float", "3141.5", "-float64", "2718e28", extra, } @@ -141,9 +137,6 @@ func TestParse(t *testing.T) { if *stringFlag != "hello" { t.Error("string flag should be `hello`, is ", *stringFlag) } - if *floatFlag != 3141.5 { - t.Error("float flag should be 3141.5, is ", *floatFlag) - } if *float64Flag != 2718e28 { t.Error("float64 flag should be 2718e28, is ", *float64Flag) } diff --git a/src/pkg/fmt/fmt_test.go b/src/pkg/fmt/fmt_test.go index 0aafe6d9942..3f085b72245 100644 --- a/src/pkg/fmt/fmt_test.go +++ b/src/pkg/fmt/fmt_test.go @@ -28,10 +28,8 @@ type ( renamedUintptr uintptr renamedString string renamedBytes []byte - renamedFloat float renamedFloat32 float32 renamedFloat64 float64 - renamedComplex complex renamedComplex64 complex64 renamedComplex128 complex128 ) @@ -224,31 +222,31 @@ var fmttests = []struct { {"%b", 7, "111"}, {"%b", b64, "1111111111111111111111111111111111111111111111111111111111111111"}, {"%b", -6, "-110"}, - {"%e", float64(1), "1.000000e+00"}, - {"%e", float64(1234.5678e3), "1.234568e+06"}, - {"%e", float64(1234.5678e-8), "1.234568e-05"}, - {"%e", float64(-7), "-7.000000e+00"}, - {"%e", float64(-1e-9), "-1.000000e-09"}, - {"%f", float64(1234.5678e3), "1234567.800000"}, - {"%f", float64(1234.5678e-8), "0.000012"}, - {"%f", float64(-7), "-7.000000"}, - {"%f", float64(-1e-9), "-0.000000"}, - {"%g", float64(1234.5678e3), "1.2345678e+06"}, + {"%e", 1.0, "1.000000e+00"}, + {"%e", 1234.5678e3, "1.234568e+06"}, + {"%e", 1234.5678e-8, "1.234568e-05"}, + {"%e", -7.0, "-7.000000e+00"}, + {"%e", -1e-9, "-1.000000e-09"}, + {"%f", 1234.5678e3, "1234567.800000"}, + {"%f", 1234.5678e-8, "0.000012"}, + {"%f", -7.0, "-7.000000"}, + {"%f", -1e-9, "-0.000000"}, + {"%g", 1234.5678e3, "1.2345678e+06"}, {"%g", float32(1234.5678e3), "1.2345678e+06"}, - {"%g", float64(1234.5678e-8), "1.2345678e-05"}, - {"%g", float64(-7), "-7"}, - {"%g", float64(-1e-9), "-1e-09"}, + {"%g", 1234.5678e-8, "1.2345678e-05"}, + {"%g", -7.0, "-7"}, + {"%g", -1e-9, "-1e-09"}, {"%g", float32(-1e-9), "-1e-09"}, - {"%E", float64(1), "1.000000E+00"}, - {"%E", float64(1234.5678e3), "1.234568E+06"}, - {"%E", float64(1234.5678e-8), "1.234568E-05"}, - {"%E", float64(-7), "-7.000000E+00"}, - {"%E", float64(-1e-9), "-1.000000E-09"}, - {"%G", float64(1234.5678e3), "1.2345678E+06"}, + {"%E", 1.0, "1.000000E+00"}, + {"%E", 1234.5678e3, "1.234568E+06"}, + {"%E", 1234.5678e-8, "1.234568E-05"}, + {"%E", -7.0, "-7.000000E+00"}, + {"%E", -1e-9, "-1.000000E-09"}, + {"%G", 1234.5678e3, "1.2345678E+06"}, {"%G", float32(1234.5678e3), "1.2345678E+06"}, - {"%G", float64(1234.5678e-8), "1.2345678E-05"}, - {"%G", float64(-7), "-7"}, - {"%G", float64(-1e-9), "-1E-09"}, + {"%G", 1234.5678e-8, "1.2345678E-05"}, + {"%G", -7.0, "-7"}, + {"%G", -1e-9, "-1E-09"}, {"%G", float32(-1e-9), "-1E-09"}, {"%c", 'x', "x"}, {"%c", 0xe4, "ä"}, @@ -273,15 +271,15 @@ var fmttests = []struct { {"%20e", 1.2345e3, " 1.234500e+03"}, {"%20e", 1.2345e-3, " 1.234500e-03"}, {"%20.8e", 1.2345e3, " 1.23450000e+03"}, - {"%20f", float64(1.23456789e3), " 1234.567890"}, - {"%20f", float64(1.23456789e-3), " 0.001235"}, - {"%20f", float64(12345678901.23456789), " 12345678901.234568"}, - {"%-20f", float64(1.23456789e3), "1234.567890 "}, - {"%20.8f", float64(1.23456789e3), " 1234.56789000"}, - {"%20.8f", float64(1.23456789e-3), " 0.00123457"}, - {"%g", float64(1.23456789e3), "1234.56789"}, - {"%g", float64(1.23456789e-3), "0.00123456789"}, - {"%g", float64(1.23456789e20), "1.23456789e+20"}, + {"%20f", 1.23456789e3, " 1234.567890"}, + {"%20f", 1.23456789e-3, " 0.001235"}, + {"%20f", 12345678901.23456789, " 12345678901.234568"}, + {"%-20f", 1.23456789e3, "1234.567890 "}, + {"%20.8f", 1.23456789e3, " 1234.56789000"}, + {"%20.8f", 1.23456789e-3, " 0.00123457"}, + {"%g", 1.23456789e3, "1234.56789"}, + {"%g", 1.23456789e-3, "0.00123456789"}, + {"%g", 1.23456789e20, "1.23456789e+20"}, {"%20e", math.Inf(1), " +Inf"}, {"%-20f", math.Inf(-1), "-Inf "}, {"%20g", math.NaN(), " NaN"}, @@ -346,10 +344,8 @@ var fmttests = []struct { {"%x", renamedString("thing"), "7468696e67"}, {"%d", renamedBytes([]byte{1, 2, 15}), `[1 2 15]`}, {"%q", renamedBytes([]byte("hello")), `"hello"`}, - {"%v", renamedFloat(11), "11"}, {"%v", renamedFloat32(22), "22"}, {"%v", renamedFloat64(33), "33"}, - {"%v", renamedComplex(7 + .2i), "(7+0.2i)"}, {"%v", renamedComplex64(3 + 4i), "(3+4i)"}, {"%v", renamedComplex128(4 - 3i), "(4-3i)"}, @@ -363,7 +359,7 @@ var fmttests = []struct { {"%#v", S{F(7), G(8)}, "fmt_test.S{f:, g:GoString(8)}"}, // %T - {"%T", (4 - 3i), "complex"}, + {"%T", (4 - 3i), "complex128"}, {"%T", renamedComplex128(4 - 3i), "fmt_test.renamedComplex128"}, {"%T", intVal, "int"}, {"%6T", &intVal, " *int"}, diff --git a/src/pkg/fmt/format.go b/src/pkg/fmt/format.go index 0121dda31dc..86057bf693c 100644 --- a/src/pkg/fmt/format.go +++ b/src/pkg/fmt/format.go @@ -396,36 +396,3 @@ func (f *fmt) fmt_c128(v complex128, verb int) { } f.buf.Write(irparenBytes) } - -// float -func (x *fmt) f(a float) { - if strconv.FloatSize == 32 { - x.fmt_f32(float32(a)) - } else { - x.fmt_f64(float64(a)) - } -} - -func (x *fmt) e(a float) { - if strconv.FloatSize == 32 { - x.fmt_e32(float32(a)) - } else { - x.fmt_e64(float64(a)) - } -} - -func (x *fmt) g(a float) { - if strconv.FloatSize == 32 { - x.fmt_g32(float32(a)) - } else { - x.fmt_g64(float64(a)) - } -} - -func (x *fmt) fb(a float) { - if strconv.FloatSize == 32 { - x.fmt_fb32(float32(a)) - } else { - x.fmt_fb64(float64(a)) - } -} diff --git a/src/pkg/fmt/print.go b/src/pkg/fmt/print.go index 412260441fb..96029a8789f 100644 --- a/src/pkg/fmt/print.go +++ b/src/pkg/fmt/print.go @@ -573,26 +573,12 @@ func (p *pp) printField(field interface{}, verb int, plus, goSyntax bool, depth case bool: p.fmtBool(f, verb, field) return false - case float: - if floatBits == 32 { - p.fmtFloat32(float32(f), verb, field) - } else { - p.fmtFloat64(float64(f), verb, field) - } - return false case float32: p.fmtFloat32(f, verb, field) return false case float64: p.fmtFloat64(f, verb, field) return false - case complex: - if complexBits == 64 { - p.fmtComplex64(complex64(f), verb, field) - } else { - p.fmtComplex128(complex128(f), verb, field) - } - return false case complex64: p.fmtComplex64(complex64(f), verb, field) return false diff --git a/src/pkg/fmt/scan.go b/src/pkg/fmt/scan.go index dcc42bc92da..ebbb17155e4 100644 --- a/src/pkg/fmt/scan.go +++ b/src/pkg/fmt/scan.go @@ -640,7 +640,7 @@ func (s *ss) scanComplex(verb int, n int) complex128 { sreal, simag := s.complexTokens() real := s.convertFloat(sreal, n/2) imag := s.convertFloat(simag, n/2) - return cmplx(real, imag) + return complex(real, imag) } // convertString returns the string represented by the next input characters. @@ -772,8 +772,6 @@ func (s *ss) scanOne(verb int, field interface{}) { switch v := field.(type) { case *bool: *v = s.scanBool(verb) - case *complex: - *v = complex(s.scanComplex(verb, int(complexBits))) case *complex64: *v = complex64(s.scanComplex(verb, 64)) case *complex128: @@ -802,11 +800,6 @@ func (s *ss) scanOne(verb int, field interface{}) { *v = uintptr(s.scanUint(verb, uintptrBits)) // Floats are tricky because you want to scan in the precision of the result, not // scan in high precision and convert, in order to preserve the correct error condition. - case *float: - if s.okVerb(verb, floatVerbs, "float") { - s.skipSpace(false) - *v = float(s.convertFloat(s.floatToken(), int(floatBits))) - } case *float32: if s.okVerb(verb, floatVerbs, "float32") { s.skipSpace(false) diff --git a/src/pkg/fmt/scan_test.go b/src/pkg/fmt/scan_test.go index fe5ee1d6175..78b9fbb4ab0 100644 --- a/src/pkg/fmt/scan_test.go +++ b/src/pkg/fmt/scan_test.go @@ -50,13 +50,11 @@ var ( uint16Val uint16 uint32Val uint32 uint64Val uint64 - floatVal float float32Val float32 float64Val float64 stringVal string stringVal1 string bytesVal []byte - complexVal complex complex64Val complex64 complex128Val complex128 renamedBoolVal renamedBool @@ -73,10 +71,8 @@ var ( renamedUintptrVal renamedUintptr renamedStringVal renamedString renamedBytesVal renamedBytes - renamedFloatVal renamedFloat renamedFloat32Val renamedFloat32 renamedFloat64Val renamedFloat64 - renamedComplexVal renamedComplex renamedComplex64Val renamedComplex64 renamedComplex128Val renamedComplex128 ) @@ -161,12 +157,12 @@ var scanTests = []ScanTest{ {"30\n", &uint64Val, uint64(30)}, {"255\n", &uint8Val, uint8(255)}, {"32767\n", &int16Val, int16(32767)}, - {"2.3\n", &floatVal, 2.3}, + {"2.3\n", &float64Val, 2.3}, {"2.3e1\n", &float32Val, float32(2.3e1)}, - {"2.3e2\n", &float64Val, float64(2.3e2)}, + {"2.3e2\n", &float64Val, 2.3e2}, {"2.35\n", &stringVal, "2.35"}, {"2345678\n", &bytesVal, []byte("2345678")}, - {"(3.4e1-2i)\n", &complexVal, 3.4e1 - 2i}, + {"(3.4e1-2i)\n", &complex128Val, 3.4e1 - 2i}, {"-3.45e1-3i\n", &complex64Val, complex64(-3.45e1 - 3i)}, {"-.45e1-1e2i\n", &complex128Val, complex128(-.45e1 - 100i)}, {"hello\n", &stringVal, "hello"}, @@ -256,10 +252,8 @@ var scanfTests = []ScanfTest{ {"%d", "113\n", &renamedUintptrVal, renamedUintptr(113)}, {"%s", "114\n", &renamedStringVal, renamedString("114")}, {"%q", "\"1155\"\n", &renamedBytesVal, renamedBytes([]byte("1155"))}, - {"%g", "115.1\n", &renamedFloatVal, renamedFloat(115.1)}, {"%g", "116e1\n", &renamedFloat32Val, renamedFloat32(116e1)}, {"%g", "-11.7e+1", &renamedFloat64Val, renamedFloat64(-11.7e+1)}, - {"%g", "11+5.1i\n", &renamedComplexVal, renamedComplex(11 + 5.1i)}, {"%g", "11+6e1i\n", &renamedComplex64Val, renamedComplex64(11 + 6e1i)}, {"%g", "-11.+7e+1i", &renamedComplex128Val, renamedComplex128(-11. + 7e+1i)}, @@ -288,15 +282,15 @@ var overflowTests = []ScanTest{ {"65536", &uint16Val, 0}, {"1e100", &float32Val, 0}, {"1e500", &float64Val, 0}, - {"(1e100+0i)", &complexVal, 0}, + {"(1e100+0i)", &complex64Val, 0}, {"(1+1e100i)", &complex64Val, 0}, {"(1-1e500i)", &complex128Val, 0}, } var i, j, k int -var f float +var f float64 var s, t string -var c complex +var c complex128 var x, y Xs var multiTests = []ScanfMultiTest{ @@ -307,7 +301,7 @@ var multiTests = []ScanfMultiTest{ {"%2d.%3d", "66.777", args(&i, &j), args(66, 777), ""}, {"%d, %d", "23, 18", args(&i, &j), args(23, 18), ""}, {"%3d22%3d", "33322333", args(&i, &j), args(333, 333), ""}, - {"%6vX=%3fY", "3+2iX=2.5Y", args(&c, &f), args((3 + 2i), float(2.5)), ""}, + {"%6vX=%3fY", "3+2iX=2.5Y", args(&c, &f), args((3 + 2i), 2.5), ""}, {"%d%s", "123abc", args(&i, &s), args(123, "abc"), ""}, {"%c%c%c", "2\u50c2X", args(&i, &j, &k), args('2', '\u50c2', 'X'), ""}, @@ -409,7 +403,7 @@ func TestScanOverflow(t *testing.T) { } func verifyNaN(str string, t *testing.T) { - var f float + var f float64 var f32 float32 var f64 float64 text := str + " " + str + " " + str @@ -432,7 +426,7 @@ func TestNaN(t *testing.T) { } func verifyInf(str string, t *testing.T) { - var f float + var f float64 var f32 float32 var f64 float64 text := str + " " + str + " " + str diff --git a/src/pkg/fmt/stringer_test.go b/src/pkg/fmt/stringer_test.go index 815147e1ae6..0ca3f522d62 100644 --- a/src/pkg/fmt/stringer_test.go +++ b/src/pkg/fmt/stringer_test.go @@ -20,7 +20,7 @@ type TU16 uint16 type TU32 uint32 type TU64 uint64 type TUI uintptr -type TF float +type TF float64 type TF32 float32 type TF64 float64 type TB bool @@ -37,7 +37,7 @@ func (v TU16) String() string { return Sprintf("U16: %d", uint16(v)) } func (v TU32) String() string { return Sprintf("U32: %d", uint32(v)) } func (v TU64) String() string { return Sprintf("U64: %d", uint64(v)) } func (v TUI) String() string { return Sprintf("UI: %d", uintptr(v)) } -func (v TF) String() string { return Sprintf("F: %f", float(v)) } +func (v TF) String() string { return Sprintf("F: %f", float64(v)) } func (v TF32) String() string { return Sprintf("F32: %f", float32(v)) } func (v TF64) String() string { return Sprintf("F64: %f", float64(v)) } func (v TB) String() string { return Sprintf("B: %t", bool(v)) } diff --git a/src/pkg/go/doc/doc.go b/src/pkg/go/doc/doc.go index fb1c4e03d86..e46857cb8a1 100644 --- a/src/pkg/go/doc/doc.go +++ b/src/pkg/go/doc/doc.go @@ -154,7 +154,7 @@ func (doc *docReader) addValue(decl *ast.GenDecl) { // determine values list const threshold = 0.75 values := &doc.values - if domName != "" && domFreq >= int(float(len(decl.Specs))*threshold) { + if domName != "" && domFreq >= int(float64(len(decl.Specs))*threshold) { // typed entries are sufficiently frequent typ := doc.lookupTypeDoc(domName) if typ != nil { diff --git a/src/pkg/go/printer/nodes.go b/src/pkg/go/printer/nodes.go index 8aadc75a54c..8207996dcdc 100644 --- a/src/pkg/go/printer/nodes.go +++ b/src/pkg/go/printer/nodes.go @@ -228,7 +228,7 @@ func (p *printer) exprList(prev0 token.Pos, list []ast.Expr, depth int, mode exp useFF = false } else { const r = 4 // threshold - ratio := float(size) / float(prevSize) + ratio := float64(size) / float64(prevSize) useFF = ratio <= 1/r || r <= ratio } } diff --git a/src/pkg/gob/codec_test.go b/src/pkg/gob/codec_test.go index d150dbe9a9a..af941c629cd 100644 --- a/src/pkg/gob/codec_test.go +++ b/src/pkg/gob/codec_test.go @@ -254,18 +254,6 @@ func TestScalarEncInstructions(t *testing.T) { } } - // float - { - b.Reset() - data := struct{ a float }{17} - instr := &encInstr{encFloat, 6, 0, 0} - state := newencoderState(b) - instr.op(instr, state, unsafe.Pointer(&data)) - if !bytes.Equal(floatResult, b.Bytes()) { - t.Errorf("float enc instructions: expected % x got % x", floatResult, b.Bytes()) - } - } - // float32 { b.Reset() @@ -492,19 +480,6 @@ func TestScalarDecInstructions(t *testing.T) { } } - // float - { - var data struct { - a float - } - instr := &decInstr{decOpMap[reflect.Float], 6, 0, 0, ovfl} - state := newDecodeStateFromData(floatResult) - execDec("float", instr, state, t, unsafe.Pointer(&data)) - if data.a != 17 { - t.Errorf("float a = %v not 17", data.a) - } - } - // float32 { var data struct { @@ -531,19 +506,6 @@ func TestScalarDecInstructions(t *testing.T) { } } - // complex - { - var data struct { - a complex - } - instr := &decInstr{decOpMap[reflect.Complex], 6, 0, 0, ovfl} - state := newDecodeStateFromData(complexResult) - execDec("complex", instr, state, t, unsafe.Pointer(&data)) - if data.a != 17+19i { - t.Errorf("complex a = %v not 17+19i", data.a) - } - } - // complex64 { var data struct { @@ -605,8 +567,8 @@ func TestEndToEnd(t *testing.T) { s2 := "string2" type T1 struct { A, B, C int - M map[string]*float - N *[3]float + M map[string]*float64 + N *[3]float64 Strs *[2]string Int64s *[]int64 RI complex64 @@ -620,8 +582,8 @@ func TestEndToEnd(t *testing.T) { A: 17, B: 18, C: -5, - M: map[string]*float{"pi": &pi, "e": &e}, - N: &[3]float{1.5, 2.5, 3.5}, + M: map[string]*float64{"pi": &pi, "e": &e}, + N: &[3]float64{1.5, 2.5, 3.5}, Strs: &[2]string{s1, s2}, Int64s: &[]int64{77, 89, 123412342134}, RI: 17 - 23i, @@ -799,7 +761,7 @@ func TestOverflow(t *testing.T) { // complex64 b.Reset() it = inputT{ - Maxc: cmplx(math.MaxFloat32*2, math.MaxFloat32*2), + Maxc: complex(math.MaxFloat32*2, math.MaxFloat32*2), } type outc64 struct { Maxc complex64 @@ -940,10 +902,10 @@ func TestAutoIndirection(t *testing.T) { type RT0 struct { A int B string - C float + C float64 } type RT1 struct { - C float + C float64 B string A int NotSet string @@ -973,13 +935,13 @@ type IT0 struct { A int64 B string Ignore_d []int - Ignore_e [3]float + Ignore_e [3]float64 Ignore_f bool Ignore_g string Ignore_h []byte Ignore_i *RT1 Ignore_m map[string]int - C float + C float64 } func TestIgnoredFields(t *testing.T) { @@ -1013,7 +975,7 @@ func TestIgnoredFields(t *testing.T) { type Bad0 struct { ch chan int - c float + c float64 } var nilEncoder *Encoder @@ -1109,7 +1071,7 @@ func (i Int) Square() int { return int(i * i) } -type Float float +type Float float64 func (f Float) Square() int { return int(f * f) @@ -1137,14 +1099,14 @@ func (p Point) Square() int { type InterfaceItem struct { I int Sq1, Sq2, Sq3 Squarer - F float + F float64 Sq []Squarer } // The same struct without interfaces type NoInterfaceItem struct { I int - F float + F float64 } func TestInterface(t *testing.T) { @@ -1207,8 +1169,8 @@ func TestInterface(t *testing.T) { type BasicInterfaceItem struct { Int, Int8, Int16, Int32, Int64 interface{} Uint, Uint8, Uint16, Uint32, Uint64 interface{} - Float, Float32, Float64 interface{} - Complex, Complex64, Complex128 interface{} + Float32, Float64 interface{} + Complex64, Complex128 interface{} Bool interface{} String interface{} Bytes interface{} @@ -1219,8 +1181,8 @@ func TestInterfaceBasic(t *testing.T) { item1 := &BasicInterfaceItem{ int(1), int8(1), int16(1), int32(1), int64(1), uint(1), uint8(1), uint16(1), uint32(1), uint64(1), - float(1), float32(1), float64(1), - complex(0i), complex64(0i), complex128(0i), + float32(1), 1.0, + complex64(0i), complex128(0i), true, "hello", []byte("sailor"), @@ -1318,7 +1280,7 @@ func TestIgnoreInterface(t *testing.T) { type U struct { A int B string - c float + c float64 D uint } @@ -1354,7 +1316,7 @@ type DT struct { // X OnTheFly A int B string - C float + C float64 I interface{} J interface{} I_nil interface{} diff --git a/src/pkg/gob/decode.go b/src/pkg/gob/decode.go index f88ca72daab..2db75215c19 100644 --- a/src/pkg/gob/decode.go +++ b/src/pkg/gob/decode.go @@ -333,7 +333,7 @@ func decComplex64(i *decInstr, state *decodeState, p unsafe.Pointer) { p = *(*unsafe.Pointer)(p) } storeFloat32(i, state, p) - storeFloat32(i, state, unsafe.Pointer(uintptr(p)+uintptr(unsafe.Sizeof(float(0))))) + storeFloat32(i, state, unsafe.Pointer(uintptr(p)+uintptr(unsafe.Sizeof(float32(0))))) } func decComplex128(i *decInstr, state *decodeState, p unsafe.Pointer) { @@ -345,7 +345,7 @@ func decComplex128(i *decInstr, state *decodeState, p unsafe.Pointer) { } real := floatFromBits(uint64(state.decodeUint())) imag := floatFromBits(uint64(state.decodeUint())) - *(*complex128)(p) = cmplx(real, imag) + *(*complex128)(p) = complex(real, imag) } // uint8 arrays are encoded as an unsigned count followed by the raw bytes. @@ -993,20 +993,6 @@ func (dec *Decoder) decode(wireId typeId, val reflect.Value) os.Error { } func init() { - var fop, cop decOp - switch reflect.Typeof(float(0)).Bits() { - case 32: - fop = decFloat32 - cop = decComplex64 - case 64: - fop = decFloat64 - cop = decComplex128 - default: - panic("gob: unknown size of float") - } - decOpMap[reflect.Float] = fop - decOpMap[reflect.Complex] = cop - var iop, uop decOp switch reflect.Typeof(int(0)).Bits() { case 32: diff --git a/src/pkg/gob/encode.go b/src/pkg/gob/encode.go index 3431eafa7e9..d286a7e00b8 100644 --- a/src/pkg/gob/encode.go +++ b/src/pkg/gob/encode.go @@ -223,15 +223,6 @@ func floatBits(f float64) uint64 { return v } -func encFloat(i *encInstr, state *encoderState, p unsafe.Pointer) { - f := *(*float)(p) - if f != 0 || state.sendZero { - v := floatBits(float64(f)) - state.update(i) - state.encodeUint(v) - } -} - func encFloat32(i *encInstr, state *encoderState, p unsafe.Pointer) { f := *(*float32)(p) if f != 0 || state.sendZero { @@ -251,17 +242,6 @@ func encFloat64(i *encInstr, state *encoderState, p unsafe.Pointer) { } // Complex numbers are just a pair of floating-point numbers, real part first. -func encComplex(i *encInstr, state *encoderState, p unsafe.Pointer) { - c := *(*complex)(p) - if c != 0+0i || state.sendZero { - rpart := floatBits(float64(real(c))) - ipart := floatBits(float64(imag(c))) - state.update(i) - state.encodeUint(rpart) - state.encodeUint(ipart) - } -} - func encComplex64(i *encInstr, state *encoderState, p unsafe.Pointer) { c := *(*complex64)(p) if c != 0+0i || state.sendZero { @@ -446,10 +426,8 @@ var encOpMap = []encOp{ reflect.Uint32: encUint32, reflect.Uint64: encUint64, reflect.Uintptr: encUintptr, - reflect.Float: encFloat, reflect.Float32: encFloat32, reflect.Float64: encFloat64, - reflect.Complex: encComplex, reflect.Complex64: encComplex64, reflect.Complex128: encComplex128, reflect.String: encString, diff --git a/src/pkg/gob/encoder_test.go b/src/pkg/gob/encoder_test.go index db0b7db6670..c2309352a09 100644 --- a/src/pkg/gob/encoder_test.go +++ b/src/pkg/gob/encoder_test.go @@ -33,7 +33,7 @@ type ET3 struct { // Like ET1 but with a different type for a field type ET4 struct { A int - Et2 float + Et2 float64 Next int } @@ -189,13 +189,13 @@ func TestPtrTypeToType(t *testing.T) { func TestTypeToPtrPtrPtrPtrType(t *testing.T) { type Type2 struct { - A ****float + A ****float64 } t2 := Type2{} - t2.A = new(***float) - *t2.A = new(**float) - **t2.A = new(*float) - ***t2.A = new(float) + t2.A = new(***float64) + *t2.A = new(**float64) + **t2.A = new(*float64) + ***t2.A = new(float64) ****t2.A = 27.4 t2pppp := new(***Type2) if err := encAndDec(t2, t2pppp); err != nil { @@ -254,13 +254,13 @@ func TestDefaultsInArray(t *testing.T) { B []bool I []int S []string - F []float + F []float64 } t7 := Type7{ []bool{false, false, true}, []int{0, 0, 1}, []string{"hi", "", "there"}, - []float{0, 0, 1}, + []float64{0, 0, 1}, } var t7p Type7 if err := encAndDec(t7, &t7p); err != nil { diff --git a/src/pkg/gob/type.go b/src/pkg/gob/type.go index c00af87bf20..22502a6e6b9 100644 --- a/src/pkg/gob/type.go +++ b/src/pkg/gob/type.go @@ -93,7 +93,7 @@ var ( tBool = bootstrapType("bool", false, 1) tInt = bootstrapType("int", int(0), 2) tUint = bootstrapType("uint", uint(0), 3) - tFloat = bootstrapType("float", float64(0), 4) + tFloat = bootstrapType("float", 0.0, 4) tBytes = bootstrapType("bytes", make([]byte, 0), 5) tString = bootstrapType("string", "", 6) tComplex = bootstrapType("complex", 0+0i, 7) @@ -529,10 +529,8 @@ func registerBasics() { Register(uint16(0)) Register(uint32(0)) Register(uint64(0)) - Register(float(0)) Register(float32(0)) - Register(float64(0)) - Register(complex(0i)) + Register(0.0) Register(complex64(0i)) Register(complex128(0i)) Register(false) diff --git a/src/pkg/gob/type_test.go b/src/pkg/gob/type_test.go index 106e4f10b51..5aecde103a5 100644 --- a/src/pkg/gob/type_test.go +++ b/src/pkg/gob/type_test.go @@ -135,8 +135,8 @@ type Foo struct { b int32 // will become int c string d []byte - e *float // will become float - f ****float64 // will become float + e *float64 // will become float64 + f ****float64 // will become float64 g *Bar h *Bar // should not interpolate the definition of Bar again i *Foo // will not explode diff --git a/src/pkg/json/decode.go b/src/pkg/json/decode.go index c704cacbd28..ff91dd83c33 100644 --- a/src/pkg/json/decode.go +++ b/src/pkg/json/decode.go @@ -749,7 +749,7 @@ func (d *decodeState) literalInterface() interface{} { } n, err := strconv.Atof64(string(item)) if err != nil { - d.saveError(&UnmarshalTypeError{"number " + string(item), reflect.Typeof(float64(0))}) + d.saveError(&UnmarshalTypeError{"number " + string(item), reflect.Typeof(0.0)}) } return n } diff --git a/src/pkg/json/decode_test.go b/src/pkg/json/decode_test.go index 68cdea051ea..9cb27af412a 100644 --- a/src/pkg/json/decode_test.go +++ b/src/pkg/json/decode_test.go @@ -52,7 +52,7 @@ var unmarshalTests = []unmarshalTest{ // basic types {`true`, new(bool), true, nil}, {`1`, new(int), 1, nil}, - {`1.2`, new(float), 1.2, nil}, + {`1.2`, new(float64), 1.2, nil}, {`-5`, new(int16), int16(-5), nil}, {`"a\u1234"`, new(string), "a\u1234", nil}, {`"http:\/\/"`, new(string), "http://", nil}, @@ -220,7 +220,6 @@ type All struct { Uint32 uint32 Uint64 uint64 Uintptr uintptr - Float float Float32 float32 Float64 float64 @@ -238,7 +237,6 @@ type All struct { PUint32 *uint32 PUint64 *uint64 PUintptr *uintptr - PFloat *float PFloat32 *float32 PFloat64 *float64 @@ -291,7 +289,6 @@ var allValue = All{ Uint32: 10, Uint64: 11, Uintptr: 12, - Float: 13.1, Float32: 14.1, Float64: 15.1, Foo: "foo", @@ -312,7 +309,7 @@ var allValue = All{ ByteSlice: []byte{27, 28, 29}, Small: Small{Tag: "tag30"}, PSmall: &Small{Tag: "tag31"}, - Interface: float64(5.2), + Interface: 5.2, } var pallValue = All{ @@ -328,7 +325,6 @@ var pallValue = All{ PUint32: &allValue.Uint32, PUint64: &allValue.Uint64, PUintptr: &allValue.Uintptr, - PFloat: &allValue.Float, PFloat32: &allValue.Float32, PFloat64: &allValue.Float64, PString: &allValue.String, @@ -353,7 +349,6 @@ var allValueIndent = `{ "Uint32": 10, "Uint64": 11, "Uintptr": 12, - "Float": 13.1, "Float32": 14.1, "Float64": 15.1, "bar": "foo", @@ -369,7 +364,6 @@ var allValueIndent = `{ "PUint32": null, "PUint64": null, "PUintptr": null, - "PFloat": null, "PFloat32": null, "PFloat64": null, "String": "16", @@ -449,7 +443,6 @@ var pallValueIndent = `{ "Uint32": 0, "Uint64": 0, "Uintptr": 0, - "Float": 0, "Float32": 0, "Float64": 0, "bar": "", @@ -465,7 +458,6 @@ var pallValueIndent = `{ "PUint32": 10, "PUint64": 11, "PUintptr": 12, - "PFloat": 13.1, "PFloat32": 14.1, "PFloat64": 15.1, "String": "", diff --git a/src/pkg/json/stream_test.go b/src/pkg/json/stream_test.go index c83cfe3a937..6ddaed9fe8f 100644 --- a/src/pkg/json/stream_test.go +++ b/src/pkg/json/stream_test.go @@ -13,14 +13,14 @@ import ( // Test values for the stream test. // One of each JSON kind. var streamTest = []interface{}{ - float64(0.1), + 0.1, "hello", nil, true, false, []interface{}{"a", "b", "c"}, map[string]interface{}{"K": "Kelvin", "ß": "long s"}, - float64(3.14), // another value to make sure something can follow map + 3.14, // another value to make sure something can follow map } var streamEncoded = `0.1 diff --git a/src/pkg/math/all_test.go b/src/pkg/math/all_test.go index 0efef2bbf0a..d2a7d411ec0 100644 --- a/src/pkg/math/all_test.go +++ b/src/pkg/math/all_test.go @@ -2076,7 +2076,7 @@ func TestLog1p(t *testing.T) { t.Errorf("Log1p(%g) = %g, want %g", a, f, log1p[i]) } } - a := float64(9) + a := 9.0 if f := Log1p(a); f != Ln10 { t.Errorf("Log1p(%g) = %g, want %g", a, f, Ln10) } diff --git a/src/pkg/math/gamma.go b/src/pkg/math/gamma.go index 4c5b17d05c7..73ca0e53add 100644 --- a/src/pkg/math/gamma.go +++ b/src/pkg/math/gamma.go @@ -151,7 +151,7 @@ func Gamma(x float64) float64 { } // Reduce argument - z := float64(1) + z := 1.0 for x >= 3 { x = x - 1 z = z * x diff --git a/src/pkg/math/jn.go b/src/pkg/math/jn.go index 7d317431076..9024af3c223 100644 --- a/src/pkg/math/jn.go +++ b/src/pkg/math/jn.go @@ -132,7 +132,7 @@ func Jn(n int, x float64) float64 { } else { temp := x * 0.5 b = temp - a := float64(1) + a := 1.0 for i := 2; i <= n; i++ { a *= float64(i) // a = n! b *= temp // b = (x/2)**n @@ -181,7 +181,7 @@ func Jn(n int, x float64) float64 { q0, q1 = q1, z*q1-q0 } m := n + n - t := float64(0) + t := 0.0 for i := 2 * (n + k); i >= m; i -= 2 { t = 1 / (float64(i)/x - t) } diff --git a/src/pkg/math/lgamma.go b/src/pkg/math/lgamma.go index dc31be929db..dc30f468f4b 100644 --- a/src/pkg/math/lgamma.go +++ b/src/pkg/math/lgamma.go @@ -272,7 +272,7 @@ func Lgamma(x float64) (lgamma float64, sign int) { p := y * (S0 + y*(S1+y*(S2+y*(S3+y*(S4+y*(S5+y*S6)))))) q := 1 + y*(R1+y*(R2+y*(R3+y*(R4+y*(R5+y*R6))))) lgamma = 0.5*y + p/q - z := float64(1) // Lgamma(1+s) = Log(s) + Lgamma(s) + z := 1.0 // Lgamma(1+s) = Log(s) + Lgamma(s) switch i { case 7: z *= (y + 6) diff --git a/src/pkg/math/pow.go b/src/pkg/math/pow.go index f0ad84af6b9..06b107401b9 100644 --- a/src/pkg/math/pow.go +++ b/src/pkg/math/pow.go @@ -98,7 +98,7 @@ func Pow(x, y float64) float64 { } // ans = a1 * 2**ae (= 1 for now). - a1 := float64(1) + a1 := 1.0 ae := 0 // ans *= x**yf diff --git a/src/pkg/rand/rand.go b/src/pkg/rand/rand.go index 8c1219a7a1c..459aed1db4f 100644 --- a/src/pkg/rand/rand.go +++ b/src/pkg/rand/rand.go @@ -88,9 +88,6 @@ func (r *Rand) Float64() float64 { return float64(r.Int63()) / (1 << 63) } // Float32 returns, as a float32, a pseudo-random number in [0.0,1.0). func (r *Rand) Float32() float32 { return float32(r.Float64()) } -// Float returns, as a float, a pseudo-random number in [0.0,1.0). -func (r *Rand) Float() float { return float(r.Float64()) } - // Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n). func (r *Rand) Perm(n int) []int { m := make([]int, n) @@ -140,9 +137,6 @@ func Float64() float64 { return globalRand.Float64() } // Float32 returns, as a float32, a pseudo-random number in [0.0,1.0). func Float32() float32 { return globalRand.Float32() } -// Float returns, as a float, a pseudo-random number in [0.0,1.0). -func Float() float { return globalRand.Float() } - // Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n). func Perm(n int) []int { return globalRand.Perm(n) } diff --git a/src/pkg/rand/rand_test.go b/src/pkg/rand/rand_test.go index b9bf43208a3..2476ebaf61d 100644 --- a/src/pkg/rand/rand_test.go +++ b/src/pkg/rand/rand_test.go @@ -131,8 +131,8 @@ func TestStandardNormalValues(t *testing.T) { } func TestNonStandardNormalValues(t *testing.T) { - for sd := float64(0.5); sd < 1000; sd *= 2 { - for m := float64(0.5); m < 1000; m *= 2 { + for sd := 0.5; sd < 1000; sd *= 2 { + for m := 0.5; m < 1000; m *= 2 { for _, seed := range testSeeds { testNormalDistribution(t, numTestSamples, m, sd, seed) } @@ -182,7 +182,7 @@ func TestStandardExponentialValues(t *testing.T) { } func TestNonStandardExponentialValues(t *testing.T) { - for rate := float64(0.05); rate < 10; rate *= 2 { + for rate := 0.05; rate < 10; rate *= 2 { for _, seed := range testSeeds { testExponentialDistribution(t, numTestSamples, rate, seed) } diff --git a/src/pkg/rand/zipf.go b/src/pkg/rand/zipf.go index c4e7b7d93e9..38e8ec5162a 100644 --- a/src/pkg/rand/zipf.go +++ b/src/pkg/rand/zipf.go @@ -55,7 +55,7 @@ func NewZipf(r *Rand, s float64, v float64, imax uint64) *Zipf { // Uint64 returns a value drawn from the Zipf distributed described // by the Zipf object. func (z *Zipf) Uint64() uint64 { - k := float64(0.0) + k := 0.0 for { r := z.r.Float64() // r on [0,1] diff --git a/src/pkg/reflect/all_test.go b/src/pkg/reflect/all_test.go index 7d34e5ca30f..3675be6f1c1 100644 --- a/src/pkg/reflect/all_test.go +++ b/src/pkg/reflect/all_test.go @@ -48,7 +48,6 @@ var typeTests = []pair{ {struct{ x uint16 }{}, "uint16"}, {struct{ x uint32 }{}, "uint32"}, {struct{ x uint64 }{}, "uint64"}, - {struct{ x float }{}, "float"}, {struct{ x float32 }{}, "float32"}, {struct{ x float64 }{}, "float64"}, {struct{ x int8 }{}, "int8"}, @@ -244,8 +243,6 @@ func TestSet(t *testing.T) { } case *FloatValue: switch v.Type().Kind() { - case Float: - v.Set(128.5) case Float32: v.Set(256.25) case Float64: @@ -253,8 +250,6 @@ func TestSet(t *testing.T) { } case *ComplexValue: switch v.Type().Kind() { - case Complex: - v.Set(53200.0 + 100i) case Complex64: v.Set(532.125 + 10i) case Complex128: @@ -304,17 +299,13 @@ func TestSetValue(t *testing.T) { } case *FloatValue: switch v.Type().Kind() { - case Float: - v.SetValue(NewValue(float(128.5))) case Float32: v.SetValue(NewValue(float32(256.25))) case Float64: - v.SetValue(NewValue(float64(512.125))) + v.SetValue(NewValue(512.125)) } case *ComplexValue: switch v.Type().Kind() { - case Complex: - v.SetValue(NewValue(complex(53200.0 + 100i))) case Complex64: v.SetValue(NewValue(complex64(532.125 + 10i))) case Complex128: @@ -470,7 +461,7 @@ func TestInterfaceGet(t *testing.T) { assert(t, v2.Type().String(), "interface { }") i2 := v2.(*InterfaceValue).Interface() v3 := NewValue(i2) - assert(t, v3.Type().String(), "float") + assert(t, v3.Type().String(), "float64") } func TestInterfaceValue(t *testing.T) { @@ -482,11 +473,11 @@ func TestInterfaceValue(t *testing.T) { v2 := v1.(*PtrValue).Elem().(*StructValue).Field(0) assert(t, v2.Type().String(), "interface { }") v3 := v2.(*InterfaceValue).Elem() - assert(t, v3.Type().String(), "float") + assert(t, v3.Type().String(), "float64") i3 := v2.Interface() - if _, ok := i3.(float); !ok { - t.Error("v2.Interface() did not return float, got ", Typeof(i3)) + if _, ok := i3.(float64); !ok { + t.Error("v2.Interface() did not return float64, got ", Typeof(i3)) } } @@ -697,11 +688,11 @@ type _Complex struct { a int b [3]*_Complex c *string - d map[float]float + d map[float64]float64 } func TestDeepEqualComplexStruct(t *testing.T) { - m := make(map[float]float) + m := make(map[float64]float64) stra, strb := "hello", "hello" a, b := new(_Complex), new(_Complex) *a = _Complex{5, [3]*_Complex{a, b, a}, &stra, m} @@ -712,7 +703,7 @@ func TestDeepEqualComplexStruct(t *testing.T) { } func TestDeepEqualComplexStructInequality(t *testing.T) { - m := make(map[float]float) + m := make(map[float64]float64) stra, strb := "hello", "helloo" // Difference is here a, b := new(_Complex), new(_Complex) *a = _Complex{5, [3]*_Complex{a, b, a}, &stra, m} @@ -1317,12 +1308,12 @@ func TestImportPath(t *testing.T) { func TestDotDotDot(t *testing.T) { // Test example from FuncType.DotDotDot documentation. - var f func(x int, y ...float) + var f func(x int, y ...float64) typ := Typeof(f).(*FuncType) if typ.NumIn() == 2 && typ.In(0) == Typeof(int(0)) { sl, ok := typ.In(1).(*SliceType) if ok { - if sl.Elem() == Typeof(float(0)) { + if sl.Elem() == Typeof(0.0) { // ok return } @@ -1330,7 +1321,7 @@ func TestDotDotDot(t *testing.T) { } // Failed - t.Errorf("want NumIn() = 2, In(0) = int, In(1) = []float") + t.Errorf("want NumIn() = 2, In(0) = int, In(1) = []float64") s := fmt.Sprintf("have NumIn() = %d", typ.NumIn()) for i := 0; i < typ.NumIn(); i++ { s += fmt.Sprintf(", In(%d) = %s", i, typ.In(i)) diff --git a/src/pkg/reflect/type.go b/src/pkg/reflect/type.go index 9a7467b32d6..8dcbb241361 100644 --- a/src/pkg/reflect/type.go +++ b/src/pkg/reflect/type.go @@ -264,10 +264,8 @@ const ( Uint32 Uint64 Uintptr - Float Float32 Float64 - Complex Complex64 Complex128 Array @@ -306,9 +304,10 @@ var kindNames = []string{ Uint32: "uint32", Uint64: "uint64", Uintptr: "uintptr", - Float: "float", Float32: "float32", Float64: "float64", + Complex64: "complex64", + Complex128: "complex128", Array: "array", Chan: "chan", Func: "func", diff --git a/src/pkg/reflect/value.go b/src/pkg/reflect/value.go index e0bcb1a39d4..4d7d8723731 100644 --- a/src/pkg/reflect/value.go +++ b/src/pkg/reflect/value.go @@ -142,8 +142,6 @@ type FloatValue struct { // Get returns the underlying int value. func (v *FloatValue) Get() float64 { switch v.typ.Kind() { - case Float: - return float64(*(*float)(v.addr)) case Float32: return float64(*(*float32)(v.addr)) case Float64: @@ -160,8 +158,6 @@ func (v *FloatValue) Set(x float64) { switch v.typ.Kind() { default: panic("reflect: invalid float kind") - case Float: - *(*float)(v.addr) = float(x) case Float32: *(*float32)(v.addr) = float32(x) case Float64: @@ -191,8 +187,6 @@ type ComplexValue struct { // Get returns the underlying complex value. func (v *ComplexValue) Get() complex128 { switch v.typ.Kind() { - case Complex: - return complex128(*(*complex)(v.addr)) case Complex64: return complex128(*(*complex64)(v.addr)) case Complex128: @@ -209,8 +203,6 @@ func (v *ComplexValue) Set(x complex128) { switch v.typ.Kind() { default: panic("reflect: invalid complex kind") - case Complex: - *(*complex)(v.addr) = complex(x) case Complex64: *(*complex64)(v.addr) = complex64(x) case Complex128: diff --git a/src/pkg/runtime/type.go b/src/pkg/runtime/type.go index d92fe5f2a32..a350d4a0b15 100644 --- a/src/pkg/runtime/type.go +++ b/src/pkg/runtime/type.go @@ -51,10 +51,8 @@ const ( kindUint32 kindUint64 kindUintptr - kindFloat kindFloat32 kindFloat64 - kindComplex kindComplex64 kindComplex128 kindArray diff --git a/src/pkg/runtime/type.h b/src/pkg/runtime/type.h index 4b5bd7ac2ec..3fb368ebd9f 100644 --- a/src/pkg/runtime/type.h +++ b/src/pkg/runtime/type.h @@ -41,10 +41,8 @@ enum { KindUint32, KindUint64, KindUintptr, - KindFloat, KindFloat32, KindFloat64, - KindComplex, KindComplex64, KindComplex128, KindArray, diff --git a/src/pkg/sort/search.go b/src/pkg/sort/search.go index b3ddd2dfa81..6828e19b63b 100644 --- a/src/pkg/sort/search.go +++ b/src/pkg/sort/search.go @@ -74,7 +74,7 @@ func Search(n int, f func(int) bool) int { // Convenience wrappers for common cases. -// SearchInts searches x in a sorted slice of ints and returns the index +// SearchInts searches for x in a sorted slice of ints and returns the index // as specified by Search. The array must be sorted in ascending order. // func SearchInts(a []int, x int) int { @@ -82,15 +82,15 @@ func SearchInts(a []int, x int) int { } -// SearchFloats searches x in a sorted slice of floats and returns the index +// SearchFloat64s searches for x in a sorted slice of float64s and returns the index // as specified by Search. The array must be sorted in ascending order. // -func SearchFloats(a []float, x float) int { +func SearchFloat64s(a []float64, x float64) int { return Search(len(a), func(i int) bool { return a[i] >= x }) } -// SearchStrings searches x in a sorted slice of strings and returns the index +// SearchStrings searches for x in a sorted slice of strings and returns the index // as specified by Search. The array must be sorted in ascending order. // func SearchStrings(a []string, x string) int { @@ -102,8 +102,8 @@ func SearchStrings(a []string, x string) int { func (p IntArray) Search(x int) int { return SearchInts(p, x) } -// Search returns the result of applying SearchFloats to the receiver and x. -func (p FloatArray) Search(x float) int { return SearchFloats(p, x) } +// Search returns the result of applying SearchFloat64s to the receiver and x. +func (p Float64Array) Search(x float64) int { return SearchFloat64s(p, x) } // Search returns the result of applying SearchStrings to the receiver and x. diff --git a/src/pkg/sort/search_test.go b/src/pkg/sort/search_test.go index e16e2c93fb7..939f66af380 100644 --- a/src/pkg/sort/search_test.go +++ b/src/pkg/sort/search_test.go @@ -96,7 +96,7 @@ func TestSearchEfficiency(t *testing.T) { // Smoke tests for convenience wrappers - not comprehensive. -var fdata = []float{0: -3.14, 1: 0, 2: 1, 3: 2, 4: 1000.7} +var fdata = []float64{0: -3.14, 1: 0, 2: 1, 3: 2, 4: 1000.7} var sdata = []string{0: "f", 1: "foo", 2: "foobar", 3: "x"} var wrappertests = []struct { @@ -105,10 +105,10 @@ var wrappertests = []struct { i int }{ {"SearchInts", SearchInts(data, 11), 8}, - {"SearchFloats", SearchFloats(fdata, 2.1), 4}, + {"SearchFloat64s", SearchFloat64s(fdata, 2.1), 4}, {"SearchStrings", SearchStrings(sdata, ""), 0}, {"IntArray.Search", IntArray(data).Search(0), 2}, - {"FloatArray.Search", FloatArray(fdata).Search(2.0), 3}, + {"Float64Array.Search", Float64Array(fdata).Search(2.0), 3}, {"StringArray.Search", StringArray(sdata).Search("x"), 3}, } diff --git a/src/pkg/sort/sort.go b/src/pkg/sort/sort.go index 02e647fca9a..c7945d21b61 100644 --- a/src/pkg/sort/sort.go +++ b/src/pkg/sort/sort.go @@ -166,15 +166,15 @@ func (p IntArray) Swap(i, j int) { p[i], p[j] = p[j], p[i] } func (p IntArray) Sort() { Sort(p) } -// FloatArray attaches the methods of Interface to []float, sorting in increasing order. -type FloatArray []float +// Float64Array attaches the methods of Interface to []float64, sorting in increasing order. +type Float64Array []float64 -func (p FloatArray) Len() int { return len(p) } -func (p FloatArray) Less(i, j int) bool { return p[i] < p[j] } -func (p FloatArray) Swap(i, j int) { p[i], p[j] = p[j], p[i] } +func (p Float64Array) Len() int { return len(p) } +func (p Float64Array) Less(i, j int) bool { return p[i] < p[j] } +func (p Float64Array) Swap(i, j int) { p[i], p[j] = p[j], p[i] } // Sort is a convenience method. -func (p FloatArray) Sort() { Sort(p) } +func (p Float64Array) Sort() { Sort(p) } // StringArray attaches the methods of Interface to []string, sorting in increasing order. @@ -192,15 +192,15 @@ func (p StringArray) Sort() { Sort(p) } // SortInts sorts an array of ints in increasing order. func SortInts(a []int) { Sort(IntArray(a)) } -// SortFloats sorts an array of floats in increasing order. -func SortFloats(a []float) { Sort(FloatArray(a)) } +// SortFloat64s sorts an array of float64s in increasing order. +func SortFloat64s(a []float64) { Sort(Float64Array(a)) } // SortStrings sorts an array of strings in increasing order. func SortStrings(a []string) { Sort(StringArray(a)) } // IntsAreSorted tests whether an array of ints is sorted in increasing order. func IntsAreSorted(a []int) bool { return IsSorted(IntArray(a)) } -// FloatsAreSorted tests whether an array of floats is sorted in increasing order. -func FloatsAreSorted(a []float) bool { return IsSorted(FloatArray(a)) } +// Float64sAreSorted tests whether an array of float64s is sorted in increasing order. +func Float64sAreSorted(a []float64) bool { return IsSorted(Float64Array(a)) } // StringsAreSorted tests whether an array of strings is sorted in increasing order. func StringsAreSorted(a []string) bool { return IsSorted(StringArray(a)) } diff --git a/src/pkg/sort/sort_test.go b/src/pkg/sort/sort_test.go index 2085a67c82a..1bea8f03262 100644 --- a/src/pkg/sort/sort_test.go +++ b/src/pkg/sort/sort_test.go @@ -13,7 +13,7 @@ import ( var ints = [...]int{74, 59, 238, -784, 9845, 959, 905, 0, 0, 42, 7586, -5467984, 7586} -var floats = [...]float{74.3, 59.0, 238.2, -784.0, 2.3, 9845.768, -959.7485, 905, 7.8, 7.8} +var float64s = [...]float64{74.3, 59.0, 238.2, -784.0, 2.3, 9845.768, -959.7485, 905, 7.8, 7.8} var strings = [...]string{"", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "***"} func TestSortIntArray(t *testing.T) { @@ -26,12 +26,12 @@ func TestSortIntArray(t *testing.T) { } } -func TestSortFloatArray(t *testing.T) { - data := floats - a := FloatArray(data[0:]) +func TestSortFloat64Array(t *testing.T) { + data := float64s + a := Float64Array(data[0:]) Sort(a) if !IsSorted(a) { - t.Errorf("sorted %v", floats) + t.Errorf("sorted %v", float64s) t.Errorf(" got %v", data) } } @@ -55,11 +55,11 @@ func TestSortInts(t *testing.T) { } } -func TestSortFloats(t *testing.T) { - data := floats - SortFloats(data[0:]) - if !FloatsAreSorted(data[0:]) { - t.Errorf("sorted %v", floats) +func TestSortFloat64s(t *testing.T) { + data := float64s + SortFloat64s(data[0:]) + if !Float64sAreSorted(data[0:]) { + t.Errorf("sorted %v", float64s) t.Errorf(" got %v", data) } } diff --git a/src/pkg/strconv/atof.go b/src/pkg/strconv/atof.go index bcb138f7ad2..72f162c5134 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 68c50bfbead..6cc60e549da 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 a6091fc6c38..4ec3cdbb974 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<> 8 // OK - b10 byte = (1<<10) // ERROR "overflow" - b11 byte = (byte(1)<<10) >> 8 // ERROR "overflow" - b12 byte = 1000 // ERROR "overflow" - b13 byte = byte(1000) // ERROR "overflow" - b14 byte = byte(100) * byte(100) // ERROR "overflow" - b15 byte = byte(100) * 100 // ERROR "overflow" - b16 byte = byte(0) * 1000 // ERROR "overflow" - b16a byte = 0 * 1000 // OK - b17 byte = byte(0) * byte(1000) // ERROR "overflow" - b18 byte = Uint8/0 // ERROR "division by zero" + b1 = Uint8 * Uint8 // ERROR "overflow" + b2 = Uint8 * -1 // ERROR "overflow" + b3 = Uint8 - Uint8 // OK + b4 = Uint8 - Uint8 - Uint8 // ERROR "overflow" + b5 = uint8(^0) // ERROR "overflow" + b6 = ^uint8(0) // OK + b7 = uint8(Minus1) // ERROR "overflow" + b8 = uint8(int8(-1)) // ERROR "overflow" + b8a = uint8(-1) // ERROR "overflow" + b9 byte = (1 << 10) >> 8 // OK + b10 byte = (1 << 10) // ERROR "overflow" + b11 byte = (byte(1) << 10) >> 8 // ERROR "overflow" + b12 byte = 1000 // ERROR "overflow" + b13 byte = byte(1000) // ERROR "overflow" + b14 byte = byte(100) * byte(100) // ERROR "overflow" + b15 byte = byte(100) * 100 // ERROR "overflow" + b16 byte = byte(0) * 1000 // ERROR "overflow" + b16a byte = 0 * 1000 // OK + b17 byte = byte(0) * byte(1000) // ERROR "overflow" + b18 byte = Uint8 / 0 // ERROR "division by zero" - c1 float64 = Big - c2 float64 = Big*Big // ERROR "overflow" - c3 float64 = float64(Big)*Big // ERROR "overflow" - c4 = Big*Big // ERROR "overflow" - c5 = Big/0 // ERROR "division by zero" + c1 float64 = Big + c2 float64 = Big * Big // ERROR "overflow" + c3 float64 = float64(Big) * Big // ERROR "overflow" + c4 = Big * Big // ERROR "overflow" + c5 = Big / 0 // ERROR "division by zero" ) func f(int) func main() { - f(Int8) // ERROR "convert|wrong type|cannot" - f(Minus1) // ERROR "convert|wrong type|cannot" - f(Uint8) // ERROR "convert|wrong type|cannot" - f(Const) // OK - f(Float32) // ERROR "convert|wrong type|cannot" - f(Float) // ERROR "convert|wrong type|cannot" - f(ConstFloat) // ERROR "truncate" - f(ConstFloat - 0.5) // OK - f(Big) // ERROR "convert|wrong type|cannot" - f(String) // ERROR "convert|wrong type|cannot|incompatible" - f(Bool) // ERROR "convert|wrong type|cannot|incompatible" + f(Int8) // ERROR "convert|wrong type|cannot" + f(Minus1) // ERROR "convert|wrong type|cannot" + f(Uint8) // ERROR "convert|wrong type|cannot" + f(Const) // OK + f(Float32) // ERROR "convert|wrong type|cannot" + f(Float64) // ERROR "convert|wrong type|cannot" + f(ConstFloat) // ERROR "truncate" + f(ConstFloat - 0.5) // OK + f(Big) // ERROR "convert|wrong type|cannot" + f(String) // ERROR "convert|wrong type|cannot|incompatible" + f(Bool) // ERROR "convert|wrong type|cannot|incompatible" } -const ptr = nil // ERROR "const.*nil" +const ptr = nil // ERROR "const.*nil" diff --git a/test/convlit.go b/test/convlit.go index 94889d4a963..90ac5490c84 100644 --- a/test/convlit.go +++ b/test/convlit.go @@ -11,54 +11,56 @@ package main // the language spec says for now. var x1 = string(1) var x2 string = string(1) -var x3 = int(1.5) // ERROR "convert|truncate" -var x4 int = int(1.5) // ERROR "convert|truncate" +var x3 = int(1.5) // ERROR "convert|truncate" +var x4 int = int(1.5) // ERROR "convert|truncate" var x5 = "a" + string(1) -var x6 = int(1e100) // ERROR "overflow" -var x7 = float(1e1000) // ERROR "overflow" +var x6 = int(1e100) // ERROR "overflow" +var x7 = float32(1e1000) // ERROR "overflow" // implicit conversions merit scrutiny var s string -var bad1 string = 1 // ERROR "conver|incompatible|invalid|cannot" -var bad2 = s + 1 // ERROR "conver|incompatible|invalid" -var bad3 = s + 'a' // ERROR "conver|incompatible|invalid" -var bad4 = "a" + 1 // ERROR "literals|incompatible|convert|invalid" -var bad5 = "a" + 'a' // ERROR "literals|incompatible|convert|invalid" +var bad1 string = 1 // ERROR "conver|incompatible|invalid|cannot" +var bad2 = s + 1 // ERROR "conver|incompatible|invalid" +var bad3 = s + 'a' // ERROR "conver|incompatible|invalid" +var bad4 = "a" + 1 // ERROR "literals|incompatible|convert|invalid" +var bad5 = "a" + 'a' // ERROR "literals|incompatible|convert|invalid" -var bad6 int = 1.5 // ERROR "convert|truncate" -var bad7 int = 1e100 // ERROR "overflow" -var bad8 float32 = 1e200 // ERROR "overflow" +var bad6 int = 1.5 // ERROR "convert|truncate" +var bad7 int = 1e100 // ERROR "overflow" +var bad8 float32 = 1e200 // ERROR "overflow" // but these implicit conversions are okay var good1 string = "a" var good2 int = 1.0 var good3 int = 1e9 -var good4 float = 1e20 +var good4 float64 = 1e20 // explicit conversion of string is okay var _ = []int("abc") var _ = []byte("abc") // implicit is not -var _ []int = "abc" // ERROR "cannot use|incompatible|invalid" -var _ []byte = "abc" // ERROR "cannot use|incompatible|invalid" +var _ []int = "abc" // ERROR "cannot use|incompatible|invalid" +var _ []byte = "abc" // ERROR "cannot use|incompatible|invalid" // named string is okay type Tstring string + var ss Tstring = "abc" var _ = []int(ss) var _ = []byte(ss) // implicit is still not -var _ []int = ss // ERROR "cannot use|incompatible|invalid" -var _ []byte = ss // ERROR "cannot use|incompatible|invalid" +var _ []int = ss // ERROR "cannot use|incompatible|invalid" +var _ []byte = ss // ERROR "cannot use|incompatible|invalid" // named slice is not type Tint []int type Tbyte []byte -var _ = Tint("abc") // ERROR "convert|incompatible|invalid" -var _ = Tbyte("abc") // ERROR "convert|incompatible|invalid" + +var _ = Tint("abc") // ERROR "convert|incompatible|invalid" +var _ = Tbyte("abc") // ERROR "convert|incompatible|invalid" // implicit is still not -var _ Tint = "abc" // ERROR "cannot use|incompatible|invalid" -var _ Tbyte = "abc" // ERROR "cannot use|incompatible|invalid" +var _ Tint = "abc" // ERROR "cannot use|incompatible|invalid" +var _ Tbyte = "abc" // ERROR "cannot use|incompatible|invalid" diff --git a/test/decl.go b/test/decl.go index c31082bcfdc..95b6346c3ed 100644 --- a/test/decl.go +++ b/test/decl.go @@ -8,26 +8,26 @@ package main -func f1() int { return 1 } -func f2() (float, int) { return 1, 2 } -func f3() (float, int, string) { return 1, 2, "3" } +func f1() int { return 1 } +func f2() (float32, int) { return 1, 2 } +func f3() (float32, int, string) { return 1, 2, "3" } func x() (s string) { a, b, s := f3() _, _ = a, b - return // tests that result var is in scope for redeclaration + return // tests that result var is in scope for redeclaration } func main() { i, f, s := f3() - j, f := f2() // redeclare f + j, f := f2() // redeclare f k := f1() m, g, s := f3() m, h, s := f3() { // new block should be ok. i, f, s := f3() - j, f := f2() // redeclare f + j, f := f2() // redeclare f k := f1() m, g, s := f3() m, h, s := f3() diff --git a/test/declbad.go b/test/declbad.go index 269ebdefb53..5e5e1450110 100644 --- a/test/declbad.go +++ b/test/declbad.go @@ -8,51 +8,51 @@ package main -func f1() int { return 1 } -func f2() (float, int) { return 1, 2 } -func f3() (float, int, string) { return 1, 2, "3" } +func f1() int { return 1 } +func f2() (float32, int) { return 1, 2 } +func f3() (float32, int, string) { return 1, 2, "3" } func main() { { // simple redeclaration i := f1() - i := f1() // ERROR "redeclared|no new" + i := f1() // ERROR "redeclared|no new" _ = i } { // change of type for f i, f, s := f3() - f, g, t := f3() // ERROR "redeclared|cannot assign|incompatible" + f, g, t := f3() // ERROR "redeclared|cannot assign|incompatible" _, _, _, _, _ = i, f, s, g, t } { // change of type for i i, f, s := f3() - j, i, t := f3() // ERROR "redeclared|cannot assign|incompatible" + j, i, t := f3() // ERROR "redeclared|cannot assign|incompatible" _, _, _, _, _ = i, f, s, j, t } { // no new variables i, f, s := f3() - i, f := f2() // ERROR "redeclared|no new" + i, f := f2() // ERROR "redeclared|no new" _, _, _ = i, f, s } { // single redeclaration i, f, s := f3() - i := f1() // ERROR "redeclared|no new|incompatible" + i := f1() // ERROR "redeclared|no new|incompatible" _, _, _ = i, f, s } - // double redeclaration + // double redeclaration { i, f, s := f3() - i, f := f2() // ERROR "redeclared|no new" + i, f := f2() // ERROR "redeclared|no new" _, _, _ = i, f, s } { // triple redeclaration i, f, s := f3() - i, f, s := f3() // ERROR "redeclared|no new" + i, f, s := f3() // ERROR "redeclared|no new" _, _, _ = i, f, s } } diff --git a/test/fixedbugs/bug006.go b/test/fixedbugs/bug006.go index e7694f95b56..43b5dfb1294 100644 --- a/test/fixedbugs/bug006.go +++ b/test/fixedbugs/bug006.go @@ -9,11 +9,16 @@ package main import "os" const ( - x float = iota; - g float = 4.5 * iota; -); + x float64 = iota + g float64 = 4.5 * iota +) func main() { - if g == 0.0 { print("zero\n");} - if g != 4.5 { print(" fail\n"); os.Exit(1); } + if g == 0.0 { + print("zero\n") + } + if g != 4.5 { + print(" fail\n") + os.Exit(1) + } } diff --git a/test/fixedbugs/bug007.go b/test/fixedbugs/bug007.go index bd970de5f92..d65f6da4503 100644 --- a/test/fixedbugs/bug007.go +++ b/test/fixedbugs/bug007.go @@ -7,7 +7,9 @@ package main type ( - Point struct { x, y float }; + Point struct { + x, y float64 + } Polar Point ) diff --git a/test/fixedbugs/bug010.go b/test/fixedbugs/bug010.go index e71c4d7f0bc..7d96988d43b 100644 --- a/test/fixedbugs/bug010.go +++ b/test/fixedbugs/bug010.go @@ -7,14 +7,14 @@ package main -func f(i int, f float) { - i = 8; - f = 8.0; - return; +func f(i int, f float64) { + i = 8 + f = 8.0 + return } func main() { - f(3, float(5)) + f(3, float64(5)) } /* diff --git a/test/fixedbugs/bug011.go b/test/fixedbugs/bug011.go index 551adb77dfc..ce627472c47 100644 --- a/test/fixedbugs/bug011.go +++ b/test/fixedbugs/bug011.go @@ -8,19 +8,19 @@ package main type T struct { - x, y int; + x, y int } -func (t *T) m(a int, b float) int { - return (t.x+a) * (t.y+int(b)); +func (t *T) m(a int, b float64) int { + return (t.x + a) * (t.y + int(b)) } func main() { - var t *T = new(T); - t.x = 1; - t.y = 2; - r10 := t.m(1, 3.0); - _ = r10; + var t *T = new(T) + t.x = 1 + t.y = 2 + r10 := t.m(1, 3.0) + _ = r10 } /* bug11.go:16: fatal error: walktype: switch 1 unknown op CALLMETH l(16) INT32 diff --git a/test/fixedbugs/bug035.go b/test/fixedbugs/bug035.go index 461c0607ac9..bd2a633f298 100644 --- a/test/fixedbugs/bug035.go +++ b/test/fixedbugs/bug035.go @@ -6,8 +6,8 @@ package main -func f9(a int) (i int, f float) { - i := 9; // ERROR "redecl|no new" - f := float(9); // ERROR "redecl|no new" - return i, f; +func f9(a int) (i int, f float64) { + i := 9 // ERROR "redecl|no new" + f := float64(9) // ERROR "redecl|no new" + return i, f } diff --git a/test/fixedbugs/bug047.go b/test/fixedbugs/bug047.go index f3749e73972..5a776abce8d 100644 --- a/test/fixedbugs/bug047.go +++ b/test/fixedbugs/bug047.go @@ -9,15 +9,15 @@ package main func main() { type T struct { - s string; - f float; - }; - var s string = "hello"; - var f float = 0.2; - t := T{s, f}; + s string + f float64 + } + var s string = "hello" + var f float64 = 0.2 + t := T{s, f} - type M map[int] int; - m0 := M{7:8}; + type M map[int]int + m0 := M{7: 8} - _, _ = t, m0; + _, _ = t, m0 } diff --git a/test/fixedbugs/bug080.go b/test/fixedbugs/bug080.go index a5003d29b1f..bae16cdb2e9 100644 --- a/test/fixedbugs/bug080.go +++ b/test/fixedbugs/bug080.go @@ -4,18 +4,18 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package main - -func f1() (x int, y float) { - return; +package main + +func f1() (x int, y float64) { + return } -func f2 (x int, y float) { - return; +func f2(x int, y float64) { + return } func main() { - f2(f1()); // this should be a legal call + f2(f1()) // this should be a legal call } /* diff --git a/test/fixedbugs/bug109.go b/test/fixedbugs/bug109.go index c679771f2ec..7666577230f 100644 --- a/test/fixedbugs/bug109.go +++ b/test/fixedbugs/bug109.go @@ -5,10 +5,11 @@ // license that can be found in the LICENSE file. package main -func f(a float) float { - e := 1.0; - e = e * a; - return e; + +func f(a float64) float64 { + e := 1.0 + e = e * a + return e } /* diff --git a/test/fixedbugs/bug167.go b/test/fixedbugs/bug167.go index 729299b6657..33eb3cb1a95 100644 --- a/test/fixedbugs/bug167.go +++ b/test/fixedbugs/bug167.go @@ -7,20 +7,24 @@ package main func f1() { - type T struct { x int } + type T struct { + x int + } } func f2() { - type T struct { x float } + type T struct { + x float64 + } } func main() { - f1(); - f2(); + f1() + f2() } /* 1606416576: conflicting definitions for main.T·bug167 bug167.6: type main.T·bug167 struct { x int } -bug167.6: type main.T·bug167 struct { x float } +bug167.6: type main.T·bug167 struct { x float64 } */ diff --git a/test/fixedbugs/bug193.go b/test/fixedbugs/bug193.go index f6b03e13d2e..5ef02b1c1d7 100644 --- a/test/fixedbugs/bug193.go +++ b/test/fixedbugs/bug193.go @@ -7,10 +7,10 @@ package main func main() { - s := uint(10); - ss := 1<