1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // gcc '-std=c99' cmplxdivide.c && a.out >cmplxdivide1.go
12 #define nelem(x) (sizeof(x)/sizeof((x)[0]))
27 static char buf[10][30];
35 if(strcmp(p, "-0") == 0)
41 iscnan(double complex d)
43 return !isinf(creal(d)) && !isinf(cimag(d)) && (isnan(creal(d)) || isnan(cimag(d)));
46 double complex zero; // attempt to hide zero division from gcc
52 double complex n, d, q;
54 printf("// # generated by cmplxdivide.c\n");
56 printf("package main\n");
57 printf("var tests = []Test{\n");
58 for(i=0; i<nelem(f); i++)
59 for(j=0; j<nelem(f); j++)
60 for(k=0; k<nelem(f); k++)
61 for(l=0; l<nelem(f); l++) {
67 // Gcc gets the wrong answer for NaN/0 unless both sides are NaN.
68 // That is, it treats (NaN+NaN*I)/0 = NaN+NaN*I (a complex NaN)
69 // but it then computes (1+NaN*I)/0 = Inf+NaN*I (a complex infinity).
70 // Since both numerators are complex NaNs, it seems that the
71 // results should agree in kind. Override the gcc computation in this case.
72 if(iscnan(n) && d == 0)
73 q = (NAN+NAN*I) / zero;
75 printf("\tTest{complex(%s, %s), complex(%s, %s), complex(%s, %s)},\n",
76 fmt(creal(n)), fmt(cimag(n)),
77 fmt(creal(d)), fmt(cimag(d)),
78 fmt(creal(q)), fmt(cimag(q)));