2012-03-06 23:54:39 -07:00
|
|
|
// run cmplxdivide1.go
|
2010-06-18 16:46:00 -06:00
|
|
|
|
2016-04-10 15:32:26 -06:00
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
2010-06-18 16:46:00 -06:00
|
|
|
// 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 16:43:04 -07:00
|
|
|
// For details, see the comment at the top of in cmplxdivide.c.
|
2010-06-18 16:46:00 -06:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math"
|
2011-11-08 16:43:02 -07:00
|
|
|
"math/cmplx"
|
2010-06-18 16:46:00 -06:00
|
|
|
)
|
|
|
|
|
2011-11-08 16:43:02 -07:00
|
|
|
type Test struct {
|
|
|
|
f, g complex128
|
|
|
|
out complex128
|
2010-06-18 16:46:00 -06: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 16:43:02 -07:00
|
|
|
case cmplx.IsInf(a) && cmplx.IsInf(b):
|
2010-06-18 16:46:00 -06:00
|
|
|
return true
|
2011-11-08 16:43:02 -07:00
|
|
|
case cmplx.IsNaN(a) && cmplx.IsNaN(b):
|
2010-06-18 16:46:00 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return a == b
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2010-07-20 06:53:16 -06:00
|
|
|
bad := false
|
2010-06-18 16:46:00 -06:00
|
|
|
for _, t := range tests {
|
2011-11-08 16:43:02 -07:00
|
|
|
x := t.f / t.g
|
2010-06-18 16:46:00 -06:00
|
|
|
if !calike(x, t.out) {
|
2010-07-20 06:53:16 -06:00
|
|
|
if !bad {
|
|
|
|
fmt.Printf("BUG\n")
|
|
|
|
bad = true
|
|
|
|
}
|
2010-06-18 16:46:00 -06:00
|
|
|
fmt.Printf("%v/%v: expected %v error; got %v\n", t.f, t.g, t.out, x)
|
|
|
|
}
|
|
|
|
}
|
2013-02-12 11:17:49 -07:00
|
|
|
if bad {
|
|
|
|
panic("cmplxdivide failed.")
|
|
|
|
}
|
2010-06-18 16:46:00 -06:00
|
|
|
}
|