summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ex4-3.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/ex4-3.c b/ex4-3.c
index 47689f4..7de79fb 100644
--- a/ex4-3.c
+++ b/ex4-3.c
@@ -10,6 +10,11 @@ int getop(char[]);
void push(double);
double pop(void);
+// Naïve implementation of remainder operation
+double frem(double f1, double f2) {
+ return f1 - (f2 * (int)(f1 / f2));
+}
+
/**
* Reverse polish notation calculator
*/
@@ -39,6 +44,13 @@ int main(void) {
else
printf("error: zero division attempted!\n");
break;
+ case '%':
+ op2 = pop();
+ if (op2 != 0.0)
+ push(frem(pop(), op2));
+ else
+ printf("error: zero division attempted!\n");
+ break;
case '\n':
printf("\t%.8g\n", pop());
break;