Source file
test/ken/cplx3.go
1
2
3
4
5
6
7
8
9 package main
10
11 import "unsafe"
12 import "reflect"
13
14 const (
15 R = 5
16 I = 6i
17
18 C1 = R + I
19 )
20
21 func main() {
22 c0 := C1
23 c0 = (c0 + c0 + c0) / (c0 + c0 + 3i)
24 r, i := real(c0), imag(c0)
25 d := r - 1.292308
26 if d < 0 {
27 d = - d
28 }
29 if d > 1e-6 {
30 println(r, "!= 1.292308")
31 panic(0)
32 }
33 d = i + 0.1384615
34 if d < 0 {
35 d = - d
36 }
37 if d > 1e-6 {
38 println(i, "!= -0.1384615")
39 panic(0)
40 }
41
42 c := *(*complex128)(unsafe.Pointer(&c0))
43 if c != c0 {
44 println(c, "!=", c)
45 panic(0)
46 }
47
48 var a interface{}
49 switch c := reflect.ValueOf(a); c.Kind() {
50 case reflect.Complex64, reflect.Complex128:
51 v := c.Complex()
52 _, _ = complex128(v), true
53 }
54 }
55
View as plain text