2012-03-07 06:54:39 +00:00
|
|
|
// run cmplxdivide1.go
|
2010-06-18 22:46:00 +00:00
|
|
|
|
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Driver for complex division table defined in cmplxdivide1.go
|
2015-01-14 23:43:04 +00:00
|
|
|
// For details, see the comment at the top of in cmplxdivide.c.
|
2010-06-18 22:46:00 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math"
|
2011-11-08 23:43:02 +00:00
|
|
|
"math/cmplx"
|
2010-06-18 22:46:00 +00:00
|
|
|
)
|
|
|
|
|
2011-11-08 23:43:02 +00:00
|
|
|
type Test struct {
|
|
|
|
f, g complex128
|
|
|
|
out complex128
|
2010-06-18 22:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var nan = math.NaN()
|
|
|
|
var inf = math.Inf(1)
|
|
|
|
var negzero = math.Copysign(0, -1)
|
|
|
|
|
|
|
|
func calike(a, b complex128) bool {
|
|
|
|
switch {
|
2011-11-08 23:43:02 +00:00
|
|
|
case cmplx.IsInf(a) && cmplx.IsInf(b):
|
2010-06-18 22:46:00 +00:00
|
|
|
return true
|
2011-11-08 23:43:02 +00:00
|
|
|
case cmplx.IsNaN(a) && cmplx.IsNaN(b):
|
2010-06-18 22:46:00 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return a == b
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2010-07-20 12:53:16 +00:00
|
|
|
bad := false
|
2010-06-18 22:46:00 +00:00
|
|
|
for _, t := range tests {
|
2011-11-08 23:43:02 +00:00
|
|
|
x := t.f / t.g
|
2010-06-18 22:46:00 +00:00
|
|
|
if !calike(x, t.out) {
|
2010-07-20 12:53:16 +00:00
|
|
|
if !bad {
|
|
|
|
fmt.Printf("BUG\n")
|
|
|
|
bad = true
|
|
|
|
}
|
2010-06-18 22:46:00 +00:00
|
|
|
fmt.Printf("%v/%v: expected %v error; got %v\n", t.f, t.g, t.out, x)
|
|
|
|
}
|
|
|
|
}
|
2013-02-12 18:17:49 +00:00
|
|
|
if bad {
|
|
|
|
panic("cmplxdivide failed.")
|
|
|
|
}
|
2010-06-18 22:46:00 +00:00
|
|
|
}
|