This expression evaluator is very similar to the usual one. It can be defined as the default one with the command ch_expr (cf. 7.7.3, 11).
The mathematical functions that the complex expression evaluator knows are in the array Funcs_C[] (it is an array of structures FUNCTIONC). This array must be defined by the user. The total number of functions is _NBFONC_C, which must be set by the user. An array of functions is predefined in the library, it is called Func_interp_C, and the number of functions defined in Func_interp is contained in the integer _NBFONC0_C.
FUNCTIONC Funcs_interp_C[] =
{
/* name, funtion to call */
{ "Csin", 1, _I_dCsin_c }, /* 0 */
{ "Ccos", 1, _I_dCcos_c }, /* 1 */
{ "Ctan", 1, _I_dCtan_c }, /* 2 */
{ "Csinh", 1, _I_dCsinh_c }, /* 3 */
{ "Ccosh", 1, _I_dCcosh_c }, /* 4 */
{ "Ctanh", 1, _I_dCtanh_c }, /* 5 */
{ "Cexp", 1, _I_dCexp_c }, /* 6 */
{ "Clog", 1, _I_dClog_c }, /* 7 */
{ "Csqrt", 1, _I_xdCsqrt }, /* 8 */
{ "Cabs", 1, _I_CdCabs }, /* 9 */
{ 0 } /* 10 */
};
int _NBFONC0_C=10;
For instance if the program uses only the predefined array of functions, the main source file would look as follows :
......
FUNCTIONC *Funcs_C;
int main(int argc, char *argv[])
{
......
Funcs_C = Funcs_interp_C;
_NBFONC_C = _NBFONC0_C;
......
}
The structure FUNCTIONC is defined as follows :
typedef struct
{
char* name; /* Function name */
int args; /* Number of arguments to expect */
dcomplex (*func)(dcomplex *); /* Pointer to function */
} FUNCTIONC;
Its first member is the character string that will be used to call the function. The second member is the number of parameters of the function. It must be between 1 and the constant MAX_F_ARGS defined in interp.h (it is 10). The third member is the name of the function. It must be a function returning a double precision complex value, having only one argument : an array of double precision complex numbers. In the first term of the array Func_interp_C the function _I_dCsin_c looks like this
dcomplex
_I_dCsin_c(dcomplex *x)
{
return dCsin_c(*x);
}
(the function dCsin_c is defined in complex.c).