]> Cypherpunks.ru repositories - gostls13.git/blob - test/cmplxdivide.c
complex divide: match C99 implementation
[gostls13.git] / test / cmplxdivide.c
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.
4
5 // gcc '-std=c99' cmplxdivide.c && a.out >cmplxdivide1.go
6
7 #include <complex.h>
8 #include <math.h>
9 #include <stdio.h>
10 #include <string.h>
11
12 #define nelem(x) (sizeof(x)/sizeof((x)[0]))
13
14 double f[] = {
15         0,
16         1,
17         -1,
18         2,
19         NAN,
20         INFINITY,
21         -INFINITY,
22 };
23
24 char*
25 fmt(double g)
26 {
27         static char buf[10][30];
28         static int n;
29         char *p;
30         
31         p = buf[n++];
32         if(n == 10)
33                 n = 0;
34         sprintf(p, "%g", g);
35         if(strcmp(p, "-0") == 0)
36                 strcpy(p, "negzero");
37         return p;
38 }       
39
40 int
41 main(void)
42 {
43         int i, j, k, l;
44         double complex n, d, q;
45         
46         printf("// # generated by cmplxdivide.c\n");
47         printf("\n");
48         printf("package main\n");
49         printf("var tests = []Test{\n");
50         for(i=0; i<nelem(f); i++)
51         for(j=0; j<nelem(f); j++)
52         for(k=0; k<nelem(f); k++)
53         for(l=0; l<nelem(f); l++) {
54                 n = f[i] + f[j]*I;
55                 d = f[k] + f[l]*I;
56                 q = n/d;
57                 printf("\tTest{cmplx(%s, %s), cmplx(%s, %s), cmplx(%s, %s)},\n", fmt(creal(n)), fmt(cimag(n)), fmt(creal(d)), fmt(cimag(d)), fmt(creal(q)), fmt(cimag(q)));
58         }
59         printf("}\n");
60         return 0;
61 }