if(!explicit && !isideal(n->type))
return;
-//dump("convlit1", n);
if(n->op == OLITERAL) {
nn = nod(OXXX, N, N);
*nn = *n;
n = nn;
*np = n;
}
-//dump("convlit2", n);
switch(n->op) {
default:
goto bad;
case CTFLT:
case CTINT:
+ if(explicit)
+ goto bad;
n->val = tocplx(n->val);
break;
case CTCPLX:
cgen(&n1, &n3);
cgen(&n2, &n4);
break;
-
- // these are depricated
- case CASE(TFLOAT32,TCOMPLEX64):
- case CASE(TFLOAT32,TCOMPLEX128):
- case CASE(TFLOAT64,TCOMPLEX64):
- case CASE(TFLOAT64,TCOMPLEX128):
- // float to complex goes to real part
-
- subnode(&n1, &n2, t);
- cgen(f, &n1);
- zero(&n2);
- break;
}
}
{
int a;
- if(issimple[t->etype] || isptr[t->etype] || t->etype == TCHAN || t->etype == TFUNC || t->etype == TMAP)
+ if(issimple[t->etype] || isptr[t->etype] || iscomplex[t->etype] ||
+ t->etype == TCHAN || t->etype == TFUNC || t->etype == TMAP)
a = AMEM; // just bytes (int, ptr, etc)
else if(t->etype == TSTRING)
a = ASTRING; // string
{
Type *t;
+
if(key != nil && key->etype != TANY && algtype(key) == ANOEQ) {
if(key->etype == TFORW) {
// map[key] used during definition of key.
return 1;
}
- // simple fix-float-complex
- if(isint[t->etype] || isfloat[t->etype] || iscomplex[t->etype])
- if(isint[nt->etype] || isfloat[nt->etype] || iscomplex[nt->etype])
+ // simple fix-float
+ if(isint[t->etype] || isfloat[t->etype])
+ if(isint[nt->etype] || isfloat[nt->etype])
+ return 1;
+
+ // simple complex-complex
+ if(iscomplex[t->etype])
+ if(iscomplex[nt->etype])
return 1;
// to string
func main() {
c0 := C1
- c0 = (c0+c0+c0) / (c0+c0+3i)
+ c0 = (c0 + c0 + c0) / (c0 + c0 + 3i)
println(c0)
c := *(*complex)(unsafe.Pointer(&c0))
switch c := reflect.NewValue(a).(type) {
case *reflect.Complex64Value:
v := c.Get()
- _,_ = complex64(v), true
+ _, _ = complex64(v), true
case *reflect.ComplexValue:
if complexBits == 64 {
v := c.Get()
- _,_ = complex64(v), true
+ _, _ = complex64(v), true
}
}
}
C1 = R + I // ADD(5,6)
)
-func doprint(c complex) {
- fmt.Printf("c = %f\n", c)
-}
+func doprint(c complex) { fmt.Printf("c = %f\n", c) }
func main() {
--- /dev/null
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+var a [12]complex
+var s []complex
+var c chan complex
+var f struct {
+ c complex
+}
+var m map[complex]complex
+
+func main() {
+ // array of complex
+ for i := 0; i < len(a); i++ {
+ a[i] = cmplx(float(i), float(-i))
+ }
+ println(a[5])
+
+ // slice of complex
+ s = make([]complex, len(a))
+ for i := 0; i < len(s); i++ {
+ s[i] = a[i]
+ }
+ println(s[5])
+
+ // chan
+ c = make(chan complex)
+ go chantest(c)
+ println(<-c)
+
+ // pointer of complex
+ v := a[5]
+ pv := &v
+ println(*pv)
+
+ // field of complex
+ f.c = a[5]
+ println(f.c)
+
+ // map of complex
+ m = make(map[complex]complex)
+ for i := 0; i < len(s); i++ {
+ m[-a[i]] = a[i]
+ }
+ println(m[5i-5])
+ println(m[cmplx(-5, 5)])
+}
+
+func chantest(c chan complex) { c <- a[5] }