Russ Cox | 21ff75b | 2010-06-18 15:46:00 -0700 | [diff] [blame] | 1 | // $G $D/$F.go $D/cmplxdivide1.go && $L $D/$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 | // Driver for complex division table defined in cmplxdivide1.go |
| 8 | |
| 9 | package main |
| 10 | |
| 11 | import ( |
| 12 | "cmath" |
| 13 | "fmt" |
| 14 | "math" |
| 15 | ) |
| 16 | |
| 17 | type Test struct{ |
| 18 | f, g complex128 |
| 19 | out complex128 |
| 20 | } |
| 21 | |
| 22 | var nan = math.NaN() |
| 23 | var inf = math.Inf(1) |
| 24 | var negzero = math.Copysign(0, -1) |
| 25 | |
| 26 | func calike(a, b complex128) bool { |
| 27 | switch { |
| 28 | case cmath.IsInf(a) && cmath.IsInf(b): |
| 29 | return true |
| 30 | case cmath.IsNaN(a) && cmath.IsNaN(b): |
| 31 | return true |
| 32 | } |
| 33 | return a == b |
| 34 | } |
| 35 | |
| 36 | func main() { |
Kai Backman | 36057e7 | 2010-07-20 15:53:16 +0300 | [diff] [blame] | 37 | bad := false |
Russ Cox | 21ff75b | 2010-06-18 15:46:00 -0700 | [diff] [blame] | 38 | for _, t := range tests { |
| 39 | x := t.f/t.g |
| 40 | if !calike(x, t.out) { |
Kai Backman | 36057e7 | 2010-07-20 15:53:16 +0300 | [diff] [blame] | 41 | if !bad { |
| 42 | fmt.Printf("BUG\n") |
| 43 | bad = true |
| 44 | } |
Russ Cox | 21ff75b | 2010-06-18 15:46:00 -0700 | [diff] [blame] | 45 | fmt.Printf("%v/%v: expected %v error; got %v\n", t.f, t.g, t.out, x) |
| 46 | } |
| 47 | } |
| 48 | } |