From 50534766e09667a9c23c1f167dca92f5d4fd0f27 Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Mon, 21 Nov 2022 20:39:02 +0000 Subject: Actually implement ex4-3 --- ex4-3.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ex4-3.c') 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; -- cgit v1.2.3-ZIG