github.com/karrick/go@v0.0.0-20170817181416-d5b0ec858b37/test/cmplxdivide.go (about) 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 // For details, see the comment at the top of cmplxdivide.c. 9 10 package main 11 12 import ( 13 "fmt" 14 "math" 15 ) 16 17 func calike(a, b complex128) bool { 18 if imag(a) != imag(b) && !(math.IsNaN(imag(a)) && math.IsNaN(imag(b))) { 19 return false 20 } 21 22 if real(a) != real(b) && !(math.IsNaN(real(a)) && math.IsNaN(real(b))) { 23 return false 24 } 25 26 return true 27 } 28 29 func main() { 30 bad := false 31 for _, t := range tests { 32 x := t.f / t.g 33 if !calike(x, t.out) { 34 if !bad { 35 fmt.Printf("BUG\n") 36 bad = true 37 } 38 fmt.Printf("%v/%v: expected %v error; got %v\n", t.f, t.g, t.out, x) 39 } 40 } 41 if bad { 42 panic("cmplxdivide failed.") 43 } 44 }