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