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 // This C program generates the file cmplxdivide1.go. It uses the
6 // output of the operations by C99 as the reference to check
7 // the implementation of complex numbers in Go.
8 // The generated file, cmplxdivide1.go, is compiled along
9 // with the driver cmplxdivide.go (the names are confusing
10 // and unimaginative) to run the actual test. This is done by
11 // the usual test runner.
13 // The file cmplxdivide1.go is checked in to the repository, but
14 // if it needs to be regenerated, compile and run this C program
16 // gcc '-std=c99' cmplxdivide.c && a.out >cmplxdivide1.go
23 #define nelem(x) (sizeof(x)/sizeof((x)[0]))
37 static char buf[10][30];
48 if(strcmp(p, "0") == 0) {
53 if(strcmp(p, "-0") == 0) {
63 double complex n, d, q;
66 printf("// # generated by cmplxdivide.c\n");
68 printf("package main\n");
70 printf("import \"math\"\n");
73 printf("\tnan = math.NaN()\n");
74 printf("\tinf = math.Inf(1)\n");
75 printf("\tzero = 0.0\n");
78 printf("var tests = []struct {\n");
79 printf("\tf, g complex128\n");
80 printf("\tout complex128\n");
83 for(i=0; i<nelem(f); i++)
84 for(j=0; j<nelem(f); j++)
85 for(k=0; k<nelem(f); k++)
86 for(l=0; l<nelem(f); l++) {
91 printf("\t{complex(%s, %s), complex(%s, %s), complex(%s, %s)},\n",
92 fmt(creal(n)), fmt(cimag(n)),
93 fmt(creal(d)), fmt(cimag(d)),
94 fmt(creal(q)), fmt(cimag(q)));