1
0
mirror of https://github.com/golang/go synced 2024-07-05 09:50:19 +00:00

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
This commit is contained in:
Russ Cox 2011-01-19 23:09:00 -05:00
parent 0849944694
commit f2b5a07453
122 changed files with 3309 additions and 3523 deletions

View File

@ -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
}

View File

@ -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))
}
}

View File

@ -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)) }

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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.

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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()),
))

View File

@ -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),
),

View File

@ -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))
}

View File

@ -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

View File

@ -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() {

View File

@ -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})

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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"}

View File

@ -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)
}

View File

@ -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

View File

@ -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
*/

View File

@ -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

View File

@ -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)

View File

@ -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) {

View File

@ -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)
}

View File

@ -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:<v=F(7)>, 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"},

View File

@ -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))
}
}

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)) }

View File

@ -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 {

View File

@ -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
}
}

View File

@ -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{}

View File

@ -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:

View File

@ -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,

View File

@ -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 {

View File

@ -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)

View File

@ -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

View File

@ -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
}

View File

@ -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": "",

View File

@ -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{}{"": "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

View File

@ -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)
}

View File

@ -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

View File

@ -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)
}

View File

@ -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)

View File

@ -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

View File

@ -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) }

View File

@ -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)
}

View File

@ -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]

View File

@ -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))

View File

@ -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",

View File

@ -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:

View File

@ -51,10 +51,8 @@ const (
kindUint32
kindUint64
kindUintptr
kindFloat
kindFloat32
kindFloat64
kindComplex
kindComplex64
kindComplex128
kindArray

View File

@ -41,10 +41,8 @@ enum {
KindUint32,
KindUint64,
KindUintptr,
KindFloat,
KindFloat32,
KindFloat64,
KindComplex,
KindComplex64,
KindComplex128,
KindArray,

View File

@ -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.

View File

@ -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},
}

View File

@ -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)) }

View File

@ -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)
}
}

View File

@ -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).

View File

@ -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")
}
}

View File

@ -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)

View File

@ -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)

View File

@ -60,18 +60,16 @@ func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool) {
switch concrete := t.(type) {
case *reflect.BoolType:
return reflect.NewValue(rand.Int()&1 == 0), true
case *reflect.FloatType, *reflect.IntType, *reflect.UintType:
case *reflect.FloatType, *reflect.IntType, *reflect.UintType, *reflect.ComplexType:
switch t.Kind() {
case reflect.Float32:
return reflect.NewValue(randFloat32(rand)), true
case reflect.Float64:
return reflect.NewValue(randFloat64(rand)), true
case reflect.Float:
if t.Size() == 4 {
return reflect.NewValue(float(randFloat32(rand))), true
} else {
return reflect.NewValue(float(randFloat64(rand))), true
}
case reflect.Complex64:
return reflect.NewValue(complex(randFloat32(rand), randFloat32(rand))), true
case reflect.Complex128:
return reflect.NewValue(complex(randFloat64(rand), randFloat64(rand))), true
case reflect.Int16:
return reflect.NewValue(int16(randInt64(rand))), true
case reflect.Int32:
@ -157,7 +155,7 @@ type Config struct {
MaxCount int
// MaxCountScale is a non-negative scale factor applied to the default
// maximum. If zero, the default is unchanged.
MaxCountScale float
MaxCountScale float64
// If non-nil, rand is a source of random numbers. Otherwise a default
// pseudo-random source will be used.
Rand *rand.Rand
@ -183,7 +181,7 @@ func (c *Config) getMaxCount() (maxCount int) {
maxCount = c.MaxCount
if maxCount == 0 {
if c.MaxCountScale != 0 {
maxCount = int(c.MaxCountScale * float(*defaultMaxCount))
maxCount = int(c.MaxCountScale * float64(*defaultMaxCount))
} else {
maxCount = *defaultMaxCount
}

View File

@ -17,7 +17,9 @@ func fFloat32(a float32) float32 { return a }
func fFloat64(a float64) float64 { return a }
func fFloat(a float) float { return a }
func fComplex64(a complex64) complex64 { return a }
func fComplex128(a complex128) complex128 { return a }
func fInt16(a int16) int16 { return a }
@ -71,7 +73,8 @@ func TestCheckEqual(t *testing.T) {
reportError("fBool", CheckEqual(fBool, fBool, nil), t)
reportError("fFloat32", CheckEqual(fFloat32, fFloat32, nil), t)
reportError("fFloat64", CheckEqual(fFloat64, fFloat64, nil), t)
reportError("fFloat", CheckEqual(fFloat, fFloat, nil), t)
reportError("fComplex64", CheckEqual(fComplex64, fComplex64, nil), t)
reportError("fComplex128", CheckEqual(fComplex128, fComplex128, nil), t)
reportError("fInt16", CheckEqual(fInt16, fInt16, nil), t)
reportError("fInt32", CheckEqual(fInt32, fInt32, nil), t)
reportError("fInt64", CheckEqual(fInt64, fInt64, nil), t)

View File

@ -227,7 +227,6 @@ type allScalars struct {
Uint32 uint32
Uint64 uint64
Uintptr uintptr
Float float
Float32 float32
Float64 float64
String string
@ -249,7 +248,6 @@ var all = allScalars{
Uint32: 9,
Uint64: 10,
Uintptr: 11,
Float: 12.0,
Float32: 13.0,
Float64: 14.0,
String: "15",

View File

@ -193,7 +193,7 @@ func verifyInterface() {
case 2:
e[i] = fmt.Sprintf("%d", i)
case 3:
e[i] = float(i)
e[i] = float64(i)
}
}

View File

@ -28,7 +28,7 @@ const (
c4
)
var ints = []string {
var ints = []string{
"1",
"2",
"3",
@ -36,15 +36,15 @@ var ints = []string {
func f() (int, int) {
call += "f"
return 1,2
return 1, 2
}
func g() (float, float) {
func g() (float64, float64) {
call += "g"
return 3,4
return 3, 4
}
func h(_ int, _ float) {
func h(_ int, _ float64) {
}
func i() int {
@ -55,43 +55,64 @@ func i() int {
var _ = i()
func main() {
if call != "i" {panic("init did not run")}
if call != "i" {
panic("init did not run")
}
call = ""
_, _ = f()
a, _ := f()
if a != 1 {panic(a)}
if a != 1 {
panic(a)
}
b, _ := g()
if b != 3 {panic(b)}
if b != 3 {
panic(b)
}
_, a = f()
if a != 2 {panic(a)}
if a != 2 {
panic(a)
}
_, b = g()
if b != 4 {panic(b)}
if b != 4 {
panic(b)
}
_ = i()
if call != "ffgfgi" {panic(call)}
if c4 != 4 {panic(c4)}
if call != "ffgfgi" {
panic(call)
}
if c4 != 4 {
panic(c4)
}
out := ""
for _, s := range ints {
out += s
}
if out != "123" {panic(out)}
if out != "123" {
panic(out)
}
sum := 0
for s := range ints {
sum += s
}
if sum != 3 {panic(sum)}
if sum != 3 {
panic(sum)
}
h(a,b)
h(a, b)
}
// useless but legal
var _ int = 1
var _ = 2
var _, _ = 3, 4
const _ = 3
const _, _ = 4, 5
type _ int
func _() {
panic("oops")
}

View File

@ -7,26 +7,19 @@
package main
var (
f float
f32 float32
f64 float64
c complex
c64 complex64
c64 complex64
c128 complex128
)
func main() {
// ok
c = cmplx(f, f)
c64 = cmplx(f32, f32)
c128 = cmplx(f64, f64)
c64 = complex(f32, f32)
c128 = complex(f64, f64)
_ = complex(0) // ok
_ = cmplx(f, f32) // ERROR "cmplx"
_ = cmplx(f, f64) // ERROR "cmplx"
_ = cmplx(f32, f) // ERROR "cmplx"
_ = cmplx(f32, f64) // ERROR "cmplx"
_ = cmplx(f64, f) // ERROR "cmplx"
_ = cmplx(f64, f32) // ERROR "cmplx"
_ = complex128(0) // ok
_ = complex(f32, f64) // ERROR "complex"
_ = complex(f64, f32) // ERROR "complex"
}

View File

@ -72,7 +72,7 @@ main(void)
if(iscnan(n) && d == 0)
q = (NAN+NAN*I) / zero;
printf("\tTest{cmplx(%s, %s), cmplx(%s, %s), cmplx(%s, %s)},\n",
printf("\tTest{complex(%s, %s), complex(%s, %s), complex(%s, %s)},\n",
fmt(creal(n)), fmt(cimag(n)),
fmt(creal(d)), fmt(cimag(d)),
fmt(creal(q)), fmt(cimag(q)));

File diff suppressed because it is too large Load Diff

View File

@ -6,9 +6,16 @@
package main
type T struct { i int; f float; s string; next *T }
type T struct {
i int
f float64
s string
next *T
}
type R struct { num int }
type R struct {
num int
}
func itor(a int) *R {
r := new(R)
@ -18,11 +25,16 @@ func itor(a int) *R {
func eq(a []*R) {
for i := 0; i < len(a); i++ {
if a[i].num != i { panic("bad") }
if a[i].num != i {
panic("bad")
}
}
}
type P struct { a, b int }
type P struct {
a, b int
}
func NewP(a, b int) *P {
return &P{a, b}
}
@ -34,37 +46,57 @@ func main() {
var tp *T
tp = &T{0, 7.2, "hi", &t}
a1 := []int{1,2,3}
if len(a1) != 3 { panic("a1") }
a2 := [10]int{1,2,3}
if len(a2) != 10 || cap(a2) != 10 { panic("a2") }
a1 := []int{1, 2, 3}
if len(a1) != 3 {
panic("a1")
}
a2 := [10]int{1, 2, 3}
if len(a2) != 10 || cap(a2) != 10 {
panic("a2")
}
a3 := [10]int{1,2,3,}
if len(a3) != 10 || a2[3] != 0 { panic("a3") }
a3 := [10]int{1, 2, 3}
if len(a3) != 10 || a2[3] != 0 {
panic("a3")
}
var oai []int
oai = []int{1,2,3}
if len(oai) != 3 { panic("oai") }
oai = []int{1, 2, 3}
if len(oai) != 3 {
panic("oai")
}
at := [...]*T{&t, tp, &t}
if len(at) != 3 { panic("at") }
if len(at) != 3 {
panic("at")
}
c := make(chan int)
ac := []chan int{c, c, c}
if len(ac) != 3 { panic("ac") }
if len(ac) != 3 {
panic("ac")
}
aat := [][len(at)]*T{at, at}
if len(aat) != 2 || len(aat[1]) != 3 { panic("aat") }
if len(aat) != 2 || len(aat[1]) != 3 {
panic("aat")
}
s := string([]byte{'h', 'e', 'l', 'l', 'o'})
if s != "hello" { panic("s") }
if s != "hello" {
panic("s")
}
m := map[string]float{"one":1.0, "two":2.0, "pi":22./7.}
if len(m) != 3 { panic("m") }
m := map[string]float64{"one": 1.0, "two": 2.0, "pi": 22. / 7.}
if len(m) != 3 {
panic("m")
}
eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)})
p1 := NewP(1, 2)
p2 := NewP(1, 2)
if p1 == p2 { panic("NewP") }
if p1 == p2 {
panic("NewP")
}
}

View File

@ -6,76 +6,77 @@
package main
type I interface {}
type I interface{}
const (
// assume all types behave similarly to int8/uint8
Int8 int8 = 101
Minus1 int8 = -1
Uint8 uint8 = 102
Const = 103
Int8 int8 = 101
Minus1 int8 = -1
Uint8 uint8 = 102
Const = 103
Float32 float32 = 104.5
Float float = 105.5
Float32 float32 = 104.5
Float64 float64 = 105.5
ConstFloat = 106.5
Big float64 = 1e300
Big float64 = 1e300
String = "abc"
Bool = true
Bool = true
)
var (
a1 = Int8 * 100 // ERROR "overflow"
a2 = Int8 * -1 // OK
a3 = Int8 * 1000 // ERROR "overflow"
a4 = Int8 * int8(1000) // ERROR "overflow"
a5 = int8(Int8 * 1000) // ERROR "overflow"
a6 = int8(Int8 * int8(1000)) // ERROR "overflow"
a7 = Int8 - 2*Int8 - 2*Int8 // ERROR "overflow"
a8 = Int8 * Const / 100 // ERROR "overflow"
a9 = Int8 * (Const / 100) // OK
a1 = Int8 * 100 // ERROR "overflow"
a2 = Int8 * -1 // OK
a3 = Int8 * 1000 // ERROR "overflow"
a4 = Int8 * int8(1000) // ERROR "overflow"
a5 = int8(Int8 * 1000) // ERROR "overflow"
a6 = int8(Int8 * int8(1000)) // ERROR "overflow"
a7 = Int8 - 2*Int8 - 2*Int8 // ERROR "overflow"
a8 = Int8 * Const / 100 // ERROR "overflow"
a9 = Int8 * (Const / 100) // OK
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"
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"

View File

@ -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"

View File

@ -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()

View File

@ -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
}
}

View File

@ -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)
}
}

View File

@ -7,7 +7,9 @@
package main
type (
Point struct { x, y float };
Point struct {
x, y float64
}
Polar Point
)

View File

@ -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))
}
/*

View File

@ -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>INT32

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}
/*

View File

@ -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
}
/*

View File

@ -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 }
*/

View File

@ -7,10 +7,10 @@
package main
func main() {
s := uint(10);
ss := 1<<s;
y1 := float(ss);
y2 := float(1<<s); // ERROR "shift"
y3 := string(1<<s); // ERROR "shift"
_, _, _, _, _ = s, ss, y1, y2, y3;
s := uint(10)
ss := 1 << s
y1 := float64(ss)
y2 := float64(1 << s) // ERROR "shift"
y3 := string(1 << s) // ERROR "shift"
_, _, _, _, _ = s, ss, y1, y2, y3
}

View File

@ -7,8 +7,8 @@
package main
func main() {
m := make(map[int]map[uint]float);
m[0] = make(map[uint]float), false; // 6g used to reject this
m[1] = nil;
m := make(map[int]map[uint]float64)
m[0] = make(map[uint]float64), false // 6g used to reject this
m[1] = nil
}

View File

@ -8,14 +8,17 @@ package main
type S string
type I int
type F float
type F float64
func (S) m() {}
func (I) m() {}
func (F) m() {}
func main() {
c := make(chan interface { m() }, 10)
c := make(chan interface {
m()
},
10)
c <- I(0)
c <- F(1)
c <- S("hi")

View File

@ -17,6 +17,6 @@ const f struct{} = 6 // ERROR "convert|wrong|invalid"
const g interface{} = 7 // ERROR "constant|wrong|invalid"
const h bool = false
const i int = 2
const j float = 5
const j float64 = 5
func main() { println(a, b, c, d, e, f, g) }

View File

@ -23,7 +23,7 @@ type t0 int
func (t0) M(p0.T) {}
type t1 float
type t1 float64
func (t1) M(p1.T) {}

View File

@ -26,7 +26,7 @@ type t0 int
func (t0) M(p0.T) {}
// t1 satisfies I1 and p1.I
type t1 float
type t1 float64
func (t1) M(p1.T) {}

View File

@ -11,9 +11,9 @@ type T struct {
x int
y (int)
int
*float
*float64
// not legal according to spec
(complex) // ERROR "non-declaration|expected|parenthesize"
(complex128) // ERROR "non-declaration|expected|parenthesize"
(*string) // ERROR "non-declaration|expected|parenthesize"
*(bool) // ERROR "non-declaration|expected|parenthesize"
}

View File

@ -5,11 +5,11 @@
// license that can be found in the LICENSE file.
// Valid program, gccgo reported an error.
// bug307.go:14:6: error: cmplx arguments must have identical types
// bug307.go:14:6: error: complex arguments must have identical types
package main
func main() {
var f float64
_ = cmplx(1 / f, 0)
_ = complex(1/f, 0)
}

View File

@ -9,7 +9,7 @@
package main
func main() {
a := cmplx(2, 2)
a := complex(2, 2)
a /= 2
}

View File

@ -9,7 +9,7 @@
package main
const (
c = cmplx(1, 2)
c = complex(1, 2)
r = real(c) // was: const initializer must be constant
i = imag(c) // was: const initializer must be constant
)

View File

@ -21,10 +21,10 @@ func f2(a int) {
}
func f3(a, b int) int {
return a+b
return a + b
}
func f4(a, b int, c float) int {
func f4(a, b int, c float32) int {
return (a+b)/2 + int(c)
}
@ -36,12 +36,12 @@ func f6(a int) (r int) {
return 6
}
func f7(a int) (x int, y float) {
func f7(a int) (x int, y float32) {
return 7, 7.0
}
func f8(a int) (x int, y float) {
func f8(a int) (x int, y float32) {
return 8, 8.0
}
@ -49,12 +49,12 @@ type T struct {
x, y int
}
func (t *T) m10(a int, b float) int {
return (t.x+a) * (t.y+int(b))
func (t *T) m10(a int, b float32) int {
return (t.x + a) * (t.y + int(b))
}
func f9(a int) (i int, f float) {
func f9(a int) (i int, f float32) {
i = 9
f = 9.0
return

Some files were not shown because too many files have changed in this diff Show More