3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
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.
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.
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.
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>
32 double (*f) (gsl_complex z);
42 gsl_complex (*f) (gsl_complex z);
52 gsl_complex (*f) (gsl_complex z1, gsl_complex z2);
65 gsl_complex (*f) (double x);
72 #define FN(x) "gsl_complex_" #x, gsl_complex_ ## x
91 {FN (pow), ARG(0.0,0.0), ARG(0.0,0.0), RES(1.0, 0.0)},
93 {"", 0, 0, 0, 0, 0, 0, 0}
96 struct freal listreal[] =
98 #include "results_real.h"
104 #define TEST_FACTOR 100.0
106 #define TEST_FACTOR 1.0
114 const double tol = TEST_FACTOR * 10 * GSL_DBL_EPSILON;
115 const double tolf = TEST_FACTOR * 10 * GSL_FLT_EPSILON;
117 gsl_ieee_env_setup();
120 for (i = 0 ; i < 10; i++)
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);
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);
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);
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");
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);
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);
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");
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);
193 while (listreal[i].f)
195 struct freal t = listreal[i];
196 gsl_complex fz = (t.f) (t.x);
197 double fx = GSL_REAL (fz), fy = GSL_IMAG (fz);
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");
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);
212 exit (gsl_test_summary ());