39 return (*val[0] > 0) && (*val[1] > 0);
44 return (*val[0] > 0) || (*val[1] > 0);
49 return !(*val[0] > 0);
54 return *val[0] == *val[1];
59 return *val[0] != *val[1];
64 return *val[0] > *val[1];
69 return *val[0] >= *val[1];
74 return *val[0] < *val[1];
79 return *val[0] <= *val[1];
84 return *val[0] + *val[1];
89 return *val[0] - *val[1];
94 return *val[0] * *val[1];
99 return *val[0] / *val[1];
104 return pow(*val[0], *val[1]);
124 return sinh(*val[0]);
129 return cosh(*val[0]);
134 return tanh(*val[0]);
139 return atan(*val[0]);
144 return asin(*val[0]);
149 return acos(*val[0]);
154 return atan2(*val[0], *val[1]);
159 return sqrt(*val[0]);
169 return *val[0] = *val[1];
181 return fabs(*val[0]);
186 return log10(*val[0]);
206 return fmod(*val[0], *val[1]);
211 return round(*val[0]);
214 #define OPERATION_MUL 11 265 rpf->
next = malloc(
sizeof(
struct rpf_t));
287 for (; rpf; rpf = rpf->
next)
314 for (sp_op2 = *sp_op - 1; sp_op2 >= 0; sp_op2--)
316 struct rpf_t rpf2, *rpf2_tmp;
323 num_cnt = ((
struct operation_t *)op[sp_op2].value)->narg;
324 if (num_cnt > *sp_num)
326 for (sp_num2 = *sp_num - num_cnt; sp_num2 < *sp_num; sp_num2++)
328 switch (num[sp_num2].
type)
331 rpf2_tmp =
rpf_join(rpf2_tmp, num[sp_num2].value);
335 rpf2_tmp =
rpf_push(rpf2_tmp, &num[sp_num2]);
341 (*sp_num) -= num_cnt;
342 rpf2_tmp =
rpf_push(rpf2_tmp, &op[sp_op2]);
345 num[*sp_num].
rank = 0;
353 return num[*sp_num - 1].
value;
362 struct rpf_t rpf_start;
363 struct rpf_t *rpf_tmp;
370 for (; *expr; expr++)
380 for (; isspace(*expr); expr++)
382 for (end = expr; *end; end++)
391 if (rank2 || !(*end))
393 if (
formula(expr + 1, &rpf2, variable) == 0)
397 num[sp_num].
rank = 0;
399 num[sp_num].
value = rpf2;
407 else if (*expr ==
')')
412 else if (*expr ==
',')
419 else if (isspace(*expr))
426 if (strstr(expr, operation[i].op) == expr)
428 if (sp_op > 0 && op[sp_op - 1].rank == operation[i].rank)
432 if (
formula_output(num, &sp_num, op + sp_op - 1, &sp_op2, operation[i].rank) == NULL)
436 else if (sp_op > 0 && op[sp_op - 1].rank > operation[i].rank)
438 if (
formula_output(num, &sp_num, op, &sp_op, operation[i].rank) == NULL)
441 expr += strlen(operation[i].op);
442 for (; isspace(*expr); expr++)
445 if (sp_num == 0 && operation[i].func ==
math_sub)
448 num[sp_num].
rank = 0;
450 num[sp_num].
value = malloc(
sizeof(
double));
451 *((
double *)num[sp_num].
value) = -1;
466 num[sp_num].
rank = 0;
468 num[sp_num].
value = malloc(
sizeof(
double));
469 *((
double *)num[sp_num].
value) = -1;
493 op[sp_op].type = operation[i].
type;
494 op[sp_op].value = &operation[i];
497 if (operation[i].narg > 0)
505 for (end = expr; *end; end++)
514 if (rank2 || !(*end))
516 if (
formula(expr + 1, &rpf2, variable) == 0)
521 num[sp_num].
rank = 0;
523 num[sp_num].
value = rpf2;
532 op[sp_op].rank = operation[i].
rank;
533 op[sp_op].type = operation[i].
type;
534 op[sp_op].value = &operation[i];
548 char variable_name[256];
555 for (end = expr; *end; end++)
557 if (!(isalnum(*end) || *end ==
'_' || *end ==
'[' || *end ==
']'))
559 variable_name[i++] = *end;
561 variable_name[i] = 0;
563 for (i = 0; variable[i].
name; i++)
565 if (strcmp(variable[i].name, variable_name) == 0)
567 num[sp_num].
rank = 0;
574 if (!variable[i].name)
582 for (end = expr; *end; end++)
584 if (!(isdigit(*end) || (end == expr && *end ==
'-') || *end ==
'.'))
587 num[sp_num].
rank = 0;
589 num[sp_num].
value = malloc(
sizeof(
double));
590 *((
double *)num[sp_num].
value) = strtod(expr, NULL);
597 if (sp_num < 0 || sp_op != 0)
601 rpf_tmp = &rpf_start;
602 for (sp_num--; sp_num >= 0; sp_num--)
604 switch (num[sp_num].
type)
610 rpf_tmp =
rpf_push(rpf_tmp, &num[sp_num]);
614 *rpf = rpf_start.
next;
648 for (; rpf; rpf = rpf->
next)
654 stack[sp] = ((
double *)rpf->
value);
659 tmp = (op->
func)(&stack[sp - op->
narg]);
661 stack[sp] = &_stack[sp];
673 struct rpf_t *rpf_st[512];
676 struct rpf_t *rpf_new;
677 struct rpf_t rpf_new_st;
679 struct rpf_t *rpf = rpf_orig;
682 for (; rpf; rpf = rpf->
next)
691 rpf_st[sp] = malloc(
sizeof(
struct rpf_t));
692 *(rpf_st[sp]) = *rpf;
695 stack[sp] = malloc(
sizeof(
double));
696 *(stack[sp]) = *((
double *)rpf->
value);
697 rpf_st[sp]->
value = stack[sp];
709 for (i = 0; i < op->
narg; i++)
711 if (!fixed[sp - 1 - i])
716 tmp = (op->
func)(&stack[sp - op->
narg]);
717 for (i = 0; i < op->
narg; i++)
719 if (stack[sp - 1 - i])
720 free(stack[sp - 1 - i]);
721 free(rpf_st[sp - 1 - i]);
724 stack[sp] = malloc(
sizeof(
double));
728 rpf_st[sp] = malloc(
sizeof(
struct rpf_t));
730 rpf_st[sp]->
value = stack[sp];
735 rpf_st[sp] = malloc(
sizeof(
struct rpf_t));
736 *(rpf_st[sp]) = *rpf;
744 rpf_new = &rpf_new_st;
746 for (i = 0; i < sp; i++)
748 rpf_new->
next = rpf_st[i];
750 rpf_new = rpf_new->
next;
752 return rpf_new_st.
next;
757 for (; rpf; rpf = rpf->
next)
762 fprintf(stream,
"%f ", *(
double *)rpf->
value);
765 fprintf(stream,
"VARIABLE ");
double(* func)(double **)