// test: echo "1 + 2 *" | calc.exe | grep -q 'error'
// test: echo "* 1 - 2" | calc.exe | grep -q 'error'
// test: echo "2 + * 3" | calc.exe | grep -q 'error'
+// test: echo "2 + cos(3 *)" | calc.exe | grep -q 'error'
+// test: echo "2 + (foo)" | calc.exe | grep -q 'error'
+// test: echo "2 + cos (pi" | calc.exe | grep -q 'error'
+// test: echo "cos (1, 2)" | calc.exe | grep -q 'error'
// test: echo "sqrt 2" | calc.exe | grep -q 'error'
// test: echo "pow (2)" | calc.exe | grep -q 'error'
// test: echo "1.23456789" | calc.exe -p 3 | grep -q '1\.234'
// 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, 7)\nsto(9)\ndisp' | calc.exe | grep -q '0 1 0 0 7 0 0 0 7 0'
+// test: echo -e '1+1 == 2' | calc.exe | grep -q '=> 1'
+// test: echo -e '1-cos(3*pi/4) != 0.5^-2' | calc.exe | grep -q '=> 0'
+// test: echo -e '1 >= 2' | calc.exe | grep -q '=> 0'
+// test: echo -e '2 >= 2' | calc.exe | grep -q '=> 1'
+// test: echo -e '1 <= 2' | calc.exe | grep -q '=> 1'
+// test: echo -e '2 <= 2' | calc.exe | grep -q '=> 1'
+// test: echo -e '1 > 2' | calc.exe | grep -q '=> 0'
+// test: echo -e '2 > 2' | calc.exe | grep -q '=> 0'
+// test: echo -e '1 < 2' | calc.exe | grep -q '=> 1'
+// test: echo -e '2 < 2' | calc.exe | grep -q '=> 0'
+// test: echo -e '1 == 1\n1 != 1\n1 >= 1\n1 <= 1\n1 > 1\n1 < 1\nquit' | calc.exe -v 3 | grep -q bye
/* vim: set ts=4 sw=4 et: */
/* functions */
-#define NB_OPERATORS 6
+#define NB_OPERATORS 12
keyword_t operators[NB_OPERATORS] = {
{ "+\t", Add, 2, 1, 1},
{ "*", Mul, 2, 1, 2},
{ "/", Div, 2, 1, 2},
{ "%", Mod, 2, 1, 3},
- { "^", Pow, 2, 1, 4}
+ { "^", Pow, 2, 1, 4},
+ { "==", Equal, 2, 2, 6},
+ { "!=", Diff, 2, 2, 6},
+ { ">=", Ge, 2, 2, 6},
+ { "<=", Le, 2, 2, 6},
+ { ">", Gt, 2, 1, 6},
+ { "<", Lt, 2, 1, 6}
};
#define NB_FUNCTIONS 12
{ "log", Log, 1, 3, 5},
{ "sto", Store, 2, 3, 5},
{ "rcl", Recall, 1, 3, 5},
- { "disp", Disp, 0, 4, 5},
+ { "disp", Disp, 0, 4, 5},
{ "quit", Quit, 0, 4, 5},
{ "help", Help, 0, 4, 5}
};
case Ans: func = "Ans"; break;
case Pi: func = "Pi"; break;
case E: func = "E"; break;
+ case Equal: func = "Equal"; break;
+ case Diff: func = "Different"; break;
+ case Ge: func = "Greater or equal"; break;
+ case Le: func = "Lesser or equal"; break;
+ case Gt: func = "Greater"; break;
+ case Lt: func = "Lesser"; break;
}
fprintf (stdout, "Function: %s\n", func);
fprintf (stdout, "calc is a simple calculator\n\n");
fprintf (stdout, "supported operators:\n");
fprintf (stdout, " + - * / %% ^\n\n");
+ fprintf (stdout, "camparison operators:\n");
+ fprintf (stdout, " == != >= <= > <\n\n");
fprintf (stdout, "supported functions:\n");
fprintf (stdout, " pow sqrt cos sin atan log exp\n\n");
fprintf (stdout, "storage functions:\n");
case Mod:
case Pow:
case Store:
+ case Equal:
+ case Diff:
+ case Ge:
+ case Le:
+ case Gt:
+ case Lt:
if (root->ops[1]) {
op1 = evaluate_element (root->ops[1], nextmask);
} else if (root->func != Store) {
case Ans: return answer;
case Pi: return M_PI;
case E: return M_E;
+ case Equal: return op0 == op1;
+ case Diff: return op0 != op1;
+ case Ge: return op0 >= op1;
+ case Le: return op0 <= op1;
+ case Gt: return op0 > op1;
+ case Lt: return op0 < op1;
}
return 0;