OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [ken/] [cplx4.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $G $D/$F.go && $L $F.$A && ./$A.out
2
 
3
// Copyright 2010 The Go Authors. All rights reserved.
4
// Use of this source code is governed by a BSD-style
5
// license that can be found in the LICENSE file.
6
 
7
package main
8
 
9
import "fmt"
10
 
11
const (
12
        R = 5
13
        I = 6i
14
 
15
        C1 = R + I // ADD(5,6)
16
)
17
 
18
func want(s, w string) {
19
        if s != w {
20
                panic(s + " != " + w)
21
        }
22
}
23
 
24
func doprint(c complex128, w string) {
25
        s := fmt.Sprintf("%f", c)
26
        want(s, w)
27
}
28
 
29
func main() {
30
 
31
        // constants
32
        s := fmt.Sprintf("%f", -C1)
33
        want(s, "(-5.000000-6.000000i)")
34
        doprint(C1, "(5.000000+6.000000i)")
35
 
36
        // variables
37
        c1 := C1
38
        s = fmt.Sprintf("%f", c1)
39
        want(s, "(5.000000+6.000000i)")
40
        doprint(c1, "(5.000000+6.000000i)")
41
 
42
        // 128
43
        c2 := complex128(C1)
44
        s = fmt.Sprintf("%G", c2)
45
        want(s, "(5+6i)")
46
 
47
        // real, imag, complex
48
        c3 := complex(real(c2)+3, imag(c2)-5) + c2
49
        s = fmt.Sprintf("%G", c3)
50
        want(s, "(13+7i)")
51
 
52
        // compiler used to crash on nested divide
53
        c4 := complex(real(c3/2), imag(c3/2))
54
        if c4 != c3/2 {
55
                fmt.Printf("BUG: c3 = %G != c4 = %G\n", c3, c4)
56
                panic(0)
57
        }
58
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.