Qucs-core  0.0.19
evaluate.cpp
Go to the documentation of this file.
00001 /*
00002  * evaluate.cpp - the Qucs equation evaluator implementations
00003  *
00004  * Copyright (C) 2004-2011 Stefan Jahn <stefan@lkcc.org>
00005  * Copyright (C) 2006 Gunther Kraut <gn.kraut@t-online.de>
00006  *
00007  * This is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2, or (at your option)
00010  * any later version.
00011  *
00012  * This software is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this package; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021  *
00022  * $Id$
00023  *
00024  */
00025 
00026 #if HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029 
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <ctype.h>
00034 #include <cmath>
00035 
00036 #include "logging.h"
00037 #include "complex.h"
00038 #include "object.h"
00039 #include "vector.h"
00040 #include "matrix.h"
00041 #include "poly.h"
00042 #include "spline.h"
00043 #include "fourier.h"
00044 #include "receiver.h"
00045 #include "constants.h"
00046 #include "fspecial.h"
00047 #include "circuit.h"
00048 #include "range.h"
00049 #include "equation.h"
00050 #include "evaluate.h"
00051 #include "exception.h"
00052 #include "exceptionstack.h"
00053 #include "strlist.h"
00054 
00055 using namespace qucs;
00056 using namespace qucs::eqn;
00057 using namespace qucs::fourier;
00058 using namespace fspecial;
00059 
00060 // Short macros in order to obtain the correct constant value.
00061 #define D(con)   ((constant *) (con))->d
00062 #define C(con)   ((constant *) (con))->c
00063 #define V(con)   ((constant *) (con))->v
00064 #define M(con)   ((constant *) (con))->m
00065 #define MV(con)  ((constant *) (con))->mv
00066 #define STR(con) ((constant *) (con))->s
00067 #define CHR(con) ((constant *) (con))->chr
00068 #define INT(con) ((int) D (con))
00069 #define RNG(con) ((constant *) (con))->r
00070 #define B(con)   ((constant *) (con))->b
00071 
00072 #define A(a) ((assignment *) (a))
00073 #define R(r) ((reference *) (r))
00074 
00075 // Argument macros.
00076 #define _ARES(idx) args->getResult(idx)
00077 #define _ARG(idx) args->get(idx)
00078 
00079 #define _D(var,idx) nr_double_t (var) = D (_ARES (idx));
00080 #define _BO(var,idx) bool (var) = B (_ARES (idx));
00081 #define _CX(var,idx) nr_complex_t * (var) = C (_ARES (idx));
00082 #define _V(var,idx) qucs::vector * (var) = V (_ARES (idx));
00083 #define _M(var,idx) matrix * (var) = M (_ARES (idx));
00084 #define _MV(var,idx) matvec * (var) = MV (_ARES (idx));
00085 #define _I(var,idx) int (var) = INT (_ARES (idx));
00086 #define _R(var,idx) range * (var) = RNG (_ARES (idx));
00087 
00088 #define _ARR0(var) _R (var,0)
00089 #define _ARR1(var) _R (var,1)
00090 #define _ARR2(var) _R (var,2)
00091 #define _ARI0(var) _I (var,0)
00092 #define _ARI1(var) _I (var,1)
00093 #define _ARI2(var) _I (var,2)
00094 #define _ARD0(var) _D (var,0)
00095 #define _ARD1(var) _D (var,1)
00096 #define _ARD2(var) _D (var,2)
00097 #define _ARB0(var) _BO (var,0)
00098 #define _ARB1(var) _BO (var,1)
00099 #define _ARB2(var) _BO (var,2)
00100 #define _ARC0(var) _CX (var,0)
00101 #define _ARC1(var) _CX (var,1)
00102 #define _ARC2(var) _CX (var,2)
00103 #define _ARM0(var) _M (var,0)
00104 #define _ARM1(var) _M (var,1)
00105 #define _ARM2(var) _M (var,2)
00106 #define _ARV0(var) _V (var,0)
00107 #define _ARV1(var) _V (var,1)
00108 #define _ARV2(var) _V (var,2)
00109 #define _ARMV0(var) _MV (var,0)
00110 #define _ARMV1(var) _MV (var,1)
00111 #define _ARMV2(var) _MV (var,2)
00112 
00113 // Return value definition macros.
00114 #define _DEFD() constant * res = new constant (TAG_DOUBLE);
00115 #define _DEFB() constant * res = new constant (TAG_BOOLEAN);
00116 #define _DEFC() constant * res = new constant (TAG_COMPLEX);
00117 #define _DEFV() constant * res = new constant (TAG_VECTOR);
00118 #define _DEFM() constant * res = new constant (TAG_MATRIX);
00119 #define _DEFMV() constant * res = new constant (TAG_MATVEC);
00120 #define _DEFR() constant * res = new constant (TAG_RANGE);
00121 
00122 // Return value macros.
00123 #define _RETD(var) res->d = (var); return res;
00124 #define _RETD_QUCS(var) res->d = (qucs::var); return res;
00125 #define _RETD_STD(var) res->d = (std::var); return res;
00126 #define _RETD_SPECIAL(var) res->d = (fspecial::var); return res;
00127 #define _RETB(var) res->b = (var); return res;
00128 #define _RETC(var) res->c = new nr_complex_t (var); return res;
00129 #define _RETV(var) res->v = new qucs::vector (var); return res;
00130 #define _RETM(var) res->m = new matrix (var); return res;
00131 #define _RETMV(var) res->mv = new matvec (var); return res;
00132 #define _RETR(var) res->r = (var); return res;
00133 
00134 // Return value macros without arguments.
00135 #define __RETC() res->c = new nr_complex_t (); return res;
00136 #define __RETV() res->v = new qucs::vector (); return res;
00137 #define __RETM() res->m = new matrix (); return res;
00138 #define __RETMV() res->mv = new matvec (); return res;
00139 
00140 #define SOLVEE(idx) args->get(idx)->solvee
00141 
00142 // Throws a math exception.
00143 #define THROW_MATH_EXCEPTION(txt) do { \
00144   qucs::exception * e = new qucs::exception (EXCEPTION_MATH); \
00145   e->setText (txt); throw_exception (e); } while (0)
00146 
00147 /* The QUCS_CONCAT macros create a new concatenated symbol for the
00148    compiler in a portable way.  It is essential to use these macros
00149    like QUCS_CONCAT (a,b) and *not* like QUCS_CONCAT (a, b) or its
00150    variants. */
00151 #if defined (__STDC__) || defined (__cplusplus)
00152 # define QUCS_CONCAT2(a, b) a##b
00153 # define QUCS_CONCAT3(a, b, c) a##b##c
00154 #else
00155 # define QUCS_CONCAT2(a, b) a/* */b
00156 # define QUCS_CONCAT3(a, b, c) a/* */b/* */c
00157 #endif
00158 
00159 // The following macro is meant to be used for some simple functions.
00160 #define MAKE_FUNC_DEFINITION_0(cfunc) \
00161 constant * evaluate:: QUCS_CONCAT2 (cfunc,_d) (constant * args) { \
00162   _ARD0 (d);                                                      \
00163   _DEFD ();                                                       \
00164   _RETD (cfunc (d));                                              \
00165 }                                                                 \
00166 constant * evaluate:: QUCS_CONCAT2 (cfunc,_c) (constant * args) { \
00167   _ARC0 (c);                                                      \
00168   _DEFC ();                                                       \
00169   _RETC (cfunc (*c));                                             \
00170 }                                                                 \
00171 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v) (constant * args) { \
00172   _ARV0 (v);                                                      \
00173   _DEFV ();                                                       \
00174   _RETV (cfunc (*v));                                             \
00175 }
00176 
00177 // The following macro is meant to be used for some simple functions,
00178 // which must explicitly use the double function from the std namespace
00179 #define MAKE_FUNC_DEFINITION_0_STD(cfunc) \
00180 constant * evaluate:: QUCS_CONCAT2 (cfunc,_d) (constant * args) { \
00181   _ARD0 (d);                                                      \
00182   _DEFD ();                                                       \
00183   _RETD_STD (cfunc (d));                                                  \
00184 }                                                                 \
00185 constant * evaluate:: QUCS_CONCAT2 (cfunc,_c) (constant * args) { \
00186   _ARC0 (c);                                                      \
00187   _DEFC ();                                                       \
00188   _RETC (cfunc (*c));                                             \
00189 }                                                                 \
00190 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v) (constant * args) { \
00191   _ARV0 (v);                                                      \
00192   _DEFV ();                                                       \
00193   _RETV (cfunc (*v));                                             \
00194 }
00195 
00196 // The following macro is meant to be used for some simple functions,
00197 // which must explicitly use the double function from the qucs namespace
00198 #define MAKE_FUNC_DEFINITION_0_QUCS(cfunc) \
00199 constant * evaluate:: QUCS_CONCAT2 (cfunc,_d) (constant * args) { \
00200   _ARD0 (d);                                                      \
00201   _DEFD ();                                                       \
00202   _RETD_QUCS (cfunc (d));                                                 \
00203 }                                                                 \
00204 constant * evaluate:: QUCS_CONCAT2 (cfunc,_c) (constant * args) { \
00205   _ARC0 (c);                                                      \
00206   _DEFC ();                                                       \
00207   _RETC (cfunc (*c));                                             \
00208 }                                                                 \
00209 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v) (constant * args) { \
00210   _ARV0 (v);                                                      \
00211   _DEFV ();                                                       \
00212   _RETV (cfunc (*v));                                             \
00213 }
00214 
00215 // The following macro is meant to be used for some simple functions,
00216 // which must explicitly use the double function from the fspecial namespace
00217 #define MAKE_FUNC_DEFINITION_0_SPECIAL(cfunc) \
00218 constant * evaluate:: QUCS_CONCAT2 (cfunc,_d) (constant * args) { \
00219   _ARD0 (d);                                                      \
00220   _DEFD ();                                                       \
00221   _RETD_SPECIAL (cfunc (d));                                              \
00222 }                                                                 \
00223 constant * evaluate:: QUCS_CONCAT2 (cfunc,_c) (constant * args) { \
00224   _ARC0 (c);                                                      \
00225   _DEFC ();                                                       \
00226   _RETC (cfunc (*c));                                             \
00227 }                                                                 \
00228 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v) (constant * args) { \
00229   _ARV0 (v);                                                      \
00230   _DEFV ();                                                       \
00231   _RETV (cfunc (*v));                                             \
00232 }
00233 
00234 #define MAKE_FUNC_DEFINITION_1(cfunc) \
00235 constant * evaluate:: QUCS_CONCAT2 (cfunc,_d) (constant * args) { \
00236   _ARD0 (d);                                                      \
00237   _DEFD ();                                                       \
00238   _RETD (cfunc (d));                                              \
00239 }                                                                 \
00240 constant * evaluate:: QUCS_CONCAT2 (cfunc,_c) (constant * args) { \
00241   _ARC0 (c);                                                      \
00242   _DEFD ();                                                       \
00243   res->d = cfunc (*c); return res;                                \
00244 }                                                                 \
00245 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v) (constant * args) { \
00246   _ARV0 (v);                                                      \
00247   _DEFV ();                                                       \
00248   _RETV (cfunc (*v));                                             \
00249 }                                                                 \
00250 constant * evaluate:: QUCS_CONCAT2 (cfunc,_m) (constant * args) { \
00251   _ARM0 (m);                                                      \
00252   _DEFM ();                                                       \
00253   _RETM (cfunc (*m));                                             \
00254 }                                                                 \
00255 constant * evaluate:: QUCS_CONCAT2 (cfunc,_mv) (constant * args) {\
00256   _ARMV0 (mv);                                                    \
00257   _DEFMV ();                                                      \
00258   _RETMV (cfunc (*mv));                                           \
00259 }
00260 
00261 MAKE_FUNC_DEFINITION_0 (exp);    // exponential function
00262 MAKE_FUNC_DEFINITION_0 (limexp); // limited exponential function
00263 MAKE_FUNC_DEFINITION_0 (sin);    // sine
00264 MAKE_FUNC_DEFINITION_0 (cos);    // cosine
00265 MAKE_FUNC_DEFINITION_0 (tan);    // tangent
00266 MAKE_FUNC_DEFINITION_0 (sinh);   // sine hyperbolicus
00267 MAKE_FUNC_DEFINITION_0 (cosh);   // cosine hyperbolicus
00268 MAKE_FUNC_DEFINITION_0 (tanh);   // tangent hyperbolicus
00269 MAKE_FUNC_DEFINITION_0_QUCS (coth);   // cotangent hyperbolicus
00270 MAKE_FUNC_DEFINITION_0_QUCS (sech);   // secans hyperbolicus
00271 MAKE_FUNC_DEFINITION_0_QUCS (cosech); // cosecans hyperbolicus
00272 MAKE_FUNC_DEFINITION_0_QUCS (signum); // signum function
00273 MAKE_FUNC_DEFINITION_0_QUCS (sign);   // sign function
00274 MAKE_FUNC_DEFINITION_0_QUCS (sinc);   // sin(x)/x aka sinc function
00275 MAKE_FUNC_DEFINITION_0 (sqr);    // square value
00276 
00277 MAKE_FUNC_DEFINITION_1 (real);   // real value
00278 MAKE_FUNC_DEFINITION_1 (imag);   // imaginary value
00279 MAKE_FUNC_DEFINITION_1 (abs);    // absolute value
00280 
00281 // ******************** unary plus *************************
00282 constant * evaluate::plus_d (constant * args) {
00283   _ARD0 (d1); _DEFD (); _RETD (d1);
00284 }
00285 
00286 constant * evaluate::plus_c (constant * args) {
00287   _ARC0 (c1); _DEFC (); _RETC (*c1);
00288 }
00289 
00290 constant * evaluate::plus_v (constant * args) {
00291   _ARV0 (v1); _DEFV (); _RETV (*v1);
00292 }
00293 
00294 constant * evaluate::plus_m (constant * args) {
00295   _ARM0 (m1); _DEFM (); _RETM (*m1);
00296 }
00297 
00298 constant * evaluate::plus_mv (constant * args) {
00299   _ARMV0 (v1); _DEFMV (); _RETMV (*v1);
00300 }
00301 
00302 // ****************** addition *****************************
00303 constant * evaluate::plus_d_d (constant * args) {
00304   _ARD0 (d1);
00305   _ARD1 (d2);
00306   _DEFD ();
00307   _RETD (d1 + d2);
00308 }
00309 
00310 constant * evaluate::plus_c_c (constant * args) {
00311   _ARC0 (c1);
00312   _ARC1 (c2);
00313   _DEFC ();
00314   _RETC (*c1 + *c2);
00315 }
00316 
00317 constant * evaluate::plus_c_d (constant * args) {
00318   _ARC0 (c1);
00319   _ARD1 (d2);
00320   _DEFC ();
00321   _RETC (*c1 + d2);
00322 }
00323 
00324 constant * evaluate::plus_d_c (constant * args) {
00325   _ARD0 (d1);
00326   _ARC1 (c2);
00327   _DEFC ();
00328   _RETC (d1 + *c2);
00329 }
00330 
00331 constant * evaluate::plus_v_d (constant * args) {
00332   _ARV0 (v1);
00333   _ARD1 (d2);
00334   _DEFV ();
00335   _RETV (*v1 + d2);
00336 }
00337 
00338 constant * evaluate::plus_d_v (constant * args) {
00339   _ARD0 (d1);
00340   _ARV1 (v2);
00341   _DEFV ();
00342   _RETV (d1 + *v2);
00343 }
00344 
00345 constant * evaluate::plus_v_c (constant * args) {
00346   _ARV0 (v1);
00347   _ARC1 (c2);
00348   _DEFV ();
00349   _RETV (*v1 + *c2);
00350 }
00351 
00352 constant * evaluate::plus_c_v (constant * args) {
00353   _ARC0 (c1);
00354   _ARV1 (v2);
00355   _DEFV ();
00356   _RETV (*v2 + *c1);
00357 }
00358 
00359 constant * evaluate::plus_v_v (constant * args) {
00360   _ARV0 (v1);
00361   _ARV1 (v2);
00362   _DEFV ();
00363   _RETV (*v1 + *v2);
00364 }
00365 
00366 constant * evaluate::plus_m_m (constant * args) {
00367   _ARM0 (m1);
00368   _ARM1 (m2);
00369   _DEFM ();
00370   _RETM (*m1 + *m2);
00371 }
00372 
00373 constant * evaluate::plus_mv_mv (constant * args) {
00374   _ARMV0 (v1);
00375   _ARMV1 (v2);
00376   _DEFMV ();
00377   _RETMV (*v1 + *v2);
00378 }
00379 
00380 constant * evaluate::plus_mv_m (constant * args) {
00381   _ARMV0 (v1);
00382   _ARM1 (m2);
00383   _DEFMV ();
00384   _RETMV (*v1 + *m2);
00385 }
00386 
00387 constant * evaluate::plus_m_mv (constant * args) {
00388   _ARM0 (m1);
00389   _ARMV1 (v2);
00390   _DEFMV ();
00391   _RETMV (*m1 + *v2);
00392 }
00393 
00394 constant * evaluate::plus_m_d (constant * args) {
00395   _ARM0 (m1);
00396   _ARD1 (d2);
00397   _DEFM ();
00398   _RETM (*m1 + d2);
00399 }
00400 
00401 constant * evaluate::plus_d_m (constant * args) {
00402   _ARD0 (d1);
00403   _ARM1 (m2);
00404   _DEFM ();
00405   _RETM (d1 + *m2);
00406 }
00407 
00408 constant * evaluate::plus_m_c (constant * args) {
00409   _ARM0 (m1);
00410   _ARC1 (c2);
00411   _DEFM ();
00412   _RETM (*m1 + *c2);
00413 }
00414 
00415 constant * evaluate::plus_c_m (constant * args) {
00416   _ARC0 (c1);
00417   _ARM1 (m2);
00418   _DEFM ();
00419   _RETM (*c1 + *m2);
00420 }
00421 
00422 constant * evaluate::plus_mv_d (constant * args) {
00423   _ARMV0 (m1);
00424   _ARD1  (d2);
00425   _DEFMV ();
00426   _RETMV (*m1 + d2);
00427 }
00428 
00429 constant * evaluate::plus_d_mv (constant * args) {
00430   _ARD0  (d1);
00431   _ARMV1 (m2);
00432   _DEFMV ();
00433   _RETMV (d1 + *m2);
00434 }
00435 
00436 constant * evaluate::plus_mv_c (constant * args) {
00437   _ARMV0 (m1);
00438   _ARC1  (c2);
00439   _DEFMV ();
00440   _RETMV (*m1 + *c2);
00441 }
00442 
00443 constant * evaluate::plus_c_mv (constant * args) {
00444   _ARC0  (c1);
00445   _ARMV1 (m2);
00446   _DEFMV ();
00447   _RETMV (*c1 + *m2);
00448 }
00449 
00450 constant * evaluate::plus_mv_v (constant * args) {
00451   _ARMV0 (m1);
00452   _ARV1  (v2);
00453   _DEFMV ();
00454   _RETMV (*m1 + *v2);
00455 }
00456 
00457 constant * evaluate::plus_v_mv (constant * args) {
00458   _ARV0  (v1);
00459   _ARMV1 (m2);
00460   _DEFMV ();
00461   _RETMV (*v1 + *m2);
00462 }
00463 
00464 constant * evaluate::plus_s_s (constant * args) {
00465   char * s1 = STR (_ARES(0));
00466   char * s2 = STR (_ARES(1));
00467   constant * res = new constant (TAG_STRING);
00468   char * p = (char *) malloc (strlen (s1) + strlen (s2) + 1);
00469   strcpy (p, s1); strcat (p, s2);
00470   res->s = p;
00471   return res;
00472 }
00473 
00474 constant * evaluate::plus_c_s (constant * args) {
00475   char   c1 = CHR (_ARES(0));
00476   char * s2 = STR (_ARES(1));
00477   constant * res = new constant (TAG_STRING);
00478   char * p = (char *) malloc (strlen (s2) + 2);
00479   p[0] = c1; strcpy (&p[1], s2);
00480   res->s = p;
00481   return res;
00482 }
00483 
00484 constant * evaluate::plus_s_c (constant * args) {
00485   char * s1 = STR (_ARES(0));
00486   char   c2 = CHR (_ARES(1));
00487   constant * res = new constant (TAG_STRING);
00488   char * p = (char *) malloc (strlen (s1) + 2);
00489   strcpy (p, s1); p[strlen (s1)] = c2; p[strlen (s1) + 1] = '\0';
00490   res->s = p;
00491   return res;
00492 }
00493 
00494 // ******************** unary minus ***************************
00495 constant * evaluate::minus_d (constant * args) {
00496   _ARD0 (d1); _DEFD (); _RETD (-d1);
00497 }
00498 
00499 constant * evaluate::minus_c (constant * args) {
00500   _ARC0 (c1); _DEFC (); _RETC (-*c1);
00501 }
00502 
00503 constant * evaluate::minus_v (constant * args) {
00504   _ARV0 (v1); _DEFV (); _RETV (-*v1);
00505 }
00506 
00507 constant * evaluate::minus_m (constant * args) {
00508   _ARM0 (m1); _DEFM (); _RETM (-*m1);
00509 }
00510 
00511 constant * evaluate::minus_mv (constant * args) {
00512   _ARMV0 (v1); _DEFMV (); _RETMV (-*v1);
00513 }
00514 
00515 // ****************** subtraction *****************************
00516 constant * evaluate::minus_d_d (constant * args) {
00517   _ARD0 (d1);
00518   _ARD1 (d2);
00519   _DEFD ();
00520   _RETD (d1 - d2);
00521 }
00522 
00523 constant * evaluate::minus_c_c (constant * args) {
00524   _ARC0 (c1);
00525   _ARC1 (c2);
00526   _DEFC ();
00527   _RETC (*c1 - *c2);
00528 }
00529 
00530 constant * evaluate::minus_c_d (constant * args) {
00531   _ARC0 (c1);
00532   _ARD1 (d2);
00533   _DEFC ();
00534   _RETC (*c1 - d2);
00535 }
00536 
00537 constant * evaluate::minus_d_c (constant * args) {
00538   _ARD0 (d1);
00539   _ARC1 (c2);
00540   _DEFC ();
00541   _RETC (d1 - *c2);
00542 }
00543 
00544 constant * evaluate::minus_v_d (constant * args) {
00545   _ARV0 (v1);
00546   _ARD1 (d2);
00547   _DEFV ();
00548   _RETV (*v1 - d2);
00549 }
00550 
00551 constant * evaluate::minus_d_v (constant * args) {
00552   _ARD0 (d1);
00553   _ARV1 (v2);
00554   _DEFV ();
00555   _RETV (d1 - *v2);
00556 }
00557 
00558 constant * evaluate::minus_v_c (constant * args) {
00559   _ARV0 (v1);
00560   _ARC1 (c2);
00561   _DEFV ();
00562   _RETV (*v1 - *c2);
00563 }
00564 
00565 constant * evaluate::minus_c_v (constant * args) {
00566   _ARC0 (c1);
00567   _ARV1 (v2);
00568   _DEFV ();
00569   _RETV (*c1 - *v2);
00570 }
00571 
00572 constant * evaluate::minus_v_v (constant * args) {
00573   _ARV0 (v1);
00574   _ARV1 (v2);
00575   _DEFV ();
00576   _RETV (*v1 - *v2);
00577 }
00578 
00579 constant * evaluate::minus_m_m (constant * args) {
00580   _ARM0 (m1);
00581   _ARM1 (m2);
00582   _DEFM ();
00583   _RETM (*m1 - *m2);
00584 }
00585 
00586 constant * evaluate::minus_mv_mv (constant * args) {
00587   _ARMV0 (v1);
00588   _ARMV1 (v2);
00589   _DEFMV ();
00590   _RETMV (*v1 - *v2);
00591 }
00592 
00593 constant * evaluate::minus_mv_m (constant * args) {
00594   _ARMV0 (v1);
00595   _ARM1 (m2);
00596   _DEFMV ();
00597   _RETMV (*v1 - *m2);
00598 }
00599 
00600 constant * evaluate::minus_m_mv (constant * args) {
00601   _ARM0 (m1);
00602   _ARMV1 (v2);
00603   _DEFMV ();
00604   _RETMV (*m1 - *v2);
00605 }
00606 
00607 constant * evaluate::minus_m_d (constant * args) {
00608   _ARM0 (m1);
00609   _ARD1 (d2);
00610   _DEFM ();
00611   _RETM (*m1 - d2);
00612 }
00613 
00614 constant * evaluate::minus_d_m (constant * args) {
00615   _ARD0 (d1);
00616   _ARM1 (m2);
00617   _DEFM ();
00618   _RETM (d1 - *m2);
00619 }
00620 
00621 constant * evaluate::minus_m_c (constant * args) {
00622   _ARM0 (m1);
00623   _ARC1 (c2);
00624   _DEFM ();
00625   _RETM (*m1 - *c2);
00626 }
00627 
00628 constant * evaluate::minus_c_m (constant * args) {
00629   _ARC0 (c1);
00630   _ARM1 (m2);
00631   _DEFM ();
00632   _RETM (*c1 - *m2);
00633 }
00634 
00635 constant * evaluate::minus_mv_d (constant * args) {
00636   _ARMV0 (m1);
00637   _ARD1  (d2);
00638   _DEFMV ();
00639   _RETMV (*m1 - d2);
00640 }
00641 
00642 constant * evaluate::minus_d_mv (constant * args) {
00643   _ARD0  (d1);
00644   _ARMV1 (m2);
00645   _DEFMV ();
00646   _RETMV (d1 - *m2);
00647 }
00648 
00649 constant * evaluate::minus_mv_c (constant * args) {
00650   _ARMV0 (m1);
00651   _ARC1  (c2);
00652   _DEFMV ();
00653   _RETMV (*m1 - *c2);
00654 }
00655 
00656 constant * evaluate::minus_c_mv (constant * args) {
00657   _ARC0  (c1);
00658   _ARMV1 (m2);
00659   _DEFMV ();
00660   _RETMV (*c1 - *m2);
00661 }
00662 
00663 constant * evaluate::minus_mv_v (constant * args) {
00664   _ARMV0 (m1);
00665   _ARV1  (v2);
00666   _DEFMV ();
00667   _RETMV (*m1 - *v2);
00668 }
00669 
00670 constant * evaluate::minus_v_mv (constant * args) {
00671   _ARV0  (v1);
00672   _ARMV1 (m2);
00673   _DEFMV ();
00674   _RETMV (*v1 - *m2);
00675 }
00676 
00677 // ****************** multiplication *************************
00678 constant * evaluate::times_d_d (constant * args) {
00679   _ARD0 (d1);
00680   _ARD1 (d2);
00681   _DEFD ();
00682   _RETD (d1 * d2);
00683 }
00684 
00685 constant * evaluate::times_c_c (constant * args) {
00686   _ARC0 (c1);
00687   _ARC1 (c2);
00688   _DEFC ();
00689   _RETC ((*c1) * (*c2));
00690 }
00691 
00692 constant * evaluate::times_c_d (constant * args) {
00693   _ARC0 (c1);
00694   _ARD1 (d2);
00695   _DEFC ();
00696   _RETC ((*c1) * d2);
00697 }
00698 
00699 constant * evaluate::times_d_c (constant * args) {
00700   _ARD0 (d1);
00701   _ARC1 (c2);
00702   _DEFC ();
00703   _RETC (d1 * (*c2));
00704 }
00705 
00706 constant * evaluate::times_v_d (constant * args) {
00707   _ARV0 (v1);
00708   _ARD1 (d2);
00709   _DEFV ();
00710   _RETV (*v1 * d2);
00711   return res;
00712 }
00713 
00714 constant * evaluate::times_d_v (constant * args) {
00715   _ARD0 (d1);
00716   _ARV1 (v2);
00717   _DEFV ();
00718   _RETV (d1 * *v2);
00719 }
00720 
00721 constant * evaluate::times_v_c (constant * args) {
00722   _ARV0 (v1);
00723   _ARC1 (c2);
00724   _DEFV ();
00725   _RETV (*v1 * *c2);
00726 }
00727 
00728 constant * evaluate::times_c_v (constant * args) {
00729   _ARC0 (c1);
00730   _ARV1 (v2);
00731   _DEFV ();
00732   _RETV (*c1 * *v2);
00733 }
00734 
00735 constant * evaluate::times_v_v (constant * args) {
00736   _ARV0 (v1);
00737   _ARV1 (v2);
00738   _DEFV ();
00739   _RETV (*v1 * *v2);
00740 }
00741 
00742 constant * evaluate::times_m_m (constant * args) {
00743   _ARM0 (m1);
00744   _ARM1 (m2);
00745   _DEFM ();
00746   if (m1->getCols () != m2->getRows ()) {
00747     THROW_MATH_EXCEPTION ("nonconformant arguments in matrix multiplication");
00748     res->m = new matrix (m1->getRows (), m2->getCols ());
00749   } else {
00750     res->m = new matrix (*m1 * *m2);
00751   }
00752   return res;
00753 }
00754 
00755 constant * evaluate::times_m_c (constant * args) {
00756   _ARM0 (m1);
00757   _ARC1 (c2);
00758   _DEFM ();
00759   _RETM (*m1 * *c2);
00760 }
00761 
00762 constant * evaluate::times_c_m (constant * args) {
00763   _ARC0 (c1);
00764   _ARM1 (m2);
00765   _DEFM ();
00766   _RETM (*c1 * *m2);
00767 }
00768 
00769 constant * evaluate::times_m_d (constant * args) {
00770   _ARM0 (m1);
00771   _ARD1 (d2);
00772   _DEFM ();
00773   _RETM (*m1 * d2);
00774 }
00775 
00776 constant * evaluate::times_d_m (constant * args) {
00777   _ARD0 (d1);
00778   _ARM1 (m2);
00779   _DEFM ();
00780   _RETM (d1 * *m2);
00781 }
00782 
00783 constant * evaluate::times_mv_mv (constant * args) {
00784   _ARMV0 (v1);
00785   _ARMV1 (v2);
00786   _DEFMV ();
00787   if (v1->getCols () != v2->getRows ()) {
00788     THROW_MATH_EXCEPTION ("nonconformant arguments in matrix multiplication");
00789     res->mv = new matvec (v1->getSize (), v1->getRows (), v2->getCols ());
00790   } else {
00791     res->mv = new matvec (*v1 * *v2);
00792   }
00793   return res;
00794 }
00795 
00796 constant * evaluate::times_mv_c (constant * args) {
00797   _ARMV0 (v1);
00798   _ARC1 (c2);
00799   _DEFMV ();
00800   _RETMV (*v1 * *c2);
00801 }
00802 
00803 constant * evaluate::times_c_mv (constant * args) {
00804   _ARC0 (c1);
00805   _ARMV1 (v2);
00806   _DEFMV ();
00807   _RETMV (*c1 * *v2);
00808 }
00809 
00810 constant * evaluate::times_mv_d (constant * args) {
00811   _ARMV0 (v1);
00812   _ARD1 (d2);
00813   _DEFMV ();
00814   _RETMV (*v1 * d2);
00815 }
00816 
00817 constant * evaluate::times_d_mv (constant * args) {
00818   _ARD0 (d1);
00819   _ARMV1 (v2);
00820   _DEFMV ();
00821   _RETMV (d1 * *v2);
00822 }
00823 
00824 constant * evaluate::times_mv_m (constant * args) {
00825   _ARMV0 (v1);
00826   _ARM1 (m2);
00827   _DEFMV ();
00828   if (v1->getCols () != m2->getRows ()) {
00829     THROW_MATH_EXCEPTION ("nonconformant arguments in matrix multiplication");
00830     res->mv = new matvec (v1->getSize (), v1->getRows (), m2->getCols ());
00831   } else {
00832     res->mv = new matvec (*v1 * *m2);
00833   }
00834   return res;
00835 }
00836 
00837 constant * evaluate::times_m_mv (constant * args) {
00838   _ARM0 (m1);
00839   _ARMV1 (v2);
00840   _DEFMV ();
00841   if (m1->getCols () != v2->getRows ()) {
00842     THROW_MATH_EXCEPTION ("nonconformant arguments in matrix multiplication");
00843     res->mv = new matvec (v2->getSize (), m1->getRows (), v2->getCols ());
00844   } else {
00845     res->mv = new matvec (*m1 * *v2);
00846   }
00847   return res;
00848 }
00849 
00850 constant * evaluate::times_mv_v (constant * args) {
00851   _ARMV0 (v1);
00852   _ARV1 (v2);
00853   _DEFMV ();
00854   _RETMV (*v1 * *v2);
00855 }
00856 
00857 constant * evaluate::times_v_mv (constant * args) {
00858   _ARV0 (v1);
00859   _ARMV1 (v2);
00860   _DEFMV ();
00861   _RETMV (*v1 * *v2);
00862 }
00863 
00864 // ****************** division *************************
00865 constant * evaluate::over_d_d (constant * args) {
00866   _ARD0 (d1);
00867   _ARD1 (d2);
00868   _DEFD ();
00869   if (d2 == 0.0) THROW_MATH_EXCEPTION ("division by zero");
00870   _RETD (d1 / d2);
00871 }
00872 
00873 constant * evaluate::over_c_c (constant * args) {
00874   _ARC0 (c1);
00875   _ARC1 (c2);
00876   _DEFC ();
00877   if (*c2 == 0.0) THROW_MATH_EXCEPTION ("division by zero");
00878   _RETC (*c1 / *c2);
00879 }
00880 
00881 constant * evaluate::over_c_d (constant * args) {
00882   _ARC0 (c1);
00883   _ARD1 (d2);
00884   _DEFC ();
00885   if (d2 == 0.0) THROW_MATH_EXCEPTION ("division by zero");
00886   _RETC (*c1 / d2);
00887 }
00888 
00889 constant * evaluate::over_d_c (constant * args) {
00890   _ARD0 (d1);
00891   _ARC1 (c2);
00892   _DEFC ();
00893   if (*c2 == 0.0) THROW_MATH_EXCEPTION ("division by zero");
00894   _RETC (d1 / *c2);
00895 }
00896 
00897 constant * evaluate::over_v_d (constant * args) {
00898   _ARV0 (v1);
00899   _ARD1 (d2);
00900   _DEFV ();
00901   if (d2 == 0.0) THROW_MATH_EXCEPTION ("division by zero");
00902   _RETV (*v1 / d2);
00903 }
00904 
00905 constant * evaluate::over_d_v (constant * args) {
00906   _ARD0 (d1);
00907   _ARV1 (v2);
00908   _DEFV ();
00909   _RETV (d1 / *v2);
00910 }
00911 
00912 constant * evaluate::over_v_c (constant * args) {
00913   _ARV0 (v1);
00914   _ARC1 (c2);
00915   _DEFV ();
00916   if (*c2 == 0.0) THROW_MATH_EXCEPTION ("division by zero");
00917   _RETV (*v1 / *c2);
00918 }
00919 
00920 constant * evaluate::over_c_v (constant * args) {
00921   _ARC0 (c1);
00922   _ARV1 (v2);
00923   _DEFV ();
00924   _RETV (*c1 / *v2);
00925 }
00926 
00927 constant * evaluate::over_v_v (constant * args) {
00928   _ARV0 (v1);
00929   _ARV1 (v2);
00930   _DEFV ();
00931   _RETV (*v1 / *v2);
00932 }
00933 
00934 constant * evaluate::over_m_c (constant * args) {
00935   _ARM0 (m1);
00936   _ARC1 (c2);
00937   _DEFM ();
00938   _RETM (*m1 / *c2);
00939 }
00940 
00941 constant * evaluate::over_m_d (constant * args) {
00942   _ARM0 (m1);
00943   _ARD1 (d2);
00944   _DEFM ();
00945   _RETM (*m1 / d2);
00946 }
00947 
00948 constant * evaluate::over_mv_c (constant * args) {
00949   _ARMV0 (v1);
00950   _ARC1 (c2);
00951   _DEFMV ();
00952   _RETMV (*v1 / *c2);
00953 }
00954 
00955 constant * evaluate::over_mv_d (constant * args) {
00956   _ARMV0 (v1);
00957   _ARD1 (d2);
00958   _DEFMV ();
00959   _RETMV (*v1 / d2);
00960 }
00961 
00962 constant * evaluate::over_mv_v (constant * args) {
00963   _ARMV0 (v1);
00964   _ARV1 (v2);
00965   _DEFMV ();
00966   _RETMV (*v1 / *v2);
00967 }
00968 
00969 // ****************** modulo *************************
00970 constant * evaluate::modulo_d_d (constant * args) {
00971   _ARD0 (d1);
00972   _ARD1 (d2);
00973   _DEFD ();
00974   _RETD (std::fmod (d1, d2));
00975 }
00976 
00977 constant * evaluate::modulo_c_c (constant * args) {
00978   _ARC0 (c1);
00979   _ARC1 (c2);
00980   _DEFC ();
00981   _RETC ((*c1) % (*c2));
00982 }
00983 
00984 constant * evaluate::modulo_c_d (constant * args) {
00985   _ARC0 (c1);
00986   _ARD1 (d2);
00987   _DEFC ();
00988   _RETC ((*c1) % d2);
00989 }
00990 
00991 constant * evaluate::modulo_d_c (constant * args) {
00992   _ARD0 (d1);
00993   _ARC1 (c2);
00994   _DEFC ();
00995   _RETC (d1 % (*c2));
00996 }
00997 
00998 constant * evaluate::modulo_v_d (constant * args) {
00999   _ARV0 (v1);
01000   _ARD1 (d2);
01001   _DEFV ();
01002   _RETV (*v1 % d2);
01003 }
01004 
01005 constant * evaluate::modulo_d_v (constant * args) {
01006   _ARD0 (d1);
01007   _ARV1 (v2);
01008   _DEFV ();
01009   _RETV (d1 % *v2);
01010 }
01011 
01012 constant * evaluate::modulo_v_c (constant * args) {
01013   _ARV0 (v1);
01014   _ARC1 (c2);
01015   _DEFV ();
01016   _RETV (*v1 % *c2);
01017 }
01018 
01019 constant * evaluate::modulo_c_v (constant * args) {
01020   _ARC0 (c1);
01021   _ARV1 (v2);
01022   _DEFV ();
01023   _RETV (*c1 % *v2);
01024 }
01025 
01026 constant * evaluate::modulo_v_v (constant * args) {
01027   _ARV0 (v1);
01028   _ARV1 (v2);
01029   _DEFV ();
01030   _RETV (*v1 % *v2);
01031 }
01032 
01033 // ****************** power *************************
01034 constant * evaluate::power_d_d (constant * args) {
01035   _ARD0 (d1);
01036   _ARD1 (d2);
01037   _DEFD ();
01038   _RETD (std::pow (d1, d2));
01039 }
01040 
01041 constant * evaluate::power_c_c (constant * args) {
01042   _ARC0 (c1);
01043   _ARC1 (c2);
01044   _DEFC ();
01045   _RETC (std::pow (*c1, *c2));
01046 }
01047 
01048 constant * evaluate::power_c_d (constant * args) {
01049   _ARC0 (c1);
01050   _ARD1 (d2);
01051   _DEFC ();
01052   _RETC (pow (*c1, d2));
01053 }
01054 
01055 constant * evaluate::power_d_c (constant * args) {
01056   _ARD0 (d1);
01057   _ARC1 (c2);
01058   _DEFC ();
01059   _RETC (pow (d1, *c2));
01060 }
01061 
01062 constant * evaluate::power_v_d (constant * args) {
01063   _ARV0 (v1);
01064   _ARD1 (d2);
01065   _DEFV ();
01066   _RETV (pow (*v1, d2));
01067 }
01068 
01069 constant * evaluate::power_d_v (constant * args) {
01070   _ARD0 (d1);
01071   _ARV1 (v2);
01072   _DEFV ();
01073   _RETV (pow (d1, *v2));
01074 }
01075 
01076 constant * evaluate::power_v_c (constant * args) {
01077   _ARV0 (v1);
01078   _ARC1 (c2);
01079   _DEFV ();
01080   _RETV (pow (*v1, *c2));
01081 }
01082 
01083 constant * evaluate::power_c_v (constant * args) {
01084   _ARC0 (c1);
01085   _ARV1 (v2);
01086   _DEFV ();
01087   _RETV (pow (*c1, *v2));
01088 }
01089 
01090 constant * evaluate::power_v_v (constant * args) {
01091   _ARV0 (v1);
01092   _ARV1 (v2);
01093   _DEFV ();
01094   _RETV (pow (*v1, *v2));
01095 }
01096 
01097 constant * evaluate::power_m_d (constant * args) {
01098   _ARM0 (m1);
01099   _ARI1 (i2);
01100   _DEFM ();
01101   _RETM (pow (*m1, i2));
01102 }
01103 
01104 constant * evaluate::power_m_c (constant * args) {
01105   _ARM0 (m1);
01106   _ARC1 (c2);
01107   _DEFM ();
01108   _RETM (pow (*m1, (int) real (*c2)));
01109 }
01110 
01111 constant * evaluate::power_mv_d (constant * args) {
01112   _ARMV0 (m1);
01113   _ARI1  (i2);
01114   _DEFMV ();
01115   _RETMV (pow (*m1, i2));
01116 }
01117 
01118 constant * evaluate::power_mv_c (constant * args) {
01119   _ARMV0 (m1);
01120   _ARC1  (c2);
01121   _DEFMV ();
01122   _RETMV (pow (*m1, (int) real (*c2)));
01123 }
01124 
01125 constant * evaluate::power_mv_v (constant * args) {
01126   _ARMV0 (m1);
01127   _ARV1  (v2);
01128   _DEFMV ();
01129   _RETMV (pow (*m1, *v2));
01130 }
01131 
01132 // ****************** hypotenuse *************************
01133 constant * evaluate::xhypot_d_d (constant * args) {
01134   _ARD0 (d1);
01135   _ARD1 (d2);
01136   _DEFD ();
01137   _RETD (xhypot (d1, d2));
01138 }
01139 
01140 constant * evaluate::xhypot_c_c (constant * args) {
01141   _ARC0 (c1);
01142   _ARC1 (c2);
01143   _DEFD ();
01144   _RETD (xhypot (*c1, *c2));
01145 }
01146 
01147 constant * evaluate::xhypot_c_d (constant * args) {
01148   _ARC0 (c1);
01149   _ARD1 (d2);
01150   _DEFD ();
01151   _RETD (xhypot (*c1, d2));
01152 }
01153 
01154 constant * evaluate::xhypot_d_c (constant * args) {
01155   _ARD0 (d1);
01156   _ARC1 (c2);
01157   _DEFD ();
01158   _RETD (xhypot (d1, *c2));
01159 }
01160 
01161 constant * evaluate::xhypot_v_d (constant * args) {
01162   _ARV0 (v1);
01163   _ARD1 (d2);
01164   _DEFV ();
01165   _RETV (xhypot (*v1, d2));
01166 }
01167 
01168 constant * evaluate::xhypot_d_v (constant * args) {
01169   _ARD0 (d1);
01170   _ARV1 (v2);
01171   _DEFV ();
01172   _RETV (xhypot (d1, *v2));
01173 }
01174 
01175 constant * evaluate::xhypot_v_c (constant * args) {
01176   _ARV0 (v1);
01177   _ARC1 (c2);
01178   _DEFV ();
01179   _RETV (xhypot (*v1, *c2));
01180 }
01181 
01182 constant * evaluate::xhypot_c_v (constant * args) {
01183   _ARC0 (c1);
01184   _ARV1 (v2);
01185   _DEFV ();
01186   _RETV (xhypot (*c1, *v2));
01187 }
01188 
01189 constant * evaluate::xhypot_v_v (constant * args) {
01190   _ARV0 (v1);
01191   _ARV1 (v2);
01192   _DEFV ();
01193   _RETV (xhypot (*v1, *v2));
01194 }
01195 
01196 // ************** conjugate complex **********************
01197 constant * evaluate::conj_d (constant * args) {
01198   _ARD0 (d1);
01199   _DEFD ();
01200   _RETD (d1);
01201 }
01202 
01203 constant * evaluate::conj_c (constant * args) {
01204   _ARC0 (c1);
01205   _DEFC ();
01206   _RETC (conj (*c1));
01207 }
01208 
01209 constant * evaluate::conj_v (constant * args) {
01210   _ARV0 (v1);
01211   _DEFV ();
01212   _RETV (conj (*v1));
01213 }
01214 
01215 constant * evaluate::conj_m (constant * args) {
01216   _ARM0 (m);
01217   _DEFM ();
01218   _RETM (conj (*m));
01219 }
01220 
01221 constant * evaluate::conj_mv (constant * args) {
01222   _ARMV0 (mv);
01223   _DEFMV ();
01224   _RETMV (conj (*mv));
01225 }
01226 
01227 // ********** square of absolute value *****************
01228 constant * evaluate::norm_d (constant * args) {
01229   _ARD0 (d1);
01230   _DEFD ();
01231   _RETD (d1 * d1);
01232 }
01233 
01234 constant * evaluate::norm_c (constant * args) {
01235   _ARC0 (c1);
01236   _DEFD ();
01237   _RETD (norm (*c1));
01238 }
01239 
01240 constant * evaluate::norm_v (constant * args) {
01241   _ARV0 (v1);
01242   _DEFV ();
01243   _RETV (norm (*v1));
01244 }
01245 
01246 // ********** phase in degrees *****************
01247 constant * evaluate::phase_d (constant * args) {
01248   _ARD0 (d1);
01249   _DEFD ();
01250   _RETD (d1 < 0.0 ? 180.0 : 0.0);
01251 }
01252 
01253 constant * evaluate::phase_c (constant * args) {
01254   _ARC0 (c1);
01255   _DEFD ();
01256   _RETD (rad2deg (arg (*c1)));
01257 }
01258 
01259 constant * evaluate::phase_v (constant * args) {
01260   _ARV0 (v1);
01261   _DEFV ();
01262   _RETV (rad2deg (arg (*v1)));
01263 }
01264 
01265 constant * evaluate::phase_m (constant * args) {
01266   _ARM0 (m1);
01267   _DEFM ();
01268   _RETM (rad2deg (arg (*m1)));
01269 }
01270 
01271 constant * evaluate::phase_mv (constant * args) {
01272   _ARMV0 (v1);
01273   _DEFMV ();
01274   _RETMV (rad2deg (arg (*v1)));
01275 }
01276 
01277 // ********** phase in radians *****************
01278 constant * evaluate::arg_d (constant * args) {
01279   _ARD0 (d1);
01280   _DEFD ();
01281   _RETD (d1 < 0.0 ? pi : 0.0);
01282 }
01283 
01284 constant * evaluate::arg_c (constant * args) {
01285   _ARC0 (c1);
01286   _DEFD ();
01287   _RETD (arg (*c1));
01288 }
01289 
01290 constant * evaluate::arg_v (constant * args) {
01291   _ARV0 (v1);
01292   _DEFV ();
01293   _RETV (arg (*v1));
01294 }
01295 
01296 constant * evaluate::arg_m (constant * args) {
01297   _ARM0 (m1);
01298   _DEFM ();
01299   _RETM (arg (*m1));
01300 }
01301 
01302 constant * evaluate::arg_mv (constant * args) {
01303   _ARMV0 (v1);
01304   _DEFMV ();
01305   _RETMV (arg (*v1));
01306 }
01307 
01308 // ******* unwrap phase in radians ************
01309 constant * evaluate::unwrap_v_1 (constant * args) {
01310   _ARV0 (v1);
01311   _DEFV ();
01312   _RETV (unwrap (*v1));
01313 }
01314 
01315 constant * evaluate::unwrap_v_2 (constant * args) {
01316   _ARV0 (v1);
01317   _ARD1 (d2);
01318   _DEFV ();
01319   _RETV (unwrap (*v1, fabs (d2)));
01320 }
01321 
01322 constant * evaluate::unwrap_v_3 (constant * args) {
01323   _ARV0 (v1);
01324   _ARD1 (d2);
01325   _ARD2 (d3);
01326   _DEFV ();
01327   _RETV (unwrap (*v1, fabs (d2), fabs (d3)));
01328 }
01329 
01330 // ******** radian/degree conversion **********
01331 constant * evaluate::deg2rad_d (constant * args) {
01332   _ARD0 (d1);
01333   _DEFD ();
01334   _RETD (deg2rad (d1));
01335 }
01336 
01337 constant * evaluate::deg2rad_c (constant * args) {
01338   _ARC0 (c1);
01339   _DEFD ();
01340   _RETD (deg2rad (*c1));
01341 }
01342 
01343 constant * evaluate::deg2rad_v (constant * args) {
01344   _ARV0 (v1);
01345   _DEFV ();
01346   _RETV (deg2rad (*v1));
01347 }
01348 
01349 constant * evaluate::rad2deg_d (constant * args) {
01350   _ARD0 (d1);
01351   _DEFD ();
01352   _RETD (rad2deg (d1));
01353 }
01354 
01355 constant * evaluate::rad2deg_c (constant * args) {
01356   _ARC0 (c1);
01357   _DEFD ();
01358   _RETD (rad2deg (*c1));
01359 }
01360 
01361 constant * evaluate::rad2deg_v (constant * args) {
01362   _ARV0 (v1);
01363   _DEFV ();
01364   _RETV (rad2deg (*v1));
01365 }
01366 
01367 // ********** voltage decibel *****************
01368 constant * evaluate::dB_d (constant * args) {
01369   _ARD0 (d1);
01370   _DEFD ();
01371   _RETD (10.0 * std::log10 (std::fabs (d1)));
01372 }
01373 
01374 constant * evaluate::dB_c (constant * args) {
01375   _ARC0 (c1);
01376   _DEFD ();
01377   _RETD (dB (*c1));
01378 }
01379 
01380 constant * evaluate::dB_v (constant * args) {
01381   _ARV0 (v1);
01382   _DEFV ();
01383   _RETV (dB (*v1));
01384 }
01385 
01386 constant * evaluate::dB_m (constant * args) {
01387   _ARM0 (m1);
01388   _DEFM ();
01389   _RETM (dB (*m1));
01390 }
01391 
01392 constant * evaluate::dB_mv (constant * args) {
01393   _ARMV0 (v1);
01394   _DEFMV ();
01395   _RETMV (dB (*v1));
01396 }
01397 
01398 // ********** square root *****************
01399 constant * evaluate::sqrt_d (constant * args) {
01400   _ARD0 (d1);
01401   _DEFC ();
01402   if (d1 < 0.0)
01403     res->c = new nr_complex_t (0.0, std::sqrt (-d1));
01404   else
01405     res->c = new nr_complex_t (std::sqrt (d1));
01406   return res;
01407 }
01408 
01409 constant * evaluate::sqrt_c (constant * args) {
01410   _ARC0 (c1);
01411   _DEFC ();
01412   _RETC (std::sqrt (*c1));
01413 }
01414 
01415 constant * evaluate::sqrt_v (constant * args) {
01416   _ARV0 (v1);
01417   _DEFV ();
01418   _RETV (sqrt (*v1));
01419 }
01420 
01421 // ********** natural logarithm *****************
01422 constant * evaluate::ln_d (constant * args) {
01423   _ARD0 (d1);
01424   _DEFC ();
01425   if (d1 < 0.0)
01426     res->c = new nr_complex_t (std::log (-d1), pi);
01427   else
01428     res->c = new nr_complex_t (std::log (d1));
01429   return res;
01430 }
01431 
01432 constant * evaluate::ln_c (constant * args) {
01433   _ARC0 (c1);
01434   _DEFC ();
01435   _RETC (std::log (*c1));
01436 }
01437 
01438 constant * evaluate::ln_v (constant * args) {
01439   _ARV0 (v1);
01440   _DEFV ();
01441   _RETV (log (*v1));
01442 }
01443 
01444 // ********** decimal logarithm *****************
01445 constant * evaluate::log10_d (constant * args) {
01446   _ARD0 (d1);
01447   _DEFC ();
01448   if (d1 < 0.0)
01449     res->c = new nr_complex_t (std::log10 (-d1), pi * log10e);
01450   else
01451     res->c = new nr_complex_t (std::log10 (d1));
01452   return res;
01453 }
01454 
01455 constant * evaluate::log10_c (constant * args) {
01456   _ARC0 (c1);
01457   _DEFC ();
01458   _RETC (std::log10 (*c1));
01459 }
01460 
01461 constant * evaluate::log10_v (constant * args) {
01462   _ARV0 (v1);
01463   _DEFV ();
01464   _RETV (log10 (*v1));
01465 }
01466 
01467 // ********** binary logarithm *****************
01468 constant * evaluate::log2_d (constant * args) {
01469   _ARD0 (d1);
01470   _DEFC ();
01471   if (d1 < 0.0)
01472     res->c = new nr_complex_t (std::log (-d1) * log2e, pi * log2e);
01473   else
01474     res->c = new nr_complex_t (std::log (d1) * log2e);
01475   return res;
01476 }
01477 
01478 constant * evaluate::log2_c (constant * args) {
01479   _ARC0 (c1);
01480   _DEFC ();
01481   _RETC (qucs::log2 (*c1));
01482 }
01483 
01484 constant * evaluate::log2_v (constant * args) {
01485   _ARV0 (v1);
01486   _DEFV ();
01487   _RETV (log2 (*v1));
01488 }
01489 
01490 // ************* arcus sine *********************
01491 constant * evaluate::arcsin_d (constant * args) {
01492   _ARD0 (d1);
01493   _DEFD ();
01494   _RETD (std::asin (d1));
01495 }
01496 
01497 constant * evaluate::arcsin_c (constant * args) {
01498   _ARC0 (c1);
01499   _DEFC ();
01500   _RETC (asin (*c1));
01501 }
01502 
01503 constant * evaluate::arcsin_v (constant * args) {
01504   _ARV0 (v1);
01505   _DEFV ();
01506   _RETV (asin (*v1));
01507 }
01508 
01509 // ************* arcus cosine ******************
01510 constant * evaluate::arccos_d (constant * args) {
01511   _ARD0 (d1);
01512   _DEFD ();
01513   _RETD (std::acos (d1));
01514 }
01515 
01516 constant * evaluate::arccos_c (constant * args) {
01517   _ARC0 (c1);
01518   _DEFC ();
01519   _RETC (qucs::acos (*c1));
01520 }
01521 
01522 constant * evaluate::arccos_v (constant * args) {
01523   _ARV0 (v1);
01524   _DEFV ();
01525   _RETV (acos (*v1));
01526 }
01527 
01528 // ************** arcus tangent ******************
01529 constant * evaluate::arctan_d (constant * args) {
01530   _ARD0 (d1);
01531   _DEFD ();
01532   _RETD (std::atan (d1));
01533 }
01534 
01535 constant * evaluate::arctan_c (constant * args) {
01536   _ARC0 (c1);
01537   _DEFC ();
01538   _RETC (qucs::atan (*c1));
01539 }
01540 
01541 constant * evaluate::arctan_v (constant * args) {
01542   _ARV0 (v1);
01543   _DEFV ();
01544   _RETV (atan (*v1));
01545 }
01546 
01547 // *************** cotangent ********************
01548 constant * evaluate::cot_d (constant * args) {
01549   _ARD0 (d1);
01550   _DEFD ();
01551   _RETD (1.0 / std::tan (d1));
01552 }
01553 
01554 constant * evaluate::cot_c (constant * args) {
01555   _ARC0 (c1);
01556   _DEFC ();
01557   _RETC (qucs::cot (*c1));
01558 }
01559 
01560 constant * evaluate::cot_v (constant * args) {
01561   _ARV0 (v1);
01562   _DEFV ();
01563   _RETV (cot (*v1));
01564 }
01565 
01566 // ************ arcus cotangent *****************
01567 constant * evaluate::arccot_d (constant * args) {
01568   _ARD0 (d1);
01569   _DEFD ();
01570   _RETD (pi_over_2 - std::atan (d1));
01571 }
01572 
01573 constant * evaluate::arccot_c (constant * args) {
01574   _ARC0 (c1);
01575   _DEFC ();
01576   _RETC (qucs::acot (*c1));
01577 }
01578 
01579 constant * evaluate::arccot_v (constant * args) {
01580   _ARV0 (v1);
01581   _DEFV ();
01582   _RETV (acot (*v1));
01583 }
01584 
01585 // ***************** secans *********************
01586 constant * evaluate::sec_d (constant * args) {
01587   _ARD0 (d1);
01588   _DEFD ();
01589   _RETD (1.0 / std::cos (d1));
01590 }
01591 
01592 constant * evaluate::sec_c (constant * args) {
01593   _ARC0 (c1);
01594   _DEFC ();
01595   _RETC (1.0 / std::cos (*c1));
01596 }
01597 
01598 constant * evaluate::sec_v (constant * args) {
01599   _ARV0 (v1);
01600   _DEFV ();
01601   _RETV (1.0 / qucs::cos (*v1));
01602 }
01603 
01604 // *************** arcus secans *******************
01605 constant * evaluate::arcsec_d (constant * args) {
01606   _ARD0 (d1);
01607   _DEFD ();
01608   _RETD (std::acos (1.0 / d1));
01609 }
01610 
01611 constant * evaluate::arcsec_c (constant * args) {
01612   _ARC0 (c1);
01613   _DEFC ();
01614   _RETC (acos (1.0 / *c1));
01615 }
01616 
01617 constant * evaluate::arcsec_v (constant * args) {
01618   _ARV0 (v1);
01619   _DEFV ();
01620   _RETV (acos (1.0 / *v1));
01621 }
01622 
01623 // ***************** cosecans *********************
01624 constant * evaluate::cosec_d (constant * args) {
01625   _ARD0 (d1);
01626   _DEFD ();
01627   _RETD (1.0 / sin (d1));
01628 }
01629 
01630 constant * evaluate::cosec_c (constant * args) {
01631   _ARC0 (c1);
01632   _DEFC ();
01633   _RETC (1.0 / sin (*c1));
01634 }
01635 
01636 constant * evaluate::cosec_v (constant * args) {
01637   _ARV0 (v1);
01638   _DEFV ();
01639   _RETV (1.0 / sin (*v1));
01640 }
01641 
01642 // ************* arcus cosecans *******************
01643 constant * evaluate::arccosec_d (constant * args) {
01644   _ARD0 (d1);
01645   _DEFD ();
01646   _RETD (std::asin (1.0 / d1));
01647 }
01648 
01649 constant * evaluate::arccosec_c (constant * args) {
01650   _ARC0 (c1);
01651   _DEFC ();
01652   _RETC (asin (1.0 / *c1));
01653 }
01654 
01655 constant * evaluate::arccosec_v (constant * args) {
01656   _ARV0 (v1);
01657   _DEFV ();
01658   _RETV (asin (1.0 / *v1));
01659 }
01660 
01661 // ********** area sine hyperbolicus **************
01662 constant * evaluate::arsinh_d (constant * args) {
01663   _ARD0 (d1);
01664   _DEFD ();
01665   _RETD (log (d1 + sqrt (d1 * d1 + 1)));
01666 }
01667 
01668 constant * evaluate::arsinh_c (constant * args) {
01669   _ARC0 (c1);
01670   _DEFC ();
01671   _RETC (asinh (*c1));
01672 }
01673 
01674 constant * evaluate::arsinh_v (constant * args) {
01675   _ARV0 (v1);
01676   _DEFV ();
01677   _RETV (asinh (*v1));
01678 }
01679 
01680 // ********** area cosecans hyperbolicus **************
01681 constant * evaluate::arcosech_d (constant * args) {
01682   _ARD0 (d1);
01683   _DEFD ();
01684   d1 = 1 / d1;
01685   _RETD (log (d1 + sqrt (d1 * d1 + 1)));
01686 }
01687 
01688 constant * evaluate::arcosech_c (constant * args) {
01689   _ARC0 (c1);
01690   _DEFC ();
01691   _RETC (asinh (1.0 / *c1));
01692 }
01693 
01694 constant * evaluate::arcosech_v (constant * args) {
01695   _ARV0 (v1);
01696   _DEFV ();
01697   _RETV (asinh (1 / *v1));
01698 }
01699 
01700 // ********* area cosine hyperbolicus ************
01701 constant * evaluate::arcosh_d (constant * args) {
01702   _ARD0 (d1);
01703   _DEFC ();
01704   _RETC (acosh (nr_complex_t (d1)));
01705 }
01706 
01707 constant * evaluate::arcosh_c (constant * args) {
01708   _ARC0 (c1);
01709   _DEFC ();
01710   _RETC (acosh (*c1));
01711 }
01712 
01713 constant * evaluate::arcosh_v (constant * args) {
01714   _ARV0 (v1);
01715   _DEFV ();
01716   _RETV (acosh (*v1));
01717 }
01718 
01719 // ********* area secans hyperbolicus ***********
01720 constant * evaluate::arsech_d (constant * args) {
01721   _ARD0 (d1);
01722   _DEFC ();
01723   _RETC (asech (nr_complex_t (d1)));
01724 }
01725 
01726 constant * evaluate::arsech_c (constant * args) {
01727   _ARC0 (c1);
01728   _DEFC ();
01729   _RETC (asech (*c1));
01730 }
01731 
01732 constant * evaluate::arsech_v (constant * args) {
01733   _ARV0 (v1);
01734   _DEFV ();
01735   _RETV (asech (*v1));
01736 }
01737 
01738 // ******* area tangent hyperbolicus **********
01739 constant * evaluate::artanh_d (constant * args) {
01740   _ARD0 (d1);
01741   _DEFD ();
01742   _RETD (0.5 * log ((1.0 + d1) / (1.0 - d1)));
01743 }
01744 
01745 constant * evaluate::artanh_c (constant * args) {
01746   _ARC0 (c1);
01747   _DEFC ();
01748   _RETC (atanh (*c1));
01749 }
01750 
01751 constant * evaluate::artanh_v (constant * args) {
01752   _ARV0 (v1);
01753   _DEFV ();
01754   _RETV (atanh (*v1));
01755 }
01756 
01757 // ******* area cotangent hyperbolicus **********
01758 constant * evaluate::arcoth_d (constant * args) {
01759   _ARD0 (d1);
01760   _DEFD ();
01761   _RETD (0.5 * std::log ((d1 + 1.0) / (d1 - 1.0)));
01762 }
01763 
01764 constant * evaluate::arcoth_c (constant * args) {
01765   _ARC0 (c1);
01766   _DEFC ();
01767   _RETC (qucs::acoth (*c1));
01768 }
01769 
01770 constant * evaluate::arcoth_v (constant * args) {
01771   _ARV0 (v1);
01772   _DEFV ();
01773   _RETV (qucs::acoth (*v1));
01774 }
01775 
01776 // This is the rtoz, ztor, ytor, rtoy helper macro.
01777 #define MAKE_FUNC_DEFINITION_2(cfunc) \
01778 constant * evaluate:: QUCS_CONCAT2 (cfunc,_d) (constant * args) {   \
01779   _ARD0 (d);                                                        \
01780   _DEFD ();                                                         \
01781   _RETD (real (cfunc (nr_complex_t (d, 0))));                               \
01782 }                                                                   \
01783 constant * evaluate:: QUCS_CONCAT2 (cfunc,_d_d) (constant * args) { \
01784   _ARD0 (d);                                                        \
01785   _ARD1 (z);                                                        \
01786   _DEFD ();                                                         \
01787   _RETD (real (cfunc (nr_complex_t (d, 0), z)));                            \
01788 }                                                                   \
01789 constant * evaluate:: QUCS_CONCAT2 (cfunc,_d_c) (constant * args) { \
01790   _ARD0 (d);                                                        \
01791   _ARC1 (z);                                                        \
01792   _DEFC ();                                                         \
01793   _RETC (cfunc (nr_complex_t (d, 0), *z));                                  \
01794 }                                                                   \
01795 constant * evaluate:: QUCS_CONCAT2 (cfunc,_c) (constant * args) {   \
01796   _ARC0 (c);                                                        \
01797   _DEFC ();                                                         \
01798   _RETC (cfunc (*c));                                               \
01799 }                                                                   \
01800 constant * evaluate:: QUCS_CONCAT2 (cfunc,_c_d) (constant * args) { \
01801   _ARC0 (c);                                                        \
01802   _ARD1 (z);                                                        \
01803   _DEFC ();                                                         \
01804   _RETC (cfunc (*c, z));                                            \
01805 }                                                                   \
01806 constant * evaluate:: QUCS_CONCAT2 (cfunc,_c_c) (constant * args) { \
01807   _ARC0 (c);                                                        \
01808   _ARC1 (z);                                                        \
01809   _DEFC ();                                                         \
01810   _RETC (cfunc (*c, *z));                                           \
01811 }                                                                   \
01812 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v) (constant * args) {   \
01813   _ARV0 (v);                                                        \
01814   _DEFV ();                                                         \
01815   _RETV (cfunc (*v));                                               \
01816 }                                                                   \
01817 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v_d) (constant * args) { \
01818   _ARV0 (v);                                                        \
01819   _ARD1 (z);                                                        \
01820   _DEFV ();                                                         \
01821   _RETV (cfunc (*v, z));                                            \
01822 }                                                                   \
01823 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v_c) (constant * args) { \
01824   _ARV0 (v);                                                        \
01825   _ARC1 (z);                                                        \
01826   _DEFV ();                                                         \
01827   _RETV (cfunc (*v, *z));                                           \
01828 }                                                                   \
01829 
01830 MAKE_FUNC_DEFINITION_2 (ztor);
01831 MAKE_FUNC_DEFINITION_2 (rtoz);
01832 MAKE_FUNC_DEFINITION_2 (ytor);
01833 MAKE_FUNC_DEFINITION_2 (rtoy);
01834 
01835 // ** convert reflexion coefficient to standing wave ratio **
01836 constant * evaluate::rtoswr_d (constant * args) {
01837   _ARD0 (d1);
01838   _DEFD ();
01839   _RETD ((1 + fabs (d1)) / (1 - fabs (d1)));
01840 }
01841 
01842 constant * evaluate::rtoswr_c (constant * args) {
01843   _ARC0 (c1);
01844   _DEFD ();
01845   _RETD ((1 + abs (*c1)) / (1 - abs (*c1)));
01846 }
01847 
01848 constant * evaluate::rtoswr_v (constant * args) {
01849   _ARV0 (v1);
01850   _DEFV ();
01851   res->v = new qucs::vector (v1->getSize ());
01852   for (int i = 0; i < v1->getSize (); i++)
01853     res->v->set ((1 + abs (v1->get (i))) / (1 - abs (v1->get (i))), i);
01854   return res;
01855 }
01856 
01857 // ** differentiate vector with respect to another vector **
01858 constant * evaluate::diff_v_2 (constant * args) {
01859   _ARV0 (v1);
01860   _ARV1 (v2);
01861   _DEFV ();
01862   _RETV (diff (*v1, *v2));
01863 }
01864 
01865 constant * evaluate::diff_v_3 (constant * args) {
01866   _ARV0 (v1);
01867   _ARV1 (v2);
01868   _ARI2 (i3);
01869   _DEFV ();
01870   _RETV (diff (*v1, *v2, i3));
01871 }
01872 
01873 // ***************** maximum *******************
01874 constant * evaluate::max_d (constant * args) {
01875   _ARD0 (d1);
01876   _DEFD ();
01877   _RETD (d1);
01878 }
01879 
01880 constant * evaluate::max_c (constant * args) {
01881   _ARC0 (c1);
01882   _DEFD ();
01883   if (fabs (arg (*c1)) < pi_over_2)
01884     res->d = abs (*c1);
01885   else
01886     res->d = -abs (*c1);
01887   return res;
01888 }
01889 
01890 constant * evaluate::max_v (constant * args) {
01891   _ARV0 (v1);
01892   _DEFD ();
01893   _RETD (v1->maximum ());
01894 }
01895 
01896 constant * evaluate::max_d_d (constant * args) {
01897   _ARD0 (d1);
01898   _ARD1 (d2);
01899   _DEFD ();
01900   _RETD (std::max (d1, d2));
01901 }
01902 
01903 constant * evaluate::max_d_c (constant * args) {
01904   _ARD0 (d1);
01905   _ARC1 (c2);
01906   _DEFC ();
01907   nr_double_t a = d1;
01908   nr_double_t b = fabs (arg (*c2)) < pi_over_2 ? abs (*c2) : -abs (*c2);
01909   nr_complex_t r = a > b ? d1 : *c2;
01910   _RETC (r);
01911 }
01912 
01913 constant * evaluate::max_c_c (constant * args) {
01914   _ARC0 (c1);
01915   _ARC1 (c2);
01916   _DEFC ();
01917   nr_double_t a = fabs (arg (*c1)) < pi_over_2 ? abs (*c1) : -abs (*c1);
01918   nr_double_t b = fabs (arg (*c2)) < pi_over_2 ? abs (*c2) : -abs (*c2);
01919   nr_complex_t r = a > b ? *c1 : *c2;
01920   _RETC (r);
01921 }
01922 
01923 constant * evaluate::max_c_d (constant * args) {
01924   _ARC0 (c1);
01925   _ARD1 (d2);
01926   _DEFC ();
01927   nr_double_t a = fabs (arg (*c1)) < pi_over_2 ? abs (*c1) : -abs (*c1);
01928   nr_double_t b = d2;
01929   nr_complex_t r = a > b ? *c1 : d2;
01930   _RETC (r);
01931 }
01932 
01933 // ***************** minimum *******************
01934 constant * evaluate::min_d (constant * args) {
01935   _ARD0 (d1);
01936   _DEFD ();
01937   _RETD (d1);
01938 }
01939 
01940 constant * evaluate::min_c (constant * args) {
01941   _ARC0 (c1);
01942   _DEFD ();
01943   if (fabs (arg (*c1)) < pi_over_2)
01944     res->d = abs (*c1);
01945   else
01946     res->d = -abs (*c1);
01947   return res;
01948 }
01949 
01950 constant * evaluate::min_v (constant * args) {
01951   _ARV0 (v1);
01952   _DEFD ();
01953   _RETD (v1->minimum ());
01954 }
01955 
01956 constant * evaluate::min_d_d (constant * args) {
01957   _ARD0 (d1);
01958   _ARD1 (d2);
01959   _DEFD ();
01960   _RETD (std::min (d1, d2));
01961 }
01962 
01963 constant * evaluate::min_d_c (constant * args) {
01964   _ARD0 (d1);
01965   _ARC1 (c2);
01966   _DEFC ();
01967   nr_double_t a = d1;
01968   nr_double_t b = fabs (arg (*c2)) < pi_over_2 ? abs (*c2) : -abs (*c2);
01969   nr_complex_t r = a < b ? d1 : *c2;
01970   _RETC (r);
01971 }
01972 
01973 constant * evaluate::min_c_c (constant * args) {
01974   _ARC0 (c1);
01975   _ARC1 (c2);
01976   _DEFC ();
01977   nr_double_t a = fabs (arg (*c1)) < pi_over_2 ? abs (*c1) : -abs (*c1);
01978   nr_double_t b = fabs (arg (*c2)) < pi_over_2 ? abs (*c2) : -abs (*c2);
01979   nr_complex_t r = a < b ? *c1 : *c2;
01980   _RETC (r);
01981 }
01982 
01983 constant * evaluate::min_c_d (constant * args) {
01984   _ARC0 (c1);
01985   _ARD1 (d2);
01986   _DEFC ();
01987   nr_double_t a = fabs (arg (*c1)) < pi_over_2 ? abs (*c1) : -abs (*c1);
01988   nr_double_t b = d2;
01989   nr_complex_t r = a < b ? *c1 : d2;
01990   _RETC (r);
01991 }
01992 
01993 // ******************** sum **********************
01994 constant * evaluate::sum_d (constant * args) {
01995   _ARD0 (d1);
01996   _DEFD ();
01997   _RETD (d1);
01998 }
01999 
02000 constant * evaluate::sum_c (constant * args) {
02001   _ARC0 (c1);
02002   _DEFC ();
02003   _RETC (*c1);
02004 }
02005 
02006 constant * evaluate::sum_v (constant * args) {
02007   _ARV0 (v1);
02008   _DEFC ();
02009   _RETC (sum (*v1));
02010 }
02011 
02012 // ****************** product ********************
02013 constant * evaluate::prod_d (constant * args) {
02014   _ARD0 (d1);
02015   _DEFD ();
02016   _RETD (d1);
02017 }
02018 
02019 constant * evaluate::prod_c (constant * args) {
02020   _ARC0 (c1);
02021   _DEFC ();
02022   _RETC (*c1);
02023 }
02024 
02025 constant * evaluate::prod_v (constant * args) {
02026   _ARV0 (v1);
02027   _DEFC ();
02028   _RETC (prod (*v1));
02029 }
02030 
02031 // ******************* average *********************
02032 constant * evaluate::avg_d (constant * args) {
02033   _ARD0 (d1);
02034   _DEFD ();
02035   _RETD (d1);
02036 }
02037 
02038 constant * evaluate::avg_c (constant * args) {
02039   _ARC0 (c1);
02040   _DEFC ();
02041   _RETC (*c1);
02042 }
02043 
02044 constant * evaluate::avg_v (constant * args) {
02045   _ARV0 (v1);
02046   _DEFC ();
02047   _RETC (avg (*v1));
02048 }
02049 
02050 // ******************* lengths *********************
02051 constant * evaluate::length_d (constant *) {
02052   _DEFD ();
02053   _RETD (1);
02054 }
02055 
02056 constant * evaluate::length_c (constant *) {
02057   _DEFD ();
02058   _RETD (1);
02059 }
02060 
02061 constant * evaluate::length_v (constant * args) {
02062   _ARV0 (v1);
02063   _DEFD ();
02064   _RETD (v1->getSize ());
02065 }
02066 
02067 constant * evaluate::length_m (constant *) {
02068   _DEFD ();
02069   _RETD (1);
02070 }
02071 
02072 constant * evaluate::length_mv (constant * args) {
02073   _ARV0 (mv);
02074   _DEFD ();
02075   _RETD (mv->getSize ());
02076 }
02077 
02078 // ***************** array indices *****************
02079 constant * evaluate::index_mv_2 (constant * args) {
02080   _ARMV0 (mv);
02081   _ARI1 (r);
02082   _ARI2 (c);
02083   _DEFV ();
02084   if (r < 1 || r > mv->getRows () || c < 1 || c > mv->getCols ()) {
02085     char txt[256];
02086     sprintf (txt, "matvec indices [%d,%d] out of bounds [1-%d,1-%d]",
02087              r, c, mv->getRows (), mv->getCols ());
02088     THROW_MATH_EXCEPTION (txt);
02089     res->v = new qucs::vector (mv->getSize ());
02090   } else {
02091     res->v = new qucs::vector (mv->get (r - 1, c - 1));
02092   }
02093   return res;
02094 }
02095 
02096 constant * evaluate::index_mv_1 (constant * args) {
02097   _ARMV0 (mv);
02098   _ARI1 (i);
02099   _DEFM ();
02100   if (i < 1 || i > mv->getSize ()) {
02101     char txt[256];
02102     sprintf (txt, "matvec index [%d] out of bounds [1-%d]", i, mv->getSize ());
02103     THROW_MATH_EXCEPTION (txt);
02104     res->m = new matrix (mv->getRows (), mv->getCols ());
02105   } else {
02106     res->m = new matrix (mv->get (i - 1));
02107   }
02108   return res;
02109 }
02110 
02111 /* Little helper macros for the following functionality. */
02112 #define EQUATION_HAS_DEPS(v,n) \
02113   ((v)->getDataDependencies() != NULL && \
02114    (v)->getDataDependencies()->length() >= n)
02115 #define EQUATION_DEPS(v) \
02116   ((v)->getDataDependencies() ? (v)->getDataDependencies()->length() : 1)
02117 
02118 /* This following function is used to get a subset of data entries
02119    from a data vector with certain data dependencies. */
02120 void evaluate::extract_vector (constant * args, int idx, int &skip, int &size,
02121                                constant * res) {
02122   _ARV0 (v);
02123   int i = INT (_ARES (idx));
02124   int type = _ARG(idx)->getType ();
02125   qucs::vector * vres;
02126   strlist * deps = _ARES(0)->getDataDependencies ();
02127   int didx = (deps ? deps->length () : 0) - idx;
02128   int dsize = SOLVEE(0)->getDependencySize (deps, idx);
02129 
02130   // all of the data vector
02131   if (type == TAG_RANGE) {
02132     if (dsize > 1) {
02133       // dependent vectors: only ':' possible
02134       vres = new qucs::vector (*(res->v));
02135       skip *= deps ? SOLVEE(0)->getDataSize (deps->get (didx - 1)) : 1;
02136       size *= deps ? SOLVEE(0)->getDataSize (deps->get (didx)) : 1;
02137     }
02138     else {
02139       // independent vectors
02140       range * r = RNG (_ARES (idx));
02141       int i, n, k;
02142       int len = res->v->getSize ();
02143       i = (int) r->lo ();
02144       if (i < 0 || i >= len) {
02145         char txt[256];
02146         sprintf (txt, "vector index %d out of bounds [%d,%d]", i, 0, len - 1);
02147         THROW_MATH_EXCEPTION (txt);
02148       }
02149       i = (int) r->hi ();
02150       if (i < 0 || i >= len) {
02151         char txt[256];
02152         sprintf (txt, "vector index %d out of bounds [%d,%d]", i, 0, len - 1);
02153         THROW_MATH_EXCEPTION (txt);
02154       }
02155       size = 0;
02156       for (n = 0; n < len; n++) if (r->inside (n)) size++;
02157       vres = new qucs::vector (size);
02158       for (k = 0, n = 0; n < len; n++) {
02159         if (r->inside (n))
02160           vres->set (res->v->get (n), k++);
02161       }
02162     }
02163   }
02164   // a subset
02165   else {
02166     vres = new qucs::vector (dsize * size);
02167     int len = deps ? SOLVEE(0)->getDataSize (deps->get (didx)) : v->getSize ();
02168     if (i < 0 || i >= len) {
02169       char txt[256];
02170       sprintf (txt, "vector index %d (%d) out of bounds [%d,%d]",
02171                idx, i, 0, len - 1);
02172       THROW_MATH_EXCEPTION (txt);
02173     } else {
02174       int k, n;
02175       for (n = k = 0; k < dsize * size; n += skip, k++) {
02176         vres->set (res->v->get (dsize * i + n), k);
02177       }
02178     }
02179     if (deps && didx >= 0) {
02180       res->addDropDependencies (deps->get (didx));
02181     }
02182   }
02183   delete res->v;
02184   res->v = vres;
02185 }
02186 
02187 constant * evaluate::index_v_1 (constant * args) {
02188   _ARV0 (v);
02189   _DEFV ();
02190   int skip = 1, size = 1;
02191   res->v = new qucs::vector (*v);
02192   extract_vector (args, 1, skip, size, res);
02193   return res;
02194 }
02195 
02196 constant * evaluate::index_v_2 (constant * args) {
02197   _ARV0 (v);
02198   _DEFV ();
02199   int skip = 1, size = 1;
02200   res->v = new qucs::vector (*v);
02201   if (!EQUATION_HAS_DEPS (_ARES(0), 2)) {
02202     char txt[256];
02203     sprintf (txt, "invalid number of vector indices (%d > %d)", 2,
02204              EQUATION_DEPS (_ARES(0)));
02205     THROW_MATH_EXCEPTION (txt);
02206     return res;
02207   }
02208   extract_vector (args, 1, skip, size, res);
02209   extract_vector (args, 2, skip, size, res);
02210   return res;
02211 }
02212 
02213 constant * evaluate::index_m_2 (constant * args) {
02214   _ARM0 (m);
02215   _ARI1 (r);
02216   _ARI2 (c);
02217   _DEFC ();
02218   if (r < 1 || r > m->getRows () || c < 1 || c > m->getCols ()) {
02219     char txt[256];
02220     sprintf (txt, "matrix indices [%d,%d] out of bounds [1-%d,1-%d]",
02221              r, c, m->getRows (), m->getCols ());
02222     THROW_MATH_EXCEPTION (txt);
02223     res->c = new nr_complex_t ();
02224   } else {
02225     res->c = new nr_complex_t (m->get (r - 1, c - 1));
02226   }
02227   return res;
02228 }
02229 
02230 constant * evaluate::index_s_1 (constant * args) {
02231   char * s = STR (_ARES(0));
02232   _ARI1 (i);
02233   constant * res = new constant (TAG_CHAR);
02234   res->chr = (i >= 0 && i < (int) strlen (s)) ? s[i] : ' ';
02235   return res;
02236 }
02237 
02238 // Interpolator helper macro without number of points given.
02239 #define INTERPOL_HELPER()                     \
02240   constant * arg = new constant (TAG_DOUBLE); \
02241   arg->d = 64;                                \
02242   arg->solvee = args->getResult(0)->solvee;   \
02243   arg->evaluate ();                           \
02244   args->append (arg);
02245 
02246 // ***************** interpolation *****************
02247 constant * evaluate::interpolate_v_v (constant * args) {
02248   INTERPOL_HELPER();
02249   return interpolate_v_v_d (args);
02250 }
02251 
02252 constant * evaluate::interpolate_v_v_d (constant * args) {
02253   _ARV0 (v1);
02254   _ARV1 (v2);
02255   _ARI2 (n);
02256   _DEFV ();
02257   if (v1->getSize () < 3) {
02258     THROW_MATH_EXCEPTION ("interpolate: number of datapoints must be greater "
02259                           "than 2");
02260     res->v = new qucs::vector ();
02261     return res;
02262   }
02263   nr_double_t last  = real (v2->get (v2->getSize () - 1));
02264   nr_double_t first = real (v2->get (0));
02265   constant * arg = new constant (TAG_VECTOR);
02266   arg->v = new qucs::vector (qucs::linspace (first, last, n));
02267   arg->solvee = args->getResult(0)->solvee;
02268   arg->evaluate ();
02269   qucs::vector * val = new qucs::vector (n);
02270   spline spl (SPLINE_BC_NATURAL);
02271   spl.vectors (*v1, *v2);
02272   spl.construct ();
02273   for (int k = 0; k < arg->v->getSize (); k++) {
02274     val->set (spl.evaluate (real (arg->v->get (k))).f0, k);
02275   }
02276   res->v = val;
02277   node * gen = SOLVEE(0)->addGeneratedEquation (arg->v, "Interpolate");
02278   res->addPrepDependencies (A(gen)->result);
02279   res->dropdeps = 1;
02280   delete arg;
02281   return res;
02282 }
02283 
02284 // ***************** fourier transformations *****************
02285 #define FOURIER_HELPER_1(efunc,cfunc,isign,dep) \
02286 constant * evaluate:: QUCS_CONCAT2 (efunc,_v_v) (constant * args) { \
02287   _ARV0 (v);                                                        \
02288   _ARV1 (t);                                                        \
02289   _DEFV ();                                                         \
02290   qucs::vector * val = new qucs::vector (QUCS_CONCAT2 (cfunc,_1d) (*v));    \
02291   int k = val->getSize ();                                          \
02292   *val = isign > 0 ? *val / k : *val * k;                           \
02293   res->v = val;                                                     \
02294   int n = t->getSize ();                                            \
02295   if (k != n) {                                                     \
02296     THROW_MATH_EXCEPTION ("nonconformant vector lengths");          \
02297     return res; }                                                   \
02298   nr_double_t last  = real (t->get (n - 1));                        \
02299   nr_double_t first = real (t->get (0));                            \
02300   nr_double_t delta = (last - first) / (n - 1);                     \
02301   constant * arg = new constant (TAG_VECTOR);                       \
02302   arg->v = new qucs::vector (qucs::linspace (0, 1.0 / delta, n));           \
02303   arg->solvee = args->getResult(0)->solvee;                         \
02304   arg->evaluate ();                                                 \
02305   node * gen = SOLVEE(0)->addGeneratedEquation (arg->v, dep);       \
02306   res->addPrepDependencies (A(gen)->result);                        \
02307   res->dropdeps = 1;                                                \
02308   args->append (arg);                                               \
02309   return res;                                                       \
02310 }
02311 
02312 #define FOURIER_HELPER_2(cfunc) \
02313 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v) (constant * args) { \
02314   _ARV0 (v);                                                      \
02315   _DEFV ();                                                       \
02316   qucs::vector * val = new qucs::vector (QUCS_CONCAT2 (cfunc,_1d) (*v));  \
02317   res->v = val;                                                   \
02318   res->dropdeps = 1;                                              \
02319   return res;                                                     \
02320 }
02321 
02322 FOURIER_HELPER_1 (time2freq,dft,1,"Frequency");
02323 FOURIER_HELPER_1 (freq2time,idft,-1,"Time");
02324 FOURIER_HELPER_2 (fft);
02325 FOURIER_HELPER_2 (ifft);
02326 FOURIER_HELPER_2 (dft);
02327 FOURIER_HELPER_2 (idft);
02328 
02329 // Shuffles values of FFT arounds.
02330 constant * evaluate::fftshift_v (constant * args) {
02331   _ARV0 (v);
02332   _DEFV ();
02333   res->v = new qucs::vector (fftshift (*v));
02334   return res;
02335 }
02336 
02337 // This is the stoz, ztos, ytos, stoy helper macro.
02338 #define MAKE_FUNC_DEFINITION_3(cfunc) \
02339 constant * evaluate:: QUCS_CONCAT2 (cfunc,_m) (constant * args) {    \
02340   _ARM0 (m);                                                         \
02341   _DEFM ();                                                          \
02342   _RETM (cfunc (*m));                                                \
02343 }                                                                    \
02344 constant * evaluate:: QUCS_CONCAT2 (cfunc,_m_d) (constant * args) {  \
02345   _ARM0 (m);                                                         \
02346   _ARD1 (z);                                                         \
02347   _DEFM ();                                                          \
02348   _RETM (cfunc (*m, nr_complex_t (z, 0)));                                   \
02349 }                                                                    \
02350 constant * evaluate:: QUCS_CONCAT2 (cfunc,_m_c) (constant * args) {  \
02351   _ARM0 (m);                                                         \
02352   _ARC1 (z);                                                         \
02353   _DEFM ();                                                          \
02354   _RETM (cfunc (*m, *z));                                            \
02355 }                                                                    \
02356 constant * evaluate:: QUCS_CONCAT2 (cfunc,_m_v) (constant * args) {  \
02357   _ARM0 (m);                                                         \
02358   _ARV1 (z);                                                         \
02359   _DEFM ();                                                          \
02360   _RETM (cfunc (*m, *z));                                            \
02361 }                                                                    \
02362 constant * evaluate:: QUCS_CONCAT2 (cfunc,_mv) (constant * args) {   \
02363   _ARMV0 (m);                                                        \
02364   _DEFMV ();                                                         \
02365   _RETMV (cfunc (*m));                                               \
02366 }                                                                    \
02367 constant * evaluate:: QUCS_CONCAT2 (cfunc,_mv_d) (constant * args) { \
02368   _ARMV0 (m);                                                        \
02369   _ARD1 (z);                                                         \
02370   _DEFMV ();                                                         \
02371   _RETMV (cfunc (*m, nr_complex_t (z, 0)));                                  \
02372 }                                                                    \
02373 constant * evaluate:: QUCS_CONCAT2 (cfunc,_mv_c) (constant * args) { \
02374   _ARMV0 (m);                                                        \
02375   _ARC1 (z);                                                         \
02376   _DEFMV ();                                                         \
02377   _RETMV (cfunc (*m, *z));                                           \
02378 }                                                                    \
02379 constant * evaluate:: QUCS_CONCAT2 (cfunc,_mv_v) (constant * args) { \
02380   _ARMV0 (m);                                                        \
02381   _ARV1 (z);                                                         \
02382   _DEFMV ();                                                         \
02383   _RETMV (cfunc (*m, *z));                                           \
02384 }                                                                    \
02385 
02386 MAKE_FUNC_DEFINITION_3 (stoy);
02387 MAKE_FUNC_DEFINITION_3 (ytos);
02388 MAKE_FUNC_DEFINITION_3 (stoz);
02389 MAKE_FUNC_DEFINITION_3 (ztos);
02390 
02391 // ***************** matrix conversions *****************
02392 constant * evaluate::ytoz_m (constant * args) {
02393   _ARM0 (m);
02394   _DEFM ();
02395   _RETM (ytoz (*m));
02396 }
02397 
02398 constant * evaluate::ytoz_mv (constant * args) {
02399   _ARMV0 (mv);
02400   _DEFMV ();
02401   _RETMV (ytoz (*mv));
02402 }
02403 
02404 constant * evaluate::ztoy_m (constant * args) {
02405   _ARM0 (m);
02406   _DEFM ();
02407   _RETM (ztoy (*m));
02408 }
02409 
02410 constant * evaluate::ztoy_mv (constant * args) {
02411   _ARMV0 (mv);
02412   _DEFMV ();
02413   _RETMV (ztoy (*mv));
02414 }
02415 
02416 // These are stos() helpers.
02417 #define _CHKM(m) /* check square matrix */              \
02418   if (m->getCols () != m->getRows ()) {                 \
02419     THROW_MATH_EXCEPTION ("stos: not a square matrix"); \
02420     res->m = new matrix (m->getRows (), m->getCols ()); \
02421     return res; }
02422 #define _CHKMV(mv) /* check square matrix vector */                        \
02423   if (mv->getCols () != mv->getRows ()) {                                  \
02424     THROW_MATH_EXCEPTION ("stos: not a square matrix");                    \
02425     res->mv = new matvec (mv->getSize (), mv->getRows (), mv->getCols ()); \
02426     return res; }
02427 #define _CHKMA(m,cond) \
02428   if (!(cond)) {                                            \
02429     THROW_MATH_EXCEPTION ("stos: nonconformant arguments"); \
02430     res->m = new matrix (m->getRows (), m->getCols ());     \
02431     return res; }
02432 #define _CHKMVA(mv,cond) \
02433   if (!(cond)) {                                                           \
02434     THROW_MATH_EXCEPTION ("stos: nonconformant arguments");                \
02435     res->mv = new matvec (mv->getSize (), mv->getRows (), mv->getCols ()); \
02436     return res; }
02437 
02438 // Function -- MATRIX stos (MATRIX, DOUBLE)
02439 constant * evaluate::stos_m_d (constant * args) {
02440   _ARM0 (m); _ARD1 (zref); _DEFM ();
02441   _CHKM (m);
02442   _RETM (stos (*m, zref));
02443 }
02444 
02445 // Function -- MATRIX stos (MATRIX, COMPLEX)
02446 constant * evaluate::stos_m_c (constant * args) {
02447   _ARM0 (m); _ARC1 (zref); _DEFM ();
02448   _CHKM (m);
02449   _RETM (stos (*m, *zref));
02450 }
02451 
02452 // Function -- MATRIX stos (MATRIX, DOUBLE, DOUBLE)
02453 constant * evaluate::stos_m_d_d (constant * args) {
02454   _ARM0 (m); _ARD1 (zref); _ARD2 (z0); _DEFM ();
02455   _CHKM (m);
02456   _RETM (stos (*m, zref, z0));
02457 }
02458 
02459 // Function -- MATRIX stos (MATRIX, DOUBLE, COMPLEX)
02460 constant * evaluate::stos_m_d_c (constant * args) {
02461   _ARM0 (m); _ARD1 (zref); _ARC2 (z0); _DEFM ();
02462   _CHKM (m);
02463   _RETM (stos (*m, nr_complex_t (zref, 0), *z0));
02464 }
02465 
02466 // Function -- MATRIX stos (MATRIX, COMPLEX, DOUBLE)
02467 constant * evaluate::stos_m_c_d (constant * args) {
02468   _ARM0 (m); _ARC1 (zref); _ARD2 (z0); _DEFM ();
02469   _CHKM (m);
02470   _RETM (stos (*m, *zref, nr_complex_t (z0, 0)));
02471 }
02472 
02473 // Function -- MATRIX stos (MATRIX, COMPLEX, COMPLEX)
02474 constant * evaluate::stos_m_c_c (constant * args) {
02475   _ARM0 (m); _ARC1 (zref); _ARC2 (z0); _DEFM ();
02476   _CHKM (m);
02477   _RETM (stos (*m, *zref, *z0));
02478 }
02479 
02480 // Function -- MATRIX stos (MATRIX, VECTOR)
02481 constant * evaluate::stos_m_v (constant * args) {
02482   _ARM0 (m); _ARV1 (zref); _DEFM ();
02483   _CHKM (m); _CHKMA (m, m->getRows () == zref->getSize ());
02484   _RETM (stos (*m, *zref));
02485 }
02486 
02487 // Function -- MATRIX stos (MATRIX, VECTOR, DOUBLE)
02488 constant * evaluate::stos_m_v_d (constant * args) {
02489   _ARM0 (m); _ARV1 (zref); _ARD2 (z0); _DEFM ();
02490   _CHKM (m); _CHKMA (m, m->getRows () == zref->getSize ());
02491   _RETM (stos (*m, *zref, nr_complex_t (z0, 0)));
02492 }
02493 
02494 // Function -- MATRIX stos (MATRIX, VECTOR, COMPLEX)
02495 constant * evaluate::stos_m_v_c (constant * args) {
02496   _ARM0 (m); _ARV1 (zref); _ARC2 (z0); _DEFM ();
02497   _CHKM (m); _CHKMA (m, m->getRows () == zref->getSize ());
02498   _RETM (stos (*m, *zref, *z0));
02499 }
02500 
02501 // Function -- MATRIX stos (MATRIX, DOUBLE, VECTOR)
02502 constant * evaluate::stos_m_d_v (constant * args) {
02503   _ARM0 (m); _ARD1 (zref); _ARV2 (z0); _DEFM ();
02504   _CHKM (m); _CHKMA (m, m->getRows () == z0->getSize ());
02505   _RETM (stos (*m, nr_complex_t (zref, 0), *z0));
02506 }
02507 
02508 // Function -- MATRIX stos (MATRIX, COMPLEX, VECTOR)
02509 constant * evaluate::stos_m_c_v (constant * args) {
02510   _ARM0 (m); _ARC1 (zref); _ARV2 (z0); _DEFM ();
02511   _CHKM (m); _CHKMA (m, m->getRows () == z0->getSize ());
02512   _RETM (stos (*m, *zref, *z0));
02513 }
02514 
02515 // Function -- MATRIX stos (MATRIX, VECTOR, VECTOR)
02516 constant * evaluate::stos_m_v_v (constant * args) {
02517   _ARM0 (m); _ARV1 (zref); _ARV2 (z0); _DEFM ();
02518   _CHKM (m); _CHKMA (m, m->getRows () == z0->getSize () &&
02519                      m->getRows () == zref->getSize ());
02520   _RETM (stos (*m, *zref, *z0));
02521 }
02522 
02523 // Function -- MATVEC stos (MATVEC, DOUBLE)
02524 constant * evaluate::stos_mv_d (constant * args) {
02525   _ARMV0 (mv); _ARD1 (zref); _DEFMV ();
02526   _CHKMV (mv);
02527   _RETMV (stos (*mv, zref));
02528 }
02529 
02530 // Function -- MATVEC stos (MATVEC, COMPLEX)
02531 constant * evaluate::stos_mv_c (constant * args) {
02532   _ARMV0 (mv); _ARC1 (zref); _DEFMV ();
02533   _CHKMV (mv);
02534   _RETMV (stos (*mv, *zref));
02535 }
02536 
02537 // Function -- MATVEC stos (MATVEC, DOUBLE, DOUBLE)
02538 constant * evaluate::stos_mv_d_d (constant * args) {
02539   _ARMV0 (mv); _ARD1 (zref); _ARD2 (z0); _DEFMV ();
02540   _CHKMV (mv);
02541   _RETMV (stos (*mv, zref, z0));
02542 }
02543 
02544 // Function -- MATVEC stos (MATVEC, DOUBLE, COMPLEX)
02545 constant * evaluate::stos_mv_d_c (constant * args) {
02546   _ARMV0 (mv); _ARD1 (zref); _ARC2 (z0); _DEFMV ();
02547   _CHKMV (mv);
02548   _RETMV (stos (*mv, nr_complex_t (zref, 0), *z0));
02549 }
02550 
02551 // Function -- MATVEC stos (MATVEC, COMPLEX, DOUBLE)
02552 constant * evaluate::stos_mv_c_d (constant * args) {
02553   _ARMV0 (mv); _ARC1 (zref); _ARD2 (z0); _DEFMV ();
02554   _CHKMV (mv);
02555   _RETMV (stos (*mv, *zref, nr_complex_t (z0, 0)));
02556 }
02557 
02558 // Function -- MATVEC stos (MATVEC, COMPLEX, COMPLEX)
02559 constant * evaluate::stos_mv_c_c (constant * args) {
02560   _ARMV0 (mv); _ARC1 (zref); _ARC2 (z0); _DEFMV ();
02561   _CHKMV (mv);
02562   _RETMV (stos (*mv, *zref, *z0));
02563 }
02564 
02565 // Function -- MATVEC stos (MATVEC, VECTOR)
02566 constant * evaluate::stos_mv_v (constant * args) {
02567   _ARMV0 (mv); _ARV1 (zref); _DEFMV ();
02568   _CHKMV (mv); _CHKMVA (mv, mv->getRows () == zref->getSize ());
02569   _RETMV (stos (*mv, *zref));
02570 }
02571 
02572 // Function -- MATVEC stos (MATVEC, VECTOR, DOUBLE)
02573 constant * evaluate::stos_mv_v_d (constant * args) {
02574   _ARMV0 (mv); _ARV1 (zref); _ARD2 (z0); _DEFMV ();
02575   _CHKMV (mv); _CHKMVA (mv, mv->getRows () == zref->getSize ());
02576   _RETMV (stos (*mv, *zref, nr_complex_t (z0, 0)));
02577 }
02578 
02579 // Function -- MATVEC stos (MATVEC, VECTOR, COMPLEX)
02580 constant * evaluate::stos_mv_v_c (constant * args) {
02581   _ARMV0 (mv); _ARV1 (zref); _ARC2 (z0); _DEFMV ();
02582   _CHKMV (mv); _CHKMVA (mv, mv->getRows () == zref->getSize ());
02583   _RETMV (stos (*mv, *zref, *z0));
02584 }
02585 
02586 // Function -- MATVEC stos (MATVEC, DOUBLE, VECTOR)
02587 constant * evaluate::stos_mv_d_v (constant * args) {
02588   _ARMV0 (mv); _ARD1 (zref); _ARV2 (z0); _DEFMV ();
02589   _CHKMV (mv); _CHKMVA (mv, mv->getRows () == z0->getSize ());
02590   _RETMV (stos (*mv, nr_complex_t (zref, 0), *z0));
02591 }
02592 
02593 // Function -- MATVEC stos (MATVEC, COMPLEX, VECTOR)
02594 constant * evaluate::stos_mv_c_v (constant * args) {
02595   _ARMV0 (mv); _ARC1 (zref); _ARV2 (z0); _DEFMV ();
02596   _CHKMV (mv); _CHKMVA (mv, mv->getRows () == z0->getSize ());
02597   _RETMV (stos (*mv, *zref, *z0));
02598 }
02599 
02600 // Function -- MATVEC stos (MATVEC, VECTOR, VECTOR)
02601 constant * evaluate::stos_mv_v_v (constant * args) {
02602   _ARMV0 (mv); _ARV1 (zref); _ARV2 (z0); _DEFMV ();
02603   _CHKMV (mv); _CHKMVA (mv, mv->getRows () == z0->getSize () &&
02604                         mv->getRows () == zref->getSize ());
02605   _RETMV (stos (*mv, *zref, *z0));
02606 }
02607 
02608 constant * evaluate::twoport_m (constant * args) {
02609   _ARM0 (m);
02610   char f = CHR (_ARES(1));
02611   char t = CHR (_ARES(2));
02612   _DEFM ();
02613   if (m->getRows () < 2 || m->getCols () < 2) {
02614     THROW_MATH_EXCEPTION ("invalid matrix dimensions for twoport "
02615                           "transformation");
02616     _RETM (*m);
02617   }
02618   _RETM (twoport (*m, toupper (f), toupper (t)));
02619 }
02620 
02621 constant * evaluate::twoport_mv (constant * args) {
02622   _ARMV0 (mv);
02623   char f = CHR (_ARES(1));
02624   char t = CHR (_ARES(2));
02625   _DEFMV ();
02626   if (mv->getRows () < 2 || mv->getCols () < 2) {
02627     THROW_MATH_EXCEPTION ("invalid matrix dimensions for twoport "
02628                           "transformation");
02629     _RETMV (*mv);
02630   }
02631   _RETMV (twoport (*mv, toupper (f), toupper (t)));
02632 }
02633 
02634 constant * evaluate::inverse_m (constant * args) {
02635   _ARM0 (m);
02636   _DEFM ();
02637   _RETM (inverse (*m));
02638 }
02639 
02640 constant * evaluate::inverse_mv (constant * args) {
02641   _ARMV0 (mv);
02642   _DEFMV ();
02643   _RETMV (inverse (*mv));
02644 }
02645 
02646 constant * evaluate::transpose_m (constant * args) {
02647   _ARM0 (m);
02648   _DEFM ();
02649   _RETM (transpose (*m));
02650 }
02651 
02652 constant * evaluate::transpose_mv (constant * args) {
02653   _ARMV0 (mv);
02654   _DEFMV ();
02655   _RETMV (transpose (*mv));
02656 }
02657 
02658 constant * evaluate::det_m (constant * args) {
02659   _ARM0 (m);
02660   _DEFC ();
02661   _RETC (det (*m));
02662 }
02663 
02664 constant * evaluate::det_mv (constant * args) {
02665   _ARMV0 (mv);
02666   _DEFV ();
02667   _RETV (det (*mv));
02668 }
02669 
02670 constant * evaluate::eye_m (constant * args) {
02671   _ARI0 (i);
02672   _DEFM ();
02673   _RETM (eye (i));
02674 }
02675 
02676 constant * evaluate::adjoint_m (constant * args) {
02677   _ARM0 (m);
02678   _DEFM ();
02679   _RETM (adjoint (*m));
02680 }
02681 
02682 constant * evaluate::adjoint_mv (constant * args) {
02683   _ARMV0 (mv);
02684   _DEFMV ();
02685   _RETMV (adjoint (*mv));
02686 }
02687 
02688 // ***************** s-parameter stability factors *****************
02689 constant * evaluate::rollet_m (constant * args) {
02690   _ARM0 (m);
02691   _DEFD ();
02692   _RETD (rollet (*m));
02693 }
02694 
02695 constant * evaluate::rollet_mv (constant * args) {
02696   _ARMV0 (mv);
02697   _DEFV ();
02698   _RETV (rollet (*mv));
02699 }
02700 
02701 constant * evaluate::mu1_m (constant * args) {
02702   _ARM0 (m);
02703   _DEFD ();
02704   nr_double_t k;
02705   k = (1 - norm (m->get (0, 0))) /
02706     (abs (m->get (1, 1) - conj (m->get (0, 0)) * det (*m)) +
02707      abs (m->get (0, 1) * m->get (1, 0)));
02708   _RETD (k);
02709 }
02710 
02711 constant * evaluate::mu1_mv (constant * args) {
02712   _ARMV0 (mv);
02713   _DEFV ();
02714   qucs::vector k;
02715   k = (1 - norm (mv->get (0, 0))) /
02716     (abs (mv->get (1, 1) - conj (mv->get (0, 0)) * det (*mv)) +
02717      abs (mv->get (0, 1) * mv->get (1, 0)));
02718   _RETV (k);
02719 }
02720 
02721 constant * evaluate::mu2_m (constant * args) {
02722   _ARM0 (m);
02723   _DEFD ();
02724   nr_double_t k;
02725   k = (1 - norm (m->get (1, 1))) /
02726     (abs (m->get (0, 0) - conj (m->get (1, 1)) * det (*m)) +
02727      abs (m->get (0, 1) * m->get (1, 0)));
02728   _RETD (k);
02729 }
02730 
02731 constant * evaluate::mu2_mv (constant * args) {
02732   _ARMV0 (mv);
02733   _DEFV ();
02734   qucs::vector k;
02735   k = (1 - norm (mv->get (1, 1))) /
02736     (abs (mv->get (0, 0) - conj (mv->get (1, 1)) * det (*mv)) +
02737      abs (mv->get (0, 1) * mv->get (1, 0)));
02738   _RETV (k);
02739 }
02740 
02741 constant * evaluate::b1_m (constant * args) {
02742   _ARM0 (m);
02743   _DEFD ();
02744   _RETD (b1 (*m));
02745 }
02746 
02747 constant * evaluate::b1_mv (constant * args) {
02748   _ARMV0 (mv);
02749   _DEFV ();
02750   _RETV (b1 (*mv));
02751 }
02752 
02753 // ***************** vector creation *****************
02754 constant * evaluate::linspace (constant * args) {
02755   _ARD0 (start);
02756   _ARD1 (stop);
02757   _ARI2 (points);
02758   _DEFV ();
02759   if (points < 2) {
02760     THROW_MATH_EXCEPTION ("linspace: number of points must be greater than 1");
02761     res->v = new qucs::vector ();
02762     return res;
02763   }
02764   _RETV (qucs::linspace (start, stop, points));
02765 }
02766 
02767 constant * evaluate::logspace (constant * args) {
02768   _ARD0 (start);
02769   _ARD1 (stop);
02770   _ARI2 (points);
02771   _DEFV ();
02772   if (points < 2) {
02773     THROW_MATH_EXCEPTION ("logspace: number of points must be greater than 1");
02774     res->v = new qucs::vector ();
02775     return res;
02776   }
02777   if (start * stop <= 0) {
02778     THROW_MATH_EXCEPTION ("logspace: invalid start/stop values");
02779     res->v = new qucs::vector (points);
02780     return res;
02781   }
02782   _RETV (qucs::logspace (start, stop, points));
02783 }
02784 
02785 // Circle helper macro with a number of points given.
02786 #define CIRCLE_HELPER_D(argi)                   \
02787   int n = INT (args->getResult (argi));         \
02788   if (n < 2) {                                  \
02789     THROW_MATH_EXCEPTION ("Circle: number of points must be greater than 1"); \
02790     _DEFV (); \
02791     res->v = new qucs::vector ();                       \
02792     return res;                                 \
02793   }                                             \
02794   constant * arg = new constant (TAG_VECTOR);   \
02795   arg->v = new qucs::vector (qucs::linspace (0, 360, n));       \
02796   arg->solvee = args->getResult(0)->solvee;     \
02797   arg->evaluate ();                             \
02798   delete args->get(argi);                       \
02799   args->get((argi)-1)->setNext (NULL);          \
02800   args->append (arg);
02801 
02802 // Circle helper macro with no additional argument given.
02803 #define CIRCLE_HELPER_A()                        \
02804   constant * arg = new constant (TAG_VECTOR);    \
02805   arg->v = new qucs::vector (qucs::linspace (0, 360, 64));      \
02806   arg->solvee = args->getResult(0)->solvee;      \
02807   arg->evaluate ();                              \
02808   args->append (arg);
02809 
02810 // ***************** s-parameter noise circles *****************
02811 constant * evaluate::noise_circle_d_v (constant * args) {
02812   qucs::vector * Sopt = V (_ARES(0));
02813   qucs::vector * Fmin = V (_ARES(1));
02814   qucs::vector * Rn   = V (_ARES(2));
02815   nr_double_t F = D (_ARES(3));
02816   qucs::vector * arc  = V (_ARES(4));
02817 
02818   _DEFV ();
02819   qucs::vector N = circuit::z0 / 4 / *Rn * (F - *Fmin) * norm (1 + *Sopt);
02820   qucs::vector R = sqrt (N * N + N * (1 - norm (*Sopt))) / (1 + N);
02821   qucs::vector C = *Sopt / (1 + N);
02822   qucs::vector * circle = new qucs::vector (C.getSize () * arc->getSize ());
02823   int i, a, j; nr_complex_t v;
02824   for (i = 0, j = 0; i < C.getSize (); i++) {
02825     for (a = 0; a < arc->getSize (); a++, j++) {
02826       v = C.get (i) + R.get (i) * exp (nr_complex_t (0, 1) * deg2rad (arc->get (a)));
02827       circle->set (v, j);
02828     }
02829   }
02830 
02831   node * gen = SOLVEE(4)->addGeneratedEquation (arc, "Arcs");
02832   res->addPrepDependencies (A(gen)->result);
02833   res->v = circle;
02834   return res;
02835 }
02836 
02837 constant * evaluate::noise_circle_d_d (constant * args) {
02838   CIRCLE_HELPER_D (4);
02839   return noise_circle_d_v (args);
02840 }
02841 
02842 constant * evaluate::noise_circle_d (constant * args) {
02843   CIRCLE_HELPER_A ();
02844   return noise_circle_d_v (args);
02845 }
02846 
02847 constant * evaluate::noise_circle_v_v (constant * args) {
02848   qucs::vector * Sopt = V (_ARES(0));
02849   qucs::vector * Fmin = V (_ARES(1));
02850   qucs::vector * Rn   = V (_ARES(2));
02851   qucs::vector * F    = V (_ARES(3));
02852   :: vector * arc  = V (_ARES(4));
02853 
02854   _DEFV ();
02855   qucs::vector * circle =
02856       new qucs::vector (Sopt->getSize () * arc->getSize () * F->getSize ());
02857   int i, a, j, f; nr_complex_t v; qucs::vector N, R, C;
02858   for (f = 0; f < F->getSize (); f++) {
02859     N = circuit::z0 / 4 / *Rn * (F->get (f) - *Fmin) * norm (1 + *Sopt);
02860     R = sqrt (N * N + N * (1 - norm (*Sopt))) / (1 + N);
02861     C = *Sopt / (1 + N);
02862     for (i = 0; i < C.getSize (); i++) {
02863       for (a = 0; a < arc->getSize (); a++) {
02864         v = C.get (i) + R.get (i) * exp (nr_complex_t (0, 1) * deg2rad (arc->get (a)));
02865         j = i * F->getSize () * arc->getSize () + f * arc->getSize () + a;
02866         circle->set (v, j);
02867       }
02868     }
02869   }
02870 
02871   node * gen;
02872   gen = SOLVEE(3)->addGeneratedEquation (F, "NF");
02873   res->addPrepDependencies (A(gen)->result);
02874   gen = SOLVEE(4)->addGeneratedEquation (arc, "Arcs");
02875   res->addPrepDependencies (A(gen)->result);
02876 
02877   res->v = circle;
02878   return res;
02879 }
02880 
02881 constant * evaluate::noise_circle_v_d (constant * args) {
02882   CIRCLE_HELPER_D (4);
02883   return noise_circle_v_v (args);
02884 }
02885 
02886 constant * evaluate::noise_circle_v (constant * args) {
02887   CIRCLE_HELPER_A ();
02888   return noise_circle_v_v (args);
02889 }
02890 
02891 // ***************** s-parameter stability circles *****************
02892 constant * evaluate::stab_circle_l_v (constant * args) {
02893   _ARMV0 (S);
02894   _ARV1 (arc);
02895   _DEFV ();
02896   qucs::vector D = norm (S->get (1, 1)) - norm (det (*S));
02897   qucs::vector C = (conj (S->get (1, 1)) - S->get (0, 0) * conj (det (*S))) / D;
02898   qucs::vector R = abs (S->get (0, 1)) * abs (S->get (1, 0)) / D;
02899   qucs::vector * circle = new qucs::vector (S->getSize () * arc->getSize ());
02900   int a, d, i; nr_complex_t v;
02901   for (i = 0, d = 0; i < S->getSize (); i++) {
02902     for (a = 0; a < arc->getSize (); a++, d++) {
02903       v = C.get (i) + R.get (i) * exp (nr_complex_t (0, 1) * deg2rad (arc->get (a)));
02904       circle->set (v, d);
02905     }
02906   }
02907   node * gen = SOLVEE(1)->addGeneratedEquation (arc, "Arcs");
02908   res->addPrepDependencies (A(gen)->result);
02909   res->v = circle;
02910   return res;
02911 }
02912 
02913 constant * evaluate::stab_circle_l_d (constant * args) {
02914   CIRCLE_HELPER_D (1);
02915   return stab_circle_l_v (args);
02916 }
02917 
02918 constant * evaluate::stab_circle_l (constant * args) {
02919   CIRCLE_HELPER_A ();
02920   return stab_circle_l_v (args);
02921 }
02922 
02923 constant * evaluate::stab_circle_s_v (constant * args) {
02924   _ARMV0 (S);
02925   _ARV1 (arc);
02926   _DEFV ();
02927   qucs::vector D = norm (S->get (0, 0)) - norm (det (*S));
02928   qucs::vector C = (conj (S->get (0, 0)) - S->get (1, 1) * conj (det (*S))) / D;
02929   qucs::vector R = abs (S->get (0, 1)) * abs (S->get (1, 0)) / D;
02930   qucs::vector * circle = new qucs::vector (S->getSize () * arc->getSize ());
02931   int a, d, i; nr_complex_t v;
02932   for (i = 0, d = 0; i < S->getSize (); i++) {
02933     for (a = 0; a < arc->getSize (); a++, d++) {
02934       v = C.get (i) + R.get (i) * exp (nr_complex_t (0, 1) * deg2rad (arc->get (a)));
02935       circle->set (v, d);
02936     }
02937   }
02938   node * gen = SOLVEE(1)->addGeneratedEquation (arc, "Arcs");
02939   res->addPrepDependencies (A(gen)->result);
02940   res->v = circle;
02941   return res;
02942 }
02943 
02944 constant * evaluate::stab_circle_s_d (constant * args) {
02945   CIRCLE_HELPER_D (1);
02946   return stab_circle_s_v (args);
02947 }
02948 
02949 constant * evaluate::stab_circle_s (constant * args) {
02950   CIRCLE_HELPER_A ();
02951   return stab_circle_s_v (args);
02952 }
02953 
02954 // ***************** s-parameter gain circles *****************
02955 constant * evaluate::ga_circle_d_v (constant * args) {
02956   _ARMV0 (S);
02957   _ARD1 (G);
02958   _ARV2 (arc);
02959   _DEFV ();
02960   qucs::vector g, D, c, s, k, C, R, d;
02961   D = det (*S);
02962   c = S->get (0, 0) - conj (S->get (1, 1)) * D;
02963   k = rollet (*S);
02964   s = S->get (0, 1) * S->get (1, 0);
02965   g = G / norm (S->get (1, 0));
02966   d = 1 + g * (norm (S->get (0, 0)) - norm (D));
02967   C = g * conj (c) / d;
02968   R = sqrt (1 - 2 * k * g * abs (s) + g * g * norm (s)) / abs (d);
02969 
02970   qucs::vector * circle = new qucs::vector (S->getSize () * arc->getSize ());
02971   int i, a, j; nr_complex_t v;
02972   for (i = 0, j = 0; i < C.getSize (); i++) {
02973     for (a = 0; a < arc->getSize (); a++, j++) {
02974       v = C.get (i) + R.get (i) * exp (nr_complex_t (0, 1) * deg2rad (arc->get (a)));
02975       circle->set (v, j);
02976     }
02977   }
02978 
02979   node * gen = SOLVEE(2)->addGeneratedEquation (arc, "Arcs");
02980   res->addPrepDependencies (A(gen)->result);
02981   res->v = circle;
02982   return res;
02983 }
02984 
02985 constant * evaluate::ga_circle_d_d (constant * args) {
02986   CIRCLE_HELPER_D (2);
02987   return ga_circle_d_v (args);
02988 }
02989 
02990 constant * evaluate::ga_circle_d (constant * args) {
02991   CIRCLE_HELPER_A ();
02992   return ga_circle_d_v (args);
02993 }
02994 
02995 constant * evaluate::ga_circle_v_v (constant * args) {
02996   _ARMV0 (S);
02997   _ARV1 (G);
02998   _ARV2 (arc);
02999   _DEFV ();
03000   qucs::vector * circle =
03001     new qucs::vector (S->getSize () * arc->getSize () * G->getSize ());
03002   int i, a, j, f; nr_complex_t v; qucs::vector g, D, c, s, k, R, C, d;
03003   D = det (*S);
03004   c = S->get (0, 0) - conj (S->get (1, 1)) * D;
03005   k = rollet (*S);
03006   s = S->get (0, 1) * S->get (1, 0);
03007   for (f = 0; f < G->getSize (); f++) {
03008     g = G->get (f) / norm (S->get (1, 0));
03009     d = 1 + g * (norm (S->get (0, 0)) - norm (D));
03010     C = g * conj (c) / d;
03011     R = sqrt (1 - 2 * k * g * abs (s) + g * g * norm (s)) / abs (d);
03012     for (i = 0; i < C.getSize (); i++) {
03013       for (a = 0; a < arc->getSize (); a++) {
03014         v = C.get (i) + R.get (i) * exp (nr_complex_t (0, 1) * deg2rad (arc->get (a)));
03015         j = i * G->getSize () * arc->getSize () + f * arc->getSize () + a;
03016         circle->set (v, j);
03017       }
03018     }
03019   }
03020 
03021   node * gen;
03022   gen = SOLVEE(1)->addGeneratedEquation (G, "Ga");
03023   res->addPrepDependencies (A(gen)->result);
03024   gen = SOLVEE(2)->addGeneratedEquation (arc, "Arcs");
03025   res->addPrepDependencies (A(gen)->result);
03026   res->v = circle;
03027   return res;
03028 }
03029 
03030 constant * evaluate::ga_circle_v_d (constant * args) {
03031   CIRCLE_HELPER_D (2);
03032   return ga_circle_v_v (args);
03033 }
03034 
03035 constant * evaluate::ga_circle_v (constant * args) {
03036   CIRCLE_HELPER_A ();
03037   return ga_circle_v_v (args);
03038 }
03039 
03040 constant * evaluate::gp_circle_d_v (constant * args) {
03041   _ARMV0 (S);
03042   _ARD1 (G);
03043   _ARV2 (arc);
03044   _DEFV ();
03045   qucs::vector g, D, c, s, k, C, R, d;
03046   D = det (*S);
03047   c = S->get (1, 1) - conj (S->get (0, 0)) * D;
03048   k = rollet (*S);
03049   s = S->get (0, 1) * S->get (1, 0);
03050   g = G / norm (S->get (1, 0));
03051   d = 1 + g * (norm (S->get (1, 1)) - norm (D));
03052   C = g * conj (c) / d;
03053   R = sqrt (1 - 2 * k * g * abs (s) + g * g * norm (s)) / abs (d);
03054 
03055   qucs::vector * circle = new qucs::vector (S->getSize () * arc->getSize ());
03056   int i, a, j; nr_complex_t v;
03057   for (i = 0, j = 0; i < C.getSize (); i++) {
03058     for (a = 0; a < arc->getSize (); a++, j++) {
03059       v = C.get (i) + R.get (i) * exp (nr_complex_t (0, 1) * deg2rad (arc->get (a)));
03060       circle->set (v, j);
03061     }
03062   }
03063 
03064   node * gen = SOLVEE(2)->addGeneratedEquation (arc, "Arcs");
03065   res->addPrepDependencies (A(gen)->result);
03066   res->v = circle;
03067   return res;
03068 }
03069 
03070 constant * evaluate::gp_circle_d_d (constant * args) {
03071   CIRCLE_HELPER_D (2);
03072   return gp_circle_d_v (args);
03073 }
03074 
03075 constant * evaluate::gp_circle_d (constant * args) {
03076   CIRCLE_HELPER_A ();
03077   return gp_circle_d_v (args);
03078 }
03079 
03080 constant * evaluate::gp_circle_v_v (constant * args) {
03081   _ARMV0 (S);
03082   _ARV1 (G);
03083   _ARV2 (arc);
03084   _DEFV ();
03085   qucs::vector * circle =
03086       new qucs::vector (S->getSize () * arc->getSize () * G->getSize ());
03087   int i, a, j, f; nr_complex_t v; qucs::vector g, D, c, s, k, R, C, d;
03088   D = det (*S);
03089   c = S->get (1, 1) - conj (S->get (0, 0)) * D;
03090   k = rollet (*S);
03091   s = S->get (0, 1) * S->get (1, 0);
03092   for (f = 0; f < G->getSize (); f++) {
03093     g = G->get (f) / norm (S->get (1, 0));
03094     d = 1 + g * (norm (S->get (1, 1)) - norm (D));
03095     C = g * conj (c) / d;
03096     R = sqrt (1 - 2 * k * g * abs (s) + g * g * norm (s)) / abs (d);
03097     for (i = 0; i < C.getSize (); i++) {
03098       for (a = 0; a < arc->getSize (); a++) {
03099         v = C.get (i) + R.get (i) * exp (nr_complex_t (0, 1) * deg2rad (arc->get (a)));
03100         j = i * G->getSize () * arc->getSize () + f * arc->getSize () + a;
03101         circle->set (v, j);
03102       }
03103     }
03104   }
03105 
03106   node * gen;
03107   gen = SOLVEE(1)->addGeneratedEquation (G, "Gp");
03108   res->addPrepDependencies (A(gen)->result);
03109   gen = SOLVEE(2)->addGeneratedEquation (arc, "Arcs");
03110   res->addPrepDependencies (A(gen)->result);
03111   res->v = circle;
03112   return res;
03113 }
03114 
03115 constant * evaluate::gp_circle_v_d (constant * args) {
03116   CIRCLE_HELPER_D (2);
03117   return gp_circle_v_v (args);
03118 }
03119 
03120 constant * evaluate::gp_circle_v (constant * args) {
03121   CIRCLE_HELPER_A ();
03122   return gp_circle_v_v (args);
03123 }
03124 
03125 // ***************** versus vectors *****************
03126 constant * evaluate::plot_vs_v (constant * args) {
03127   _ARV0 (v);
03128   _DEFV ();
03129   int i = 1;
03130   for (node * arg = args->getNext (); arg != NULL; arg = arg->getNext ()) {
03131     node * gen = arg->solvee->addGeneratedEquation (V (_ARES (i)), "Versus");
03132     res->addPrepDependencies (A(gen)->result);
03133     i++;
03134   }
03135   res->dropdeps = 1;
03136   _RETV (*v);
03137 }
03138 
03139 constant * evaluate::plot_vs_mv (constant * args) {
03140   _ARMV0 (mv);
03141   _DEFMV ();
03142   int i = 1;
03143   for (node * arg = args->getNext (); arg != NULL; arg = arg->getNext ()) {
03144     node * gen = arg->solvee->addGeneratedEquation (V (_ARES (i)), "Versus");
03145     res->addPrepDependencies (A(gen)->result);
03146     i++;
03147   }
03148   res->dropdeps = 1;
03149   _RETMV (*mv);
03150 }
03151 
03152 // ***************** find x-value for given y-value *****************
03153 constant * evaluate::xvalue_d (constant * args) {
03154   _ARV0 (v);
03155   _ARD1 (d);
03156   _DEFC ();
03157   strlist * deps = _ARG(0)->collectDataDependencies ();
03158   if (!deps || deps->length () != 1) {
03159     THROW_MATH_EXCEPTION ("not an appropriate dependent data vector");
03160     _RETC (0.0);
03161   }
03162   qucs::vector * indep = SOLVEE(0)->getDataVector (deps->get (0));
03163   int idx, i;
03164   nr_double_t t, diff = std::numeric_limits<nr_double_t>::max();
03165   for (idx = i = 0; i < v->getSize (); i++) {
03166     t = abs (v->get (i) - d);
03167     if (t < diff) {
03168       idx = i;
03169       diff = t;
03170     }
03171   }
03172   _RETC (indep->get (idx));
03173 }
03174 
03175 constant * evaluate::xvalue_c (constant * args) {
03176   _ARV0 (v);
03177   _ARC1 (c);
03178   _DEFC ();
03179   strlist * deps = _ARG(0)->collectDataDependencies ();
03180   if (!deps || deps->length () != 1) {
03181     THROW_MATH_EXCEPTION ("not an appropriate dependent data vector");
03182     _RETC (0.0);
03183   }
03184   qucs::vector * indep = SOLVEE(0)->getDataVector (deps->get (0));
03185   int idx, i;
03186   nr_double_t t, diff = std::numeric_limits<nr_double_t>::max();
03187   for (idx = i = 0; i < v->getSize (); i++) {
03188     t = abs (v->get (i) - *c);
03189     if (t < diff) {
03190       idx = i;
03191       diff = t;
03192     }
03193   }
03194   _RETC (indep->get (idx));
03195 }
03196 
03197 // ***************** find y-value for given x-value *****************
03198 constant * evaluate::yvalue_d (constant * args) {
03199   _ARV0 (v);
03200   _ARD1 (d);
03201   _DEFC ();
03202   strlist * deps = _ARG(0)->collectDataDependencies ();
03203   if (!deps || deps->length () != 1) {
03204     THROW_MATH_EXCEPTION ("not an appropriate dependent data vector");
03205     _RETC (0.0);
03206   }
03207   qucs::vector * indep = SOLVEE(0)->getDataVector (deps->get (0));
03208   int idx, i;
03209   nr_double_t t, diff = std::numeric_limits<nr_double_t>::max();
03210   for (idx = i = 0; i < indep->getSize (); i++) {
03211     t = abs (indep->get (i) - d);
03212     if (t < diff) {
03213       idx = i;
03214       diff = t;
03215     }
03216   }
03217   _RETC (v->get (idx));
03218 }
03219 
03220 constant * evaluate::yvalue_c (constant * args) {
03221   _ARV0 (v);
03222   _ARC1 (c);
03223   _DEFC ();
03224   strlist * deps = _ARG(0)->collectDataDependencies ();
03225   if (!deps || deps->length () != 1) {
03226     THROW_MATH_EXCEPTION ("not an appropriate dependent data vector");
03227     _RETC (0.0);
03228   }
03229   qucs::vector * indep = SOLVEE(0)->getDataVector (deps->get (0));
03230   int idx, i;
03231   nr_double_t t, diff = std::numeric_limits<nr_double_t>::max();
03232   for (idx = i = 0; i < indep->getSize (); i++) {
03233     t = abs (indep->get (i) - *c);
03234     if (t < diff) {
03235       idx = i;
03236       diff = t;
03237     }
03238   }
03239   _RETC (v->get (idx));
03240 }
03241 
03242 // ***************** min, max, avg using range specification *****************
03243 constant * evaluate::max_r (constant * args) {
03244   _ARV0 (v);
03245   _ARR1 (r);
03246   _DEFD ();
03247   strlist * deps = _ARG(0)->collectDataDependencies ();
03248   if (!deps || deps->length () != 1) {
03249     THROW_MATH_EXCEPTION ("not an appropriate dependent data vector");
03250     _RETD (0.0);
03251   }
03252   qucs::vector * indep = SOLVEE(0)->getDataVector (deps->get (0));
03253   nr_complex_t c;
03254   nr_double_t d, M = -std::numeric_limits<nr_double_t>::max();
03255   for (int i = 0; i < indep->getSize (); i++) {
03256     if (r->inside (real (indep->get (i)))) {
03257       c = v->get (i);
03258       d = fabs (arg (c)) < pi_over_2 ? abs (c) : -abs (c);
03259       if (d > M) M = d;
03260     }
03261   }
03262   _RETD (M);
03263 }
03264 
03265 constant * evaluate::min_r (constant * args) {
03266   _ARV0 (v);
03267   _ARR1 (r);
03268   _DEFD ();
03269   strlist * deps = _ARG(0)->collectDataDependencies ();
03270   if (!deps || deps->length () != 1) {
03271     THROW_MATH_EXCEPTION ("not an appropriate dependent data vector");
03272     _RETD (0.0);
03273   }
03274   qucs::vector * indep = SOLVEE(0)->getDataVector (deps->get (0));
03275   nr_complex_t c;
03276   nr_double_t d, M = +std::numeric_limits<nr_double_t>::max();
03277   for (int i = 0; i < indep->getSize (); i++) {
03278     if (r->inside (real (indep->get (i)))) {
03279       c = v->get (i);
03280       d = fabs (arg (c)) < pi_over_2 ? abs (c) : -abs (c);
03281       if (d < M) M = d;
03282     }
03283   }
03284   _RETD (M);
03285 }
03286 
03287 constant * evaluate::avg_r (constant * args) {
03288   _ARV0 (v);
03289   _ARR1 (r);
03290   _DEFC ();
03291   strlist * deps = _ARG(0)->collectDataDependencies ();
03292   if (!deps || deps->length () != 1) {
03293     THROW_MATH_EXCEPTION ("not an appropriate dependent data vector");
03294     _RETC (0.0);
03295   }
03296   qucs::vector * indep = SOLVEE(0)->getDataVector (deps->get (0));
03297   nr_complex_t c = 0.0;
03298   int i, k;
03299   for (k = i = 0; i < indep->getSize (); i++) {
03300     if (r->inside (real (indep->get (i)))) {
03301       c += v->get (i);
03302       k++;
03303     }
03304   }
03305   _RETC (c / (nr_double_t) k);
03306 }
03307 
03308 // *************** range functionality *****************
03309 constant * evaluate::range_d_d (constant * args) {
03310   _ARD0 (d1);
03311   _ARD1 (d2);
03312   _DEFR ();
03313   _RETR (new range ('[', d1, d2, ']'));
03314 }
03315 
03316 constant * evaluate::range_c_d (constant * args) {
03317   _ARD1 (d2);
03318   _DEFR ();
03319   _RETR (new range ('.', d2 - 1, d2, ']'));
03320 }
03321 
03322 constant * evaluate::range_d_c (constant * args) {
03323   _ARD0 (d1);
03324   _DEFR ();
03325   _RETR (new range ('[', d1, d1 + 1, '.'));
03326 }
03327 
03328 constant * evaluate::range_c_c (constant *) {
03329   _DEFR ();
03330   _RETR (new range ('.', 0, 0, '.'));
03331 }
03332 
03333 MAKE_FUNC_DEFINITION_0_STD (ceil);        // ceil double->integer conversion
03334 MAKE_FUNC_DEFINITION_0_STD (floor);       // floor double->integer conversion
03335 MAKE_FUNC_DEFINITION_0_QUCS (fix);        // fix double->integer conversion
03336 MAKE_FUNC_DEFINITION_0_QUCS (step);       // step function
03337 MAKE_FUNC_DEFINITION_0_QUCS (round);      // round function
03338 //#ifndef HAVE_ERF
03339 MAKE_FUNC_DEFINITION_0_SPECIAL (erf);     // error function
03340 //#else
03341 //MAKE_FUNC_DEFINITION_0_STD (erf);     // error function
03342 //#endif
03343 //#ifndef HAVE_ERFC
03344 MAKE_FUNC_DEFINITION_0_SPECIAL (erfc);    // complementary error function
03345 //#else
03346 //MAKE_FUNC_DEFINITION_0_STD (erfc);    // complementary error function
03347 //#endif
03348 MAKE_FUNC_DEFINITION_0_SPECIAL (erfinv);  // inverse of error function
03349 MAKE_FUNC_DEFINITION_0_SPECIAL (erfcinv); // inverse of complementary error function
03350 MAKE_FUNC_DEFINITION_0_SPECIAL (i0);      // modified bessel zero order
03351 
03352 // ******************* cumulative sum *********************
03353 constant * evaluate::cumsum_d (constant * args) {
03354   _ARD0 (d1);
03355   _DEFD ();
03356   _RETD (d1);
03357 }
03358 
03359 constant * evaluate::cumsum_c (constant * args) {
03360   _ARC0 (c1);
03361   _DEFC ();
03362   _RETC (*c1);
03363 }
03364 
03365 constant * evaluate::cumsum_v (constant * args) {
03366   _ARV0 (v1);
03367   _DEFV ();
03368   _RETV (cumsum (*v1));
03369 }
03370 
03371 // **************** cumulative average ******************
03372 constant * evaluate::cumavg_d (constant * args) {
03373   _ARD0 (d1);
03374   _DEFD ();
03375   _RETD (d1);
03376 }
03377 
03378 constant * evaluate::cumavg_c (constant * args) {
03379   _ARC0 (c1);
03380   _DEFC ();
03381   _RETC (*c1);
03382 }
03383 
03384 constant * evaluate::cumavg_v (constant * args) {
03385   _ARV0 (v1);
03386   _DEFV ();
03387   _RETV (cumavg (*v1));
03388 }
03389 
03390 // ******************* cumulative product *********************
03391 constant * evaluate::cumprod_d (constant * args) {
03392   _ARD0 (d1);
03393   _DEFD ();
03394   _RETD (d1);
03395 }
03396 
03397 constant * evaluate::cumprod_c (constant * args) {
03398   _ARC0 (c1);
03399   _DEFC ();
03400   _RETC (*c1);
03401 }
03402 
03403 constant * evaluate::cumprod_v (constant * args) {
03404   _ARV0 (v1);
03405   _DEFV ();
03406   _RETV (cumprod (*v1));
03407 }
03408 
03409 // ******************* rms *********************
03410 constant * evaluate::rms_d (constant * args) {
03411   _ARD0 (d1);
03412   _DEFD ();
03413   _RETD (fabs (d1));
03414 }
03415 
03416 constant * evaluate::rms_c (constant * args) {
03417   _ARC0 (c1);
03418   _DEFD ();
03419   _RETD (abs (*c1));
03420 }
03421 
03422 constant * evaluate::rms_v (constant * args) {
03423   _ARV0 (v1);
03424   _DEFD ();
03425   _RETD (v1->rms ());
03426 }
03427 
03428 // ******************* variance *********************
03429 constant * evaluate::variance_d (constant *) {
03430   _DEFD ();
03431   _RETD (0);
03432 }
03433 
03434 constant * evaluate::variance_c (constant *) {
03435   _DEFD ();
03436   _RETD (0);
03437 }
03438 
03439 constant * evaluate::variance_v (constant * args) {
03440   _ARV0 (v1);
03441   _DEFD ();
03442   _RETD (v1->variance ());
03443 }
03444 
03445 // ******************* stddev *********************
03446 constant * evaluate::stddev_d (constant *) {
03447   _DEFD ();
03448   _RETD (0);
03449 }
03450 
03451 constant * evaluate::stddev_c (constant *) {
03452   _DEFD ();
03453   _RETD (0);
03454 }
03455 
03456 constant * evaluate::stddev_v (constant * args) {
03457   _ARV0 (v1);
03458   _DEFD ();
03459   _RETD (v1->stddev ());
03460 }
03461 
03462 // ********* jn (bessel function of 1st kind, nth order) ***********
03463 constant * evaluate::jn_d_d (constant * args) {
03464   _ARI0 (n);
03465   _ARD1 (x);
03466   _DEFD ();
03467   _RETD (::jn (n, x));
03468 }
03469 
03470 constant * evaluate::jn_d_c (constant * args) {
03471   _ARI0 (n);
03472   _ARC1 (x);
03473   _DEFC ();
03474   _RETC (jn (n, *x));
03475 }
03476 
03477 constant * evaluate::jn_d_v (constant * args) {
03478   _ARI0 (n);
03479   _ARV1 (x);
03480   _DEFV ();
03481   _RETV (jn (n, *x));
03482 }
03483 
03484 // ********* yn (bessel function of 2nd kind, nth order) ***********
03485 constant * evaluate::yn_d_d (constant * args) {
03486   _ARI0 (n);
03487   _ARD1 (x);
03488   _DEFD ();
03489   _RETD (::yn (n, x));
03490 }
03491 
03492 constant * evaluate::yn_d_c (constant * args) {
03493   _ARI0 (n);
03494   _ARC1 (x);
03495   _DEFC ();
03496   _RETC (yn (n, *x));
03497 }
03498 
03499 constant * evaluate::yn_d_v (constant * args) {
03500   _ARI0 (n);
03501   _ARV1 (x);
03502   _DEFV ();
03503   _RETV (yn (n, *x));
03504 }
03505 
03506 // ***************** sqr *****************
03507 constant * evaluate::sqr_m (constant * args) {
03508   _ARM0 (m1);
03509   _DEFM ();
03510   _RETM (qucs::sqr (*m1));
03511 }
03512 
03513 constant * evaluate::sqr_mv (constant * args) {
03514   _ARMV0 (m1);
03515   _DEFMV ();
03516   _RETMV (qucs::sqr (*m1));
03517 }
03518 
03519 // ******************* polar *********************
03520 constant * evaluate::polar_d_d (constant * args) {
03521   _ARD0 (a);
03522   _ARD1 (p);
03523   _DEFC ();
03524   _RETC (std::polar (a, deg2rad (p)));
03525 }
03526 
03527 constant * evaluate::polar_c_d (constant * args) {
03528   _ARC0 (a);
03529   _ARD1 (p);
03530   _DEFC ();
03531   _RETC (qucs::polar (*a, nr_complex_t (deg2rad (p), 0)));
03532 }
03533 
03534 constant * evaluate::polar_d_c (constant * args) {
03535   _ARD0 (a);
03536   _ARC1 (p);
03537   _DEFC ();
03539   _RETC (qucs::polar (nr_complex_t (a, 0), nr_complex_t (deg2rad (*p),0)));
03540 }
03541 
03542 constant * evaluate::polar_c_c (constant * args) {
03543   _ARC0 (a);
03544   _ARC1 (p);
03545   _DEFC ();
03547   _RETC (qucs::polar (*a, nr_complex_t (deg2rad (*p), 0)));
03548 }
03549 
03550 constant * evaluate::polar_d_v (constant * args) {
03551   _ARD0 (a);
03552   _ARV1 (v);
03553   _DEFV ();
03554   _RETV (polar (nr_complex_t (a, 0), deg2rad (*v)));
03555 }
03556 
03557 constant * evaluate::polar_c_v (constant * args) {
03558   _ARC0 (a);
03559   _ARV1 (v);
03560   _DEFV ();
03561   _RETV (polar (*a, deg2rad (*v)));
03562 }
03563 
03564 constant * evaluate::polar_v_d (constant * args) {
03565   _ARV0 (v);
03566   _ARD1 (p);
03567   _DEFV ();
03568   _RETV (polar (*v, nr_complex_t (deg2rad (p), 0)));
03569 }
03570 
03571 constant * evaluate::polar_v_c (constant * args) {
03572   _ARV0 (v);
03573   _ARC1 (p);
03574   _DEFV ();
03575   _RETV (polar (*v, nr_complex_t (deg2rad (*p),0)));
03576 }
03577 
03578 constant * evaluate::polar_v_v (constant * args) {
03579   _ARV0 (a);
03580   _ARV1 (p);
03581   _DEFV ();
03582   _RETV (polar (*a, deg2rad (*p)));
03583 }
03584 
03585 // ******************* arctan2 *********************
03586 constant * evaluate::arctan2_d_d (constant * args) {
03587   _ARD0 (y);
03588   _ARD1 (x);
03589   _DEFD ();
03590   if ((x == 0) && (y == 0)) {
03591     THROW_MATH_EXCEPTION ("arctan2: not defined for (0,0)");
03592     _RETD (-pi / 2);
03593   }
03594   _RETD (std::atan2 (y, x));
03595 }
03596 
03597 constant * evaluate::arctan2_d_v (constant * args) {
03598   _ARD0 (y);
03599   _ARV1 (x);
03600   _DEFV ();
03601   _RETV (atan2 (y, *x));
03602 }
03603 
03604 constant * evaluate::arctan2_v_d (constant * args) {
03605   _ARV0 (y);
03606   _ARD1 (x);
03607   _DEFV ();
03608   _RETV (atan2 (*y, x));
03609 }
03610 
03611 constant * evaluate::arctan2_v_v (constant * args) {
03612   _ARV0 (y);
03613   _ARV1 (x);
03614   _DEFV ();
03615   _RETV (atan2 (*y, *x));
03616 }
03617 
03618 // ******************* dbm2w *********************
03619 constant * evaluate::dbm2w_d (constant * args) {
03620   _ARD0 (d1);
03621   _DEFD ();
03622   _RETD (0.001 * std::pow (10.0, d1 / 10.0));
03623 }
03624 
03625 constant * evaluate::dbm2w_c (constant * args) {
03626   _ARC0 (c1);
03627   _DEFC ();
03628   _RETC (0.001 * pow (10.0, *c1 / 10.0));
03629 }
03630 
03631 constant * evaluate::dbm2w_v (constant * args) {
03632   _ARV0 (v1);
03633   _DEFV ();
03634   _RETV (dbm2w (*v1));
03635 }
03636 
03637 // ******************* w2dbm *********************
03638 constant * evaluate::w2dbm_d (constant * args) {
03639   _ARD0 (d1);
03640   _DEFD ();
03641   _RETD (10.0 * std::log10 (d1 / 0.001));
03642 }
03643 
03644 constant * evaluate::w2dbm_c (constant * args) {
03645   _ARC0 (c1);
03646   _DEFC ();
03647   _RETC (10.0 * log10 (*c1 / 0.001));
03648 }
03649 
03650 constant * evaluate::w2dbm_v (constant * args) {
03651   _ARV0 (v1);
03652   _DEFV ();
03653   _RETV (w2dbm (*v1));
03654 }
03655 
03656 // ********** integrate *****************
03657 constant * evaluate::integrate_d_d (constant * args) {
03658   _ARD0 (data);
03659   _ARD1 (incr);
03660   _DEFD ();
03661   _RETD (data * incr);
03662 }
03663 
03664 constant * evaluate::integrate_c_c (constant * args) {
03665   _ARC0 (data);
03666   _ARC1 (incr);
03667   _DEFC ();
03668   _RETC (*data * *incr);
03669 }
03670 
03671 constant * evaluate::integrate_v_d (constant * args) {
03672   _ARV0 (data);
03673   _ARD1 (incr);
03674   _DEFD ();
03675   _RETD (integrate (*data, incr));
03676 }
03677 
03678 constant * evaluate::integrate_v_c (constant * args) {
03679   _ARV0 (data);
03680   _ARC1 (incr);
03681   _DEFC ();
03682   _RETC (integrate (*data, *incr));
03683 }
03684 
03685 // ******************* dbm *********************
03686 constant * evaluate::dbm_d (constant * args) {
03687   _ARD0 (d1);
03688   _DEFD ();
03689   _RETD (10.0 * std::log10 (norm (d1) / circuit::z0 / 0.001));
03690 }
03691 
03692 constant * evaluate::dbm_d_d (constant * args) {
03693   _ARD0 (d1);
03694   _ARD1 (z);
03695   _DEFD ();
03696   _RETD (10.0 * std::log10 (norm (d1) / z / 0.001));
03697 }
03698 
03699 constant * evaluate::dbm_c (constant * args) {
03700   _ARC0 (c1);
03701   _DEFC ();
03702   _RETC (10.0 * log10 (norm (*c1) / circuit::z0 / 0.001));
03703 }
03704 
03705 constant * evaluate::dbm_c_d (constant * args) {
03706   _ARC0 (c1);
03707   _ARD1 (z);
03708   _DEFC ();
03709   _RETC (10.0 * log10 (norm (*c1) / z / 0.001));
03710 }
03711 
03712 constant * evaluate::dbm_v (constant * args) {
03713   _ARV0 (v1);
03714   _DEFV ();
03715   _RETV (dbm (*v1));
03716 }
03717 
03718 constant * evaluate::dbm_v_d (constant * args) {
03719   _ARV0 (v1);
03720   _ARD1 (z);
03721   _DEFV ();
03722   _RETV (dbm (*v1, z));
03723 }
03724 
03725 constant * evaluate::dbm_d_c (constant * args) {
03726   _ARD0 (d1);
03727   _ARC1 (z);
03728   _DEFC ();
03729   _RETC (10.0 * log10 (norm (d1) / conj (*z) / 0.001));
03730 }
03731 
03732 constant * evaluate::dbm_c_c (constant * args) {
03733   _ARC0 (c1);
03734   _ARC1 (z);
03735   _DEFC ();
03736   _RETC (10.0 * log10 (norm (*c1) / conj (*z) / 0.001));
03737 }
03738 
03739 constant * evaluate::dbm_v_c (constant * args) {
03740   _ARV0 (v1);
03741   _ARC1 (z);
03742   _DEFV ();
03743   _RETV (dbm (*v1, *z));
03744 }
03745 
03746 // ************** running average ****************
03747 constant * evaluate::runavg_d_d (constant * args) {
03748   _ARD0 (x);
03749   _ARI1 (n);
03750   _DEFV ();
03751   if (n < 1) {
03752     THROW_MATH_EXCEPTION ("runavg: number n to be averaged over must be "
03753                           "larger or equal 1");
03754     __RETV ();
03755   }
03756   _RETV (runavg (nr_complex_t (x, 0), n));
03757 }
03758 
03759 constant * evaluate::runavg_c_d (constant * args) {
03760   _ARC0 (x);
03761   _ARI1 (n);
03762   _DEFV ();
03763   if (n < 1) {
03764     THROW_MATH_EXCEPTION ("runavg: number n to be averaged over must be "
03765                           "larger or equal 1");
03766     __RETV ();
03767   }
03768   _RETV (runavg (*x, n));
03769 }
03770 
03771 constant * evaluate::runavg_v_d (constant * args) {
03772   _ARV0 (x);
03773   _ARI1 (n);
03774   _DEFV ();
03775   if (n < 1 || n > x->getSize ()) {
03776     THROW_MATH_EXCEPTION ("runavg: number n to be averaged over must be "
03777                           "larger or equal 1 and less or equal than the "
03778                           "number of vector elements");
03779     __RETV ();
03780   }
03781   _RETV (runavg (*x, n));
03782 }
03783 
03784 // ********************* thermal voltage **********************
03785 constant * evaluate::vt_d (constant * args) {
03786   _ARD0 (d1);
03787   _DEFD ();
03788   _RETD (d1 * kBoverQ);
03789 }
03790 
03791 constant * evaluate::vt_c (constant * args) {
03792   _ARC0 (c1);
03793   _DEFC ();
03794   _RETC (*c1 * kBoverQ);
03795 }
03796 
03797 constant * evaluate::vt_v (constant * args) {
03798   _ARV0 (v1);
03799   _DEFV ();
03800   qucs::vector * v = new qucs::vector ();
03801   for (int i = 0; i < v1->getSize (); i++) v->add (v1->get (i) * kBoverQ);
03802   res->v = v;
03803   return res;
03804 }
03805 
03806 // ************** Kaiser-Bessel derived window ****************
03807 constant * evaluate::kbd_d_d (constant * args) {
03808   _ARD0 (alpha);
03809   _ARI1 (size);
03810   _DEFV ();
03811   int i;
03812   nr_double_t sval = 0.0;
03813   if (size <= 0) {
03814     THROW_MATH_EXCEPTION ("kbd: vector length must be greater than zero");
03815     __RETV ();
03816   }
03817   qucs::vector v (size);
03818   for (i = 0; i < size / 2; i++) {
03819     sval += fspecial::i0 (pi * alpha * std::sqrt (1.0 - sqr (4.0 * i / size - 1.0)));
03820     v (i) = sval;
03821   }
03822   // need to add one more value to the normalization factor at size/2
03823   sval += fspecial::i0 (pi * alpha * std::sqrt (1.0 - sqr (4.0 * (size / 2) / size - 1.0)));
03824   // normalize the window and fill in the righthand side of the window
03825   for (i = 0; i < size / 2; i++) {
03826     v (i) = std::sqrt (v (i) / sval);
03827     v (size - 1 - i) = v (i);
03828   }
03829   _RETV (v);
03830 }
03831 
03832 constant * evaluate::kbd_d (constant * args) {
03833   constant * arg = new constant (TAG_DOUBLE);
03834   arg->d = 64;
03835   arg->solvee = args->getResult(0)->solvee;
03836   arg->evaluate ();
03837   args->append (arg);
03838   return kbd_d_d (args);
03839 }
03840 
03841 // ***************** if-then-else operation ****************
03842 constant * evaluate::ifthenelse_d_d (constant * args) {
03843   _ARB0 (cond);
03844   _ARD1 (d1);
03845   _ARD2 (d2);
03846   _DEFD ();
03847   _RETD (cond ? d1 : d2);
03848 }
03849 
03850 constant * evaluate::ifthenelse_b_b (constant * args) {
03851   _ARB0 (cond);
03852   _ARB1 (b1);
03853   _ARB2 (b2);
03854   _DEFB ();
03855   _RETB (cond ? b1 : b2);
03856 }
03857 
03858 constant * evaluate::ifthenelse_d_b (constant * args) {
03859   _ARB0 (cond);
03860   _ARD1 (d1);
03861   _ARB2 (b2);
03862   _DEFD ();
03863   _RETD (cond ? d1 : (b2 ? 1.0 : 0.0));
03864 }
03865 
03866 constant * evaluate::ifthenelse_b_d (constant * args) {
03867   _ARB0 (cond);
03868   _ARB1 (b1);
03869   _ARD2 (d2);
03870   _DEFD ();
03871   _RETD (cond ? (b1 ? 1.0 : 0.0) : d2);
03872 }
03873 
03874 constant * evaluate::ifthenelse_c_c (constant * args) {
03875   _ARB0 (cond);
03876   int t1 = _ARG(1)->getType ();
03877   int t2 = _ARG(2)->getType ();
03878   nr_complex_t c1, c2;
03879   if (t1 == TAG_DOUBLE)
03880     c1 = D(_ARES(1));
03881   else if (t1 == TAG_COMPLEX)
03882     c1 = *C(_ARES(1));
03883   else
03884     c1 = B(_ARES(1)) ? 1.0 : 0.0;
03885   if (t2 == TAG_DOUBLE)
03886     c2 = D(_ARES(2));
03887   else if (t2 == TAG_COMPLEX)
03888     c2 = *C(_ARES(2));
03889   else
03890     c2 = B(_ARES(2)) ? 1.0 : 0.0;
03891   _DEFC ();
03892   _RETC (cond ? c1 : c2);
03893 }
03894 
03895 constant * evaluate::ifthenelse_m_m (constant * args) {
03896   _ARB0 (cond);
03897   int t1 = _ARG(1)->getType ();
03898   int t2 = _ARG(2)->getType ();
03899   matrix m1, m2;
03900   switch (t1) {
03901   case TAG_DOUBLE:
03902     m1 = matrix (1); m1 (1,1) = D(_ARES(1)); break;
03903   case TAG_COMPLEX:
03904     m1 = matrix (1); m1 (1,1) = *C(_ARES(1)); break;
03905   case TAG_BOOLEAN:
03906     m1 = matrix (1); m1 (1,1) = B(_ARES(1)) ? 1.0 : 0.0; break;
03907   case TAG_MATRIX:
03908     m1 = *M(_ARES(1)); break;
03909   }
03910   switch (t2) {
03911   case TAG_DOUBLE:
03912     m2 = matrix (1); m2 (0,0) = D(_ARES(2)); break;
03913   case TAG_COMPLEX:
03914     m2 = matrix (1); m2 (0,0) = *C(_ARES(2)); break;
03915   case TAG_BOOLEAN:
03916     m2 = matrix (1); m2 (0,0) = B(_ARES(2)) ? 1.0 : 0.0; break;
03917   case TAG_MATRIX:
03918     m2 = *M(_ARES(2)); break;
03919   }
03920   _DEFM ();
03921   _RETM (cond ? m1 : m2);
03922 }
03923 
03924 constant * evaluate::ifthenelse_v_v (constant * args) {
03925   _ARB0 (cond);
03926   int t1 = _ARG(1)->getType ();
03927   int t2 = _ARG(2)->getType ();
03928   qucs::vector v1, v2;
03929   switch (t1) {
03930   case TAG_DOUBLE:
03931     v1 = qucs::vector (1); v1 (0) = D(_ARES(1)); break;
03932   case TAG_COMPLEX:
03933     v1 = qucs::vector (1); v1 (0) = *C(_ARES(1)); break;
03934   case TAG_BOOLEAN:
03935     v1 = qucs::vector (1); v1 (0) = B(_ARES(1)) ? 1.0 : 0.0; break;
03936   case TAG_VECTOR:
03937     v1 = *V(_ARES(1)); break;
03938   }
03939   switch (t2) {
03940   case TAG_DOUBLE:
03941     v2 = qucs::vector (1); v2 (0) = D(_ARES(2)); break;
03942   case TAG_COMPLEX:
03943     v2 = qucs::vector (1); v2 (0) = *C(_ARES(2)); break;
03944   case TAG_BOOLEAN:
03945     v2 = qucs::vector (1); v2 (0) = B(_ARES(2)) ? 1.0 : 0.0; break;
03946   case TAG_VECTOR:
03947     v2 = *V(_ARES(2)); break;
03948   }
03949   _DEFV ();
03950   _RETV (cond ? v1 : v2);
03951 }
03952 
03953 constant * evaluate::ifthenelse_v_v_v (constant * args) {
03954   _ARV0 (cond);
03955   int t1 = _ARG(1)->getType ();
03956   int t2 = _ARG(2)->getType ();
03957   qucs::vector v1, v2;
03958   switch (t1) {
03959   case TAG_DOUBLE:
03960     v1 = qucs::vector (1); v1 (0) = D(_ARES(1)); break;
03961   case TAG_COMPLEX:
03962     v1 = qucs::vector (1); v1 (0) = *C(_ARES(1)); break;
03963   case TAG_BOOLEAN:
03964     v1 = qucs::vector (1); v1 (0) = B(_ARES(1)) ? 1.0 : 0.0; break;
03965   case TAG_VECTOR:
03966     v1 = *V(_ARES(1)); break;
03967   }
03968   switch (t2) {
03969   case TAG_DOUBLE:
03970     v2 = qucs::vector (1); v2 (0) = D(_ARES(2)); break;
03971   case TAG_COMPLEX:
03972     v2 = qucs::vector (1); v2 (0) = *C(_ARES(2)); break;
03973   case TAG_BOOLEAN:
03974     v2 = qucs::vector (1); v2 (0) = B(_ARES(2)) ? 1.0 : 0.0; break;
03975   case TAG_VECTOR:
03976     v2 = *V(_ARES(2)); break;
03977   }
03978   _DEFV ();
03979   int i, a, b;
03980   qucs::vector * v = new qucs::vector ();
03981   for (a = b = i = 0; i < cond->getSize (); i++) {
03982     v->add (cond->get (i) != 0.0 ? v1 (a) : v2 (b));
03983     a++;
03984     b++;
03985     if (a >= v1.getSize ()) a = 0;
03986     if (b >= v2.getSize ()) b = 0;
03987   }
03988   res->v = v;
03989   return res;
03990 }
03991 
03992 // ************************** less *************************
03993 constant * evaluate::less_d_d (constant * args) {
03994   _ARD0 (d0);
03995   _ARD1 (d1);
03996   _DEFB ();
03997   _RETB (d0 < d1);
03998 }
03999 
04000 constant * evaluate::less_d_c (constant * args) {
04001   _ARD0 (d0);
04002   _ARC1 (c1);
04003   _DEFB ();
04004   _RETB (d0 < *c1);
04005 }
04006 
04007 constant * evaluate::less_d_v (constant * args) {
04008   _ARD0 (d0);
04009   _ARV1 (v1);
04010   _DEFV ();
04011   qucs::vector * v = new qucs::vector ();
04012   for (int i = 0; i < v1->getSize (); i++) {
04013     v->add (d0 < v1->get (i) ? 1.0 : 0.0);
04014   }
04015   res->v = v;
04016   return res;
04017 }
04018 
04019 constant * evaluate::less_c_d (constant * args) {
04020   _ARC0 (c0);
04021   _ARD1 (d1);
04022   _DEFB ();
04023   _RETB (*c0 < d1);
04024 }
04025 
04026 constant * evaluate::less_c_c (constant * args) {
04027   _ARC0 (c0);
04028   _ARC1 (c1);
04029   _DEFB ();
04030   _RETB (*c0 < *c1);
04031 }
04032 
04033 constant * evaluate::less_c_v (constant * args) {
04034   _ARC0 (c0);
04035   _ARV1 (v1);
04036   _DEFV ();
04037   qucs::vector * v = new qucs::vector ();
04038   for (int i = 0; i < v1->getSize (); i++) {
04039     v->add (*c0 < v1->get (i) ? 1.0 : 0.0);
04040   }
04041   res->v = v;
04042   return res;
04043 }
04044 
04045 constant * evaluate::less_v_d (constant * args) {
04046   _ARV0 (v0);
04047   _ARD1 (d1);
04048   _DEFV ();
04049   qucs::vector * v = new qucs::vector ();
04050   for (int i = 0; i < v0->getSize (); i++) {
04051     v->add (real (v0->get (i)) < d1 ? 1.0 : 0.0);
04052   }
04053   res->v = v;
04054   return res;
04055 }
04056 
04057 constant * evaluate::less_v_c (constant * args) {
04058   _ARV0 (v0);
04059   _ARC1 (c1);
04060   _DEFV ();
04061   qucs::vector * v = new qucs::vector ();
04062   for (int i = 0; i < v0->getSize (); i++) {
04063     v->add (v0->get (i) < *c1 ? 1.0 : 0.0);
04064   }
04065   res->v = v;
04066   return res;
04067 }
04068 
04069 constant * evaluate::less_v_v (constant * args) {
04070   _ARV0 (v0);
04071   _ARV1 (v1);
04072   _DEFV ();
04073   qucs::vector * v = new qucs::vector ();
04074   for (int i = 0; i < v0->getSize (); i++) {
04075     v->add (v0->get (i) < v1->get (i) ? 1.0 : 0.0);
04076   }
04077   res->v = v;
04078   return res;
04079 }
04080 
04081 // ************************* greater ***********************
04082 constant * evaluate::greater_d_d (constant * args) {
04083   _ARD0 (d0);
04084   _ARD1 (d1);
04085   _DEFB ();
04086   _RETB (d0 > d1);
04087 }
04088 
04089 constant * evaluate::greater_d_c (constant * args) {
04090   _ARD0 (d0);
04091   _ARC1 (c1);
04092   _DEFB ();
04093   _RETB (d0 > *c1);
04094 }
04095 
04096 constant * evaluate::greater_d_v (constant * args) {
04097   _ARD0 (d0);
04098   _ARV1 (v1);
04099   _DEFV ();
04100   qucs::vector * v = new qucs::vector ();
04101   for (int i = 0; i < v1->getSize (); i++) {
04102     v->add (d0 > real (v1->get (i)) ? 1.0 : 0.0);
04103   }
04104   res->v = v;
04105   return res;
04106 }
04107 
04108 constant * evaluate::greater_c_d (constant * args) {
04109   _ARC0 (c0);
04110   _ARD1 (d1);
04111   _DEFB ();
04112   _RETB (*c0 > d1);
04113 }
04114 
04115 constant * evaluate::greater_c_c (constant * args) {
04116   _ARC0 (c0);
04117   _ARC1 (c1);
04118   _DEFB ();
04119   _RETB (*c0 > *c1);
04120 }
04121 
04122 constant * evaluate::greater_c_v (constant * args) {
04123   _ARC0 (c0);
04124   _ARV1 (v1);
04125   _DEFV ();
04126   qucs::vector * v = new qucs::vector ();
04127   for (int i = 0; i < v1->getSize (); i++) {
04128     v->add (*c0 > v1->get (i) ? 1.0 : 0.0);
04129   }
04130   res->v = v;
04131   return res;
04132 }
04133 
04134 constant * evaluate::greater_v_d (constant * args) {
04135   _ARV0 (v0);
04136   _ARD1 (d1);
04137   _DEFV ();
04138   qucs::vector * v = new qucs::vector ();
04139   for (int i = 0; i < v0->getSize (); i++) {
04140     v->add (real (v0->get (i)) > d1 ? 1.0 : 0.0);
04141   }
04142   res->v = v;
04143   return res;
04144 }
04145 
04146 constant * evaluate::greater_v_c (constant * args) {
04147   _ARV0 (v0);
04148   _ARC1 (c1);
04149   _DEFV ();
04150   qucs::vector * v = new qucs::vector ();
04151   for (int i = 0; i < v0->getSize (); i++) {
04152     v->add (v0->get (i) > *c1 ? 1.0 : 0.0);
04153   }
04154   res->v = v;
04155   return res;
04156 }
04157 
04158 constant * evaluate::greater_v_v (constant * args) {
04159   _ARV0 (v0);
04160   _ARV1 (v1);
04161   _DEFV ();
04162   qucs::vector * v = new qucs::vector ();
04163   for (int i = 0; i < v0->getSize (); i++) {
04164     v->add (v0->get (i) > v1->get (i) ? 1.0 : 0.0);
04165   }
04166   res->v = v;
04167   return res;
04168 }
04169 
04170 // ********************** less or equal ********************
04171 constant * evaluate::lessorequal_d_d (constant * args) {
04172   _ARD0 (d0);
04173   _ARD1 (d1);
04174   _DEFB ();
04175   _RETB (d0 <= d1);
04176 }
04177 
04178 constant * evaluate::lessorequal_d_c (constant * args) {
04179   _ARD0 (d0);
04180   _ARC1 (c1);
04181   _DEFB ();
04182   _RETB (d0 <= *c1);
04183 }
04184 
04185 constant * evaluate::lessorequal_d_v (constant * args) {
04186   _ARD0 (d0);
04187   _ARV1 (v1);
04188   _DEFV ();
04189   qucs::vector * v = new qucs::vector ();
04190   for (int i = 0; i < v1->getSize (); i++) {
04191     v->add (d0 <= real (v1->get (i)) ? 1.0 : 0.0);
04192   }
04193   res->v = v;
04194   return res;
04195 }
04196 
04197 constant * evaluate::lessorequal_c_d (constant * args) {
04198   _ARC0 (c0);
04199   _ARD1 (d1);
04200   _DEFB ();
04201   _RETB (*c0 <= d1);
04202 }
04203 
04204 constant * evaluate::lessorequal_c_c (constant * args) {
04205   _ARC0 (c0);
04206   _ARC1 (c1);
04207   _DEFB ();
04208   _RETB (*c0 <= *c1);
04209 }
04210 
04211 constant * evaluate::lessorequal_c_v (constant * args) {
04212   _ARC0 (c0);
04213   _ARV1 (v1);
04214   _DEFV ();
04215   qucs::vector * v = new qucs::vector ();
04216   for (int i = 0; i < v1->getSize (); i++) {
04217     v->add (*c0 <= v1->get (i) ? 1.0 : 0.0);
04218   }
04219   res->v = v;
04220   return res;
04221 }
04222 
04223 constant * evaluate::lessorequal_v_d (constant * args) {
04224   _ARV0 (v0);
04225   _ARD1 (d1);
04226   _DEFV ();
04227   qucs::vector * v = new qucs::vector ();
04228   for (int i = 0; i < v0->getSize (); i++) {
04229     v->add (real (v0->get (i)) <= d1 ? 1.0 : 0.0);
04230   }
04231   res->v = v;
04232   return res;
04233 }
04234 
04235 constant * evaluate::lessorequal_v_c (constant * args) {
04236   _ARV0 (v0);
04237   _ARC1 (c1);
04238   _DEFV ();
04239   qucs::vector * v = new qucs::vector ();
04240   for (int i = 0; i < v0->getSize (); i++) {
04241     v->add (v0->get (i) <= *c1 ? 1.0 : 0.0);
04242   }
04243   res->v = v;
04244   return res;
04245 }
04246 
04247 constant * evaluate::lessorequal_v_v (constant * args) {
04248   _ARV0 (v0);
04249   _ARV1 (v1);
04250   _DEFV ();
04251   qucs::vector * v = new qucs::vector ();
04252   for (int i = 0; i < v0->getSize (); i++) {
04253     v->add (v0->get (i) <= v1->get (i) ? 1.0 : 0.0);
04254   }
04255   res->v = v;
04256   return res;
04257 }
04258 
04259 // ********************* greater or equal ******************
04260 constant * evaluate::greaterorequal_d_d (constant * args) {
04261   _ARD0 (d0);
04262   _ARD1 (d1);
04263   _DEFB ();
04264   _RETB (d0 >= d1);
04265 }
04266 
04267 constant * evaluate::greaterorequal_d_c (constant * args) {
04268   _ARD0 (d0);
04269   _ARC1 (c1);
04270   _DEFB ();
04271   _RETB (d0 >= *c1);
04272 }
04273 
04274 constant * evaluate::greaterorequal_d_v (constant * args) {
04275   _ARD0 (d0);
04276   _ARV1 (v1);
04277   _DEFV ();
04278   qucs::vector * v = new qucs::vector ();
04279   for (int i = 0; i < v1->getSize (); i++) {
04280     v->add (d0 >= real (v1->get (i)) ? 1.0 : 0.0);
04281   }
04282   res->v = v;
04283   return res;
04284 }
04285 
04286 constant * evaluate::greaterorequal_c_d (constant * args) {
04287   _ARC0 (c0);
04288   _ARD1 (d1);
04289   _DEFB ();
04290   _RETB (*c0 >= d1);
04291 }
04292 
04293 constant * evaluate::greaterorequal_c_c (constant * args) {
04294   _ARC0 (c0);
04295   _ARC1 (c1);
04296   _DEFB ();
04297   _RETB (*c0 >= *c1);
04298 }
04299 
04300 constant * evaluate::greaterorequal_c_v (constant * args) {
04301   _ARC0 (c0);
04302   _ARV1 (v1);
04303   _DEFV ();
04304   qucs::vector * v = new qucs::vector ();
04305   for (int i = 0; i < v1->getSize (); i++) {
04306     v->add (*c0 >= v1->get (i) ? 1.0 : 0.0);
04307   }
04308   res->v = v;
04309   return res;
04310 }
04311 
04312 constant * evaluate::greaterorequal_v_d (constant * args) {
04313   _ARV0 (v0);
04314   _ARD1 (d1);
04315   _DEFV ();
04316   qucs::vector * v = new qucs::vector ();
04317   for (int i = 0; i < v0->getSize (); i++) {
04318     v->add (real (v0->get (i)) >= d1 ? 1.0 : 0.0);
04319   }
04320   res->v = v;
04321   return res;
04322 }
04323 
04324 constant * evaluate::greaterorequal_v_c (constant * args) {
04325   _ARV0 (v0);
04326   _ARC1 (c1);
04327   _DEFV ();
04328   qucs::vector * v = new qucs::vector ();
04329   for (int i = 0; i < v0->getSize (); i++) {
04330     v->add (v0->get (i) >= *c1 ? 1.0 : 0.0);
04331   }
04332   res->v = v;
04333   return res;
04334 }
04335 
04336 constant * evaluate::greaterorequal_v_v (constant * args) {
04337   _ARV0 (v0);
04338   _ARV1 (v1);
04339   _DEFV ();
04340   qucs::vector * v = new qucs::vector ();
04341   for (int i = 0; i < v0->getSize (); i++) {
04342     v->add (v0->get (i) >= v1->get (i) ? 1.0 : 0.0);
04343   }
04344   res->v = v;
04345   return res;
04346 }
04347 
04348 // ************************** equal ************************
04349 constant * evaluate::equal_d_d (constant * args) {
04350   _ARD0 (d0);
04351   _ARD1 (d1);
04352   _DEFB ();
04353   _RETB (d0 == d1);
04354 }
04355 
04356 constant * evaluate::equal_d_c (constant * args) {
04357   _ARD0 (d0);
04358   _ARC1 (c1);
04359   _DEFB ();
04360   _RETB (d0 == *c1);
04361 }
04362 
04363 constant * evaluate::equal_d_v (constant * args) {
04364   _ARD0 (d0);
04365   _ARV1 (v1);
04366   _DEFV ();
04367   qucs::vector * v = new qucs::vector ();
04368   for (int i = 0; i < v1->getSize (); i++) {
04369     v->add (d0 == real (v1->get (i)) ? 1.0 : 0.0);
04370   }
04371   res->v = v;
04372   return res;
04373 }
04374 
04375 constant * evaluate::equal_c_d (constant * args) {
04376   _ARC0 (c0);
04377   _ARD1 (d1);
04378   _DEFB ();
04379   _RETB (*c0 == d1);
04380 }
04381 
04382 constant * evaluate::equal_c_c (constant * args) {
04383   _ARC0 (c0);
04384   _ARC1 (c1);
04385   _DEFB ();
04386   _RETB (*c0 == *c1);
04387 }
04388 
04389 constant * evaluate::equal_c_v (constant * args) {
04390   _ARC0 (c0);
04391   _ARV1 (v1);
04392   _DEFV ();
04393   qucs::vector * v = new qucs::vector ();
04394   for (int i = 0; i < v1->getSize (); i++) {
04395     v->add (*c0 == v1->get (i) ? 1.0 : 0.0);
04396   }
04397   res->v = v;
04398   return res;
04399 }
04400 
04401 constant * evaluate::equal_v_d (constant * args) {
04402   _ARV0 (v0);
04403   _ARD1 (d1);
04404   _DEFV ();
04405   qucs::vector * v = new qucs::vector ();
04406   for (int i = 0; i < v0->getSize (); i++) {
04407     v->add (real (v0->get (i)) == d1 ? 1.0 : 0.0);
04408   }
04409   res->v = v;
04410   return res;
04411 }
04412 
04413 constant * evaluate::equal_v_c (constant * args) {
04414   _ARV0 (v0);
04415   _ARC1 (c1);
04416   _DEFV ();
04417   qucs::vector * v = new qucs::vector ();
04418   for (int i = 0; i < v0->getSize (); i++) {
04419     v->add (v0->get (i) == *c1 ? 1.0 : 0.0);
04420   }
04421   res->v = v;
04422   return res;
04423 }
04424 
04425 constant * evaluate::equal_v_v (constant * args) {
04426   _ARV0 (v0);
04427   _ARV1 (v1);
04428   _DEFV ();
04429   qucs::vector * v = new qucs::vector ();
04430   for (int i = 0; i < v0->getSize (); i++) {
04431     v->add (v0->get (i) == v1->get (i) ? 1.0 : 0.0);
04432   }
04433   res->v = v;
04434   return res;
04435 }
04436 
04437 constant * evaluate::equal_b_b (constant * args) {
04438   _ARB0 (b0);
04439   _ARB1 (b1);
04440   _DEFB ();
04441   _RETB (b0 == b1);
04442 }
04443 
04444 // ************************ not equal **********************
04445 constant * evaluate::notequal_d_d (constant * args) {
04446   _ARD0 (d0);
04447   _ARD1 (d1);
04448   _DEFB ();
04449   _RETB (d0 != d1);
04450 }
04451 
04452 constant * evaluate::notequal_d_c (constant * args) {
04453   _ARD0 (d0);
04454   _ARC1 (c1);
04455   _DEFB ();
04456   _RETB (d0 != *c1);
04457 }
04458 
04459 constant * evaluate::notequal_d_v (constant * args) {
04460   _ARD0 (d0);
04461   _ARV1 (v1);
04462   _DEFV ();
04463   qucs::vector * v = new qucs::vector ();
04464   for (int i = 0; i < v1->getSize (); i++) {
04465     v->add (d0 != real (v1->get (i)) ? 1.0 : 0.0);
04466   }
04467   res->v = v;
04468   return res;
04469 }
04470 
04471 constant * evaluate::notequal_c_d (constant * args) {
04472   _ARC0 (c0);
04473   _ARD1 (d1);
04474   _DEFB ();
04475   _RETB (*c0 != d1);
04476 }
04477 
04478 constant * evaluate::notequal_c_c (constant * args) {
04479   _ARC0 (c0);
04480   _ARC1 (c1);
04481   _DEFB ();
04482   _RETB (*c0 != *c1);
04483 }
04484 
04485 constant * evaluate::notequal_c_v (constant * args) {
04486   _ARC0 (c0);
04487   _ARV1 (v1);
04488   _DEFV ();
04489   qucs::vector * v = new qucs::vector ();
04490   for (int i = 0; i < v1->getSize (); i++) {
04491     v->add (*c0 != v1->get (i) ? 1.0 : 0.0);
04492   }
04493   res->v = v;
04494   return res;
04495 }
04496 
04497 constant * evaluate::notequal_v_d (constant * args) {
04498   _ARV0 (v0);
04499   _ARD1 (d1);
04500   _DEFV ();
04501   qucs::vector * v = new qucs::vector ();
04502   for (int i = 0; i < v0->getSize (); i++) {
04503     v->add (real (v0->get (i)) != d1 ? 1.0 : 0.0);
04504   }
04505   res->v = v;
04506   return res;
04507 }
04508 
04509 constant * evaluate::notequal_v_c (constant * args) {
04510   _ARV0 (v0);
04511   _ARC1 (c1);
04512   _DEFV ();
04513   qucs::vector * v = new qucs::vector ();
04514   for (int i = 0; i < v0->getSize (); i++) {
04515     v->add (v0->get (i) != *c1 ? 1.0 : 0.0);
04516   }
04517   res->v = v;
04518   return res;
04519 }
04520 
04521 constant * evaluate::notequal_v_v (constant * args) {
04522   _ARV0 (v0);
04523   _ARV1 (v1);
04524   _DEFV ();
04525   qucs::vector * v = new qucs::vector ();
04526   for (int i = 0; i < v0->getSize (); i++) {
04527     v->add (v0->get (i) != v1->get (i) ? 1.0 : 0.0);
04528   }
04529   res->v = v;
04530   return res;
04531 }
04532 
04533 constant * evaluate::notequal_b_b (constant * args) {
04534   _ARB0 (b0);
04535   _ARB1 (b1);
04536   _DEFB ();
04537   _RETB (b0 != b1);
04538 }
04539 
04540 // *************************** not *************************
04541 constant * evaluate::not_b (constant * args) {
04542   _ARB0 (b0);
04543   _DEFB ();
04544   _RETB (!b0);
04545 }
04546 
04547 // *************************** or **************************
04548 constant * evaluate::or_b_b (constant * args) {
04549   _ARB0 (b0);
04550   _ARB1 (b1);
04551   _DEFB ();
04552   _RETB (b0 || b1);
04553 }
04554 
04555 // ************************** and **************************
04556 constant * evaluate::and_b_b (constant * args) {
04557   _ARB0 (b0);
04558   _ARB1 (b1);
04559   _DEFB ();
04560   _RETB (b0 && b1);
04561 }
04562 
04563 // ******************* random numbers **********************
04564 constant * evaluate::rand (constant *) {
04565   _DEFD ();
04566   _RETD (((nr_double_t) ::rand ()) / (nr_double_t) RAND_MAX);
04567 }
04568 
04569 constant * evaluate::srand_d (constant * args) {
04570   static int done = 0;
04571   _ARD0 (d0);
04572   _DEFD ();
04573   if (!done) {
04574     unsigned int i0 = (unsigned int) d0;
04575     ::srand (i0);
04576     done = 1;
04577     _RETD (1.0);
04578   } else {
04579     _RETD (0.0);
04580   }
04581 }
04582 
04583 
04584 // ******************* assert test *************************
04585 constant * evaluate::assert_b(constant *args)
04586 {
04587     _ARB0(b0);
04588     if(!b0) {
04589         THROW_MATH_EXCEPTION ("assert failled");
04590         abort();
04591      }
04592      _DEFB ();
04593     _RETB(true);
04594 }
04595 
04596 
04597 constant * evaluate::assert_d(constant *args)
04598 {
04599     _ARD0(d0);
04600     if(d0 == 0.0) {
04601         THROW_MATH_EXCEPTION ("assert failled");
04602         abort();
04603     }
04604      _DEFB ();
04605     _RETB(true);
04606 }
04607 
04608 
04609 constant * evaluate::assert_v (constant * args) {
04610   _ARV0 (v0);
04611   for (int i = 0; i < v0->getSize (); i++) {
04612     if( v0->get(i) == 0.0 ) {
04613         THROW_MATH_EXCEPTION ("assert failled");
04614         abort();
04615     }
04616   }
04617   _DEFB ();
04618   _RETB(true);
04619 }
04620 
04621 
04622 constant * evaluate::bugon_b(constant *args)
04623 {
04624     _ARB0(b0);
04625     if(b0) {
04626         THROW_MATH_EXCEPTION ("bugon failled");
04627         abort();
04628      }
04629      _DEFB ();
04630     _RETB(true);
04631 }
04632 
04633 
04634 constant * evaluate::bugon_d(constant *args)
04635 {
04636     _ARD0(d0);
04637     if(d0 != 0.0) {
04638         THROW_MATH_EXCEPTION ("bugon failled");
04639         abort();
04640      }
04641      _DEFB ();
04642     _RETB(true);
04643 }
04644 
04645 
04646 constant * evaluate::bugon_v (constant * args) {
04647   _ARV0 (v0);
04648   for (int i = 0; i < v0->getSize (); i++) {
04649     if( v0->get(i) != 0.0 ) {
04650         THROW_MATH_EXCEPTION ("bugon failled");
04651         abort();
04652     }
04653   }
04654   _DEFB ();
04655   _RETB(true);
04656 }
04657 
04658 
04659 // ******************* immediate vectors *******************
04660 constant * evaluate::vector_x (constant * args) {
04661   _DEFV ();
04662   qucs::vector * v = new qucs::vector ();
04663   for (node * arg = args; arg != NULL; arg = arg->getNext ()) {
04664     constant * c = arg->getResult ();
04665     switch (arg->getType ()) {
04666     case TAG_COMPLEX:
04667       v->add (*(c->c)); break;
04668     case TAG_DOUBLE:
04669       v->add (c->d); break;
04670     case TAG_BOOLEAN:
04671       v->add (c->b ? 1.0 : 0.0); break;
04672     case TAG_VECTOR:
04673       v->add (c->v); break;
04674     default:
04675       v->add (0.0); break;
04676     }
04677   }
04678   res->v = v;
04679   return res;
04680 }
04681 
04682 // ******************* immediate matrices ******************
04683 constant * evaluate::matrix_x (constant * args) {
04684   _DEFM ();
04685   /* create temporary list of vectors */
04686   qucs::vector * va = NULL;
04687   qucs::vector * v = new qucs::vector ();
04688   va = v;
04689   for (node * arg = args; arg != NULL; arg = arg->getNext ()) {
04690     constant * c = arg->getResult ();
04691     switch (arg->getType ()) {
04692     case TAG_COMPLEX:
04693       v->add (*(c->c)); break;
04694     case TAG_DOUBLE:
04695       v->add (c->d); break;
04696     case TAG_BOOLEAN:
04697       v->add (c->b ? 1.0 : 0.0); break;
04698     case TAG_VECTOR:
04699       v->add (c->v); break;
04700     case TAG_CHAR:
04701       if (c->chr == ';') {
04702         /* append new vector, i.e. a new matrix row */
04703         qucs::vector * vn = new qucs::vector ();
04704         v->setNext (vn);
04705         v = vn;
04706       }
04707       else v->add (0.0);
04708       break;
04709     default:
04710       v->add (0.0); break;
04711     }
04712   }
04713   /* determine matrix dimensions and create it */
04714   int r, c;
04715   for (r = 0, c = 0, v = va; v != NULL; v = (::vector *) v->getNext (), r++) {
04716     if (c < v->getSize ()) c = v->getSize ();
04717   }
04718   matrix * m = new matrix (r, c);
04719   /* fill in matrix entries and delete temporary vector list */
04720   qucs::vector * vn = NULL;
04721   for (r = 0, v = va; v != NULL; v = vn, r++) {
04722     for (c = 0; c < v->getSize (); c++) {
04723       m->set (r, c, v->get (c));
04724     }
04725     vn = (::vector *) v->getNext ();
04726     delete v;
04727   }
04728   /* return result matrix */
04729   res->m = m;
04730   return res;
04731 }
04732 
04733 // ********************** EMI receiver *********************
04734 constant * evaluate::receiver_v_v (constant * args) {
04735   _ARV0 (da);
04736   _ARV1 (dt);
04737   _DEFV ();
04738 
04739   // run receiver functionality
04740   qucs::vector * ed;
04741   if (_ARG(2)) {
04742     _ARI2 (len);
04743     ed = emi::receiver (da, dt, len);
04744   }
04745   else {
04746     ed = emi::receiver (da, dt);
04747   }
04748 
04749   // create two vectors for spectrum and frequency
04750   int rlen = ed->getSize ();
04751   qucs::vector * rvec = new qucs::vector (rlen);
04752   qucs::vector * rfeq = new qucs::vector (rlen);
04753   for (int i = 0; i < rlen; i++) {
04754     (*rvec)(i) = real (ed->get (i));
04755     (*rfeq)(i) = imag (ed->get (i));
04756   }
04757   delete ed;
04758 
04759   // put results back into equation solver
04760   node * gen = SOLVEE(0)->addGeneratedEquation (rfeq, "Frequency");
04761   res->addPrepDependencies (A(gen)->result);
04762   res->dropdeps = 1;
04763   res->v = rvec;
04764   return res;
04765 }
04766 
04767 // Include the application array.
04768 #include "applications.h"
04769