1// run cmplxdivide1.go
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// Driver for complex division table defined in cmplxdivide1.go
8
9package main
10
11import (
12	"fmt"
13	"math"
14	"math/cmplx"
15)
16
17type Test struct {
18	f, g complex128
19	out  complex128
20}
21
22var nan = math.NaN()
23var inf = math.Inf(1)
24var negzero = math.Copysign(0, -1)
25
26func calike(a, b complex128) bool {
27	switch {
28	case cmplx.IsInf(a) && cmplx.IsInf(b):
29		return true
30	case cmplx.IsNaN(a) && cmplx.IsNaN(b):
31		return true
32	}
33	return a == b
34}
35
36func main() {
37	bad := false
38	for _, t := range tests {
39		x := t.f / t.g
40		if !calike(x, t.out) {
41			if !bad {
42				fmt.Printf("BUG\n")
43				bad = true
44			}
45			fmt.Printf("%v/%v: expected %v error; got %v\n", t.f, t.g, t.out, x)
46		}
47	}
48	if bad {
49		panic("cmplxdivide failed.")
50	}
51}
52