dc

Tiny reverse polish desk calculator
Log | Files | Refs | README | LICENSE

commit 604739e9e70cdbc9876556ad3e2617a23b687fe5
parent 5800671a4820e24aebfbc1103b9bbe22a530e1df
Author: Byron Torres <b@torresjrjr.com>
Date:   Wed, 24 Nov 2021 16:50:02 +0000

fix operand order

Diffstat:
Mdc.ha | 14+++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/dc.ha b/dc.ha @@ -89,10 +89,10 @@ export fn main() void = { case 'd' => push(peek()); case 'r' => - const a = pop(); const b = pop(); - push(a); + const a = pop(); push(b); + push(a); case 'R' => let n = pop(): int; if (n > 1) { @@ -115,40 +115,40 @@ export fn main() void = { fmt::errorln("dc: stack has too few elements")?; continue; }; - const a = pop(); const b = pop(); + const a = pop(); push(a + b); case '-' => if (len(S) < 2) { fmt::errorln("dc: stack has too few elements")?; continue; }; - const a = pop(); const b = pop(); + const a = pop(); push(a - b); case '*' => if (len(S) < 2) { fmt::errorln("dc: stack has too few elements")?; continue; }; - const a = pop(); const b = pop(); + const a = pop(); push(a * b); case '/' => if (len(S) < 2) { fmt::errorln("dc: stack has too few elements")?; continue; }; - const a = pop(); const b = pop(); + const a = pop(); push(a / b); case '%' => if (len(S) < 2) { fmt::errorln("dc: stack has too few elements")?; continue; }; - const a = pop(); const b = pop(); + const a = pop(); push(math::modf64(a, b)); case => fmt::errorfln("dc: unimplemented '{}'", r)?;