// test: echo -e '\n\n\n' | calc.exe -n
// test: echo -e '1.5\nsto (2)\n3 + rcl(2) * 4\nsto (5)' | calc.exe | grep -q 9
// test: echo -e '1\nsto (0)\nsto (11)\nrcl (0)\nrcl (11)' | calc.exe | grep -c invalid | xargs test 4 =
-// test: echo -e '1\nsto (2)\n3\nsto (5)\ndisp' | calc.exe | grep -q '0 1 0 0 3 0 0 0 0 0'
+// test: echo -e '1\nsto (2)\n3\nsto (5, 7)\nsto(9)\ndisp' | calc.exe | grep -q '0 1 0 0 7 0 0 0 7 0'
/* vim: set ts=4 sw=4 et: */
{ "atan", Atan, 1, 4, 5},
{ "exp", Exp, 1, 3, 5},
{ "log", Log, 1, 3, 5},
- { "sto", Store, 1, 3, 5},
+ { "sto", Store, 2, 3, 5},
{ "rcl", Recall, 1, 3, 5},
{ "disp", Disp, 0, 4, 5},
{ "quit", Quit, 0, 4, 5},
/* storage functions */
-double store (int index)
+double store (int index, double value)
{
if ((index > 0) && (index <= STORAGE_SIZE)) {
- storage[index - 1] = answer;
+ storage[index - 1] = value;
} else {
VERBOSE (WARNING, fprintf (stdout, "invalid index (%d) [1, %d]\n", index, STORAGE_SIZE));
}
- return answer;
+ return value;
}
double recall (int index)
case Div:
case Mod:
case Pow:
+ case Store:
if (root->ops[1]) {
op1 = evaluate_element (root->ops[1], nextmask);
- } else {
+ } else if (root->func != Store) {
VERBOSE (WARNING, fprintf (stdout, "error while evaluating (op[1])\n"));
return 0;
}
case Atan:
case Log:
case Exp:
- case Store:
case Recall:
if (root->ops[0]) {
op0 = evaluate_element (root->ops[0], 0);
case Atan: return atan (op0);
case Log: return log (op0);
case Exp: return exp (op0);
- case Store: return store ((int)op0);
+ case Store: return store ((int)op0, (op1) ? op1 : answer);
case Recall: return recall ((int)op0);
case Disp: display (); break;
case Quit: quit (); break;