Added MACS source
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / complex / test.c
1 /* complex/test.c
2  * 
3  * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or (at
8  * your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #include <config.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <gsl/gsl_ieee_utils.h>
24 #include <gsl/gsl_test.h>
25 #include <gsl/gsl_math.h>
26 #include <gsl/gsl_complex.h>
27 #include <gsl/gsl_complex_math.h>
28
29 struct f
30 {
31   char *name;
32   double (*f) (gsl_complex z);
33   double x;
34   double y;
35   double fx;
36   double fy;
37 };
38
39 struct fz
40 {
41   char *name;
42   gsl_complex (*f) (gsl_complex z);
43   double x;
44   double y;
45   double fx;
46   double fy;
47 };
48
49 struct fzz
50 {
51   char *name;
52   gsl_complex (*f) (gsl_complex z1, gsl_complex z2);
53   double x1;
54   double y1;
55   double x2;
56   double y2;
57   double fx;
58   double fy;
59 };
60
61
62 struct freal
63 {
64   char *name;
65   gsl_complex (*f) (double x);
66   double x;
67   double fx;
68   double fy;
69 };
70
71
72 #define FN(x) "gsl_complex_" #x, gsl_complex_ ## x
73 #define ARG(x,y) x, y
74 #define RES(x,y) x, y
75
76 struct f list[] =
77 {
78 #include "results1.h"
79   {"", 0, 0, 0, 0, 0}
80 };
81
82
83 struct fz listz[] =
84 {
85 #include "results.h"
86   {"", 0, 0, 0, 0, 0}
87 };
88
89 struct fzz listzz[] =
90 {
91   {FN (pow), ARG(0.0,0.0), ARG(0.0,0.0), RES(1.0, 0.0)},
92 #include "results2.h"
93   {"", 0, 0, 0, 0, 0, 0, 0}
94 };
95
96 struct freal listreal[] =
97 {
98 #include "results_real.h"
99   {"", 0, 0, 0, 0}
100 };
101
102 #ifndef TEST_FACTOR
103 #ifdef RELEASED
104 #define TEST_FACTOR 100.0  
105 #else
106 #define TEST_FACTOR 1.0
107 #endif
108 #endif
109
110 int
111 main (void)
112 {
113   size_t i = 0;
114   const double tol = TEST_FACTOR * 10 * GSL_DBL_EPSILON;
115   const double tolf = TEST_FACTOR * 10 * GSL_FLT_EPSILON;
116
117   gsl_ieee_env_setup();
118
119
120   for (i = 0 ; i < 10; i++) 
121     {
122       double r = (i - 5.0) * 0.3 ;
123       double t = 2.0 * M_PI * i / 5 ;
124       double x = r * cos(t), y = r * sin(t) ;
125       gsl_complex z = gsl_complex_polar (r, t) ;
126       gsl_test_rel (GSL_REAL(z), x, tol, "gsl_complex_polar real part at (r=%g,t=%g)", r, t);
127       gsl_test_rel (GSL_IMAG(z), y, tol, "gsl_complex_polar imag part at (r=%g,t=%g)", r, t);
128     }
129     
130     i = 0;
131
132   while (list[i].f)
133     {
134       struct f t = list[i];
135       gsl_complex z = gsl_complex_rect (t.x, t.y);
136       double f = (t.f) (z);
137       gsl_test_rel (f, t.fx, tol, "%s at (%g,%g)", t.name, t.x, t.y);
138       i++;
139     }
140
141   i = 0;
142
143   while (listz[i].f)
144     {
145       struct fz t = listz[i];
146       gsl_complex z = gsl_complex_rect (t.x, t.y);
147       gsl_complex fz = (t.f) (z);
148       double fx = GSL_REAL (fz), fy = GSL_IMAG (fz);
149
150 #ifdef DEBUG
151       printf("x = "); gsl_ieee_fprintf_double (stdout, &t.x); printf("\n");
152       printf("y = "); gsl_ieee_fprintf_double (stdout, &t.y); printf("\n");
153       printf("fx = "); gsl_ieee_fprintf_double (stdout, &fx); printf("\n");
154       printf("ex = "); gsl_ieee_fprintf_double (stdout, &t.fx); printf("\n");
155       printf("fy = "); gsl_ieee_fprintf_double (stdout, &fy); printf("\n");
156       printf("ey = "); gsl_ieee_fprintf_double (stdout, &t.fy); printf("\n");
157 #endif
158
159       gsl_test_rel (fx, t.fx, tol, "%s real part at (%g,%g)", t.name, t.x, t.y);
160       gsl_test_rel (fy, t.fy, tol, "%s imag part at (%g,%g)", t.name, t.x, t.y);
161       i++;
162     }
163
164   i = 0;
165
166   while (listzz[i].f)
167     {
168       struct fzz t = listzz[i];
169       gsl_complex z1 = gsl_complex_rect (t.x1, t.y1);
170       gsl_complex z2 = gsl_complex_rect (t.x2, t.y2);
171       gsl_complex fz = (t.f) (z1, z2);
172       double fx = GSL_REAL (fz), fy = GSL_IMAG (fz);
173
174 #ifdef DEBUG
175       printf("x1 = "); gsl_ieee_fprintf_double (stdout, &t.x1); printf("\n");
176       printf("y1 = "); gsl_ieee_fprintf_double (stdout, &t.y1); printf("\n");
177       printf("x2 = "); gsl_ieee_fprintf_double (stdout, &t.x2); printf("\n");
178       printf("y2 = "); gsl_ieee_fprintf_double (stdout, &t.y2); printf("\n");
179       printf("fx = "); gsl_ieee_fprintf_double (stdout, &fx); printf("\n");
180       printf("ex = "); gsl_ieee_fprintf_double (stdout, &t.fx); printf("\n");
181       printf("fy = "); gsl_ieee_fprintf_double (stdout, &fy); printf("\n");
182       printf("ey = "); gsl_ieee_fprintf_double (stdout, &t.fy); printf("\n");
183 #endif
184
185       gsl_test_rel (fx, t.fx, tolf, "%s real part at (%g,%g;%g,%g)", t.name, t.x1, t.y1, t.x2, t.y2);
186       gsl_test_rel (fy, t.fy, tolf, "%s imag part at (%g,%g;%g,%g)", t.name, t.x1, t.y1, t.x2, t.y2);
187       i++;
188     }
189
190
191   i = 0;
192
193   while (listreal[i].f)
194     {
195       struct freal t = listreal[i];
196       gsl_complex fz = (t.f) (t.x);
197       double fx = GSL_REAL (fz), fy = GSL_IMAG (fz);
198
199 #ifdef DEBUG
200       printf("x = "); gsl_ieee_fprintf_double (stdout, &t.x); printf("\n");
201       printf("fx = "); gsl_ieee_fprintf_double (stdout, &fx); printf("\n");
202       printf("ex = "); gsl_ieee_fprintf_double (stdout, &t.fx); printf("\n");
203       printf("fy = "); gsl_ieee_fprintf_double (stdout, &fy); printf("\n");
204       printf("ey = "); gsl_ieee_fprintf_double (stdout, &t.fy); printf("\n");
205 #endif
206
207       gsl_test_rel (fx, t.fx, tol, "%s real part at (%g,0)", t.name, t.x);
208       gsl_test_rel (fy, t.fy, tol, "%s imag part at (%g,0)", t.name, t.x);
209       i++;
210     }
211
212   exit (gsl_test_summary ());
213 }