microsoft / calculator

Windows Calculator: A simple yet powerful calculator that ships with Windows
MIT License
29.2k stars 5.27k forks source link

Support Reverse Polish Notation (RPN) #128

Open tigerhawkvok opened 5 years ago

tigerhawkvok commented 5 years ago

Problem Statement

Reverse Polish Notation / RPN / Postfix mode is an alternate calculator entry mode that is very powerful (leveraging a stack does this!) and should be simple enough to implement.

This behaviour can be seen in physical HP scientific calculators, or the calc mode in Emacs.

image

Evidence or User Insights

It's a simple addition with minimal overhead that would please some potential users that right now need to seek other solutions.

Goals

Users can toggle an RPN mode of entry Low-Fidelity Concept

Simple psuedocode:

#! python3

# Or a function list, or something to check if input is "function" or "input"
functionMap = { 
    "+": lambda x, y: x + y,
    # ....
    "mod": lambda x, y: x % y
}

stack = []
while True:
    userInput = getInput()
    # If it's not a function, add it to the stack
    if userInput not in functionMap.keys():
        stack.append(userInput)
    else:
        # Evaluate the last two items on the stack.
        # In real usage, the last stack item is often implicit, eg, 
        # 27 [enter] 3 / 
        # rather than
        # 27 [enter] 3 [enter] /
        b = stack.pop()
        a = stack.pop()
        stack.append(functionMap[userInput](a, b))
MicrosoftIssueBot commented 5 years ago

This is your friendly Microsoft Issue Bot. I've seen this issue come in and have gone to tell a human about it.

grochocki commented 5 years ago

Thanks for the feature suggestion! This is really well thought-out, and we really appreciate it. Let's keep this idea open for discussion so the community has the chance to provide feedback.

rbeesley commented 5 years ago

Shunting-yard algorithm? The first time I considered this, I thought it would make sense to reuse the history capability as a stack, and this would have the added benefit of being able to swap or move results around the stack by drag and drop. But the calculator engine is highly fixed how it works. I now think it might be easier and less disruptive to have a mode (like scientific) which would maintain its own stack and just use a shunting-yard to convert to Infix for the calculator engine. The equals key (=) would just become Enter, and you'd loose the need for the parenthesis. Postfix (RPN) to Infix is pretty straight forward and actually easier to implement than Infix to Postfix, but it'd also be handy to have an operation which converts expressions back and forth without evaluating until the Enter/Equals key is pressed.

(1+2)/3 could be written Infix and pressing the RPN key would transform it to 1 2 + 3 / for the user and swapping the mode at the same time. Pressing Enter/Equal at this time would evaluate. Where this would be unusual is initially being in RPN mode where normally the operator carries out an evaluation, so it would normally convert like 1 2 +333 /1, where the values in bold are what are added to the stack/output.

I've been waiting for this mode for 20 years.

AtomicMegaNerd commented 5 years ago

This is the one feature I wish that Windows calculator had. Once you get used to RPN it is really hard to go back. The calculator on macOS offers this option and every other device I use has some kind of RPN calculator setup on it. I really like the Fluent design interface on Windows calculator and this would really make me want to use this more if it offered this as an option!

dgua commented 5 years ago

Calculator is USELESS without RPN mode.

grochocki commented 5 years ago

We reviewed the pitch and would love to explore this idea further! I think this pitch is a great start, but there are still some open questions. Moving this into planning to iron out some of the details. Keep in mind that not all ideas that make it into the planning phase are guaranteed to make it to release.

A couple top-of-mind open questions:

I created calculator-specs/rpn to track progress. For more information on next steps, check out our spec workflow.

arigit commented 4 years ago

huge +1 on this request. This feature is overdue by some decades now. MacOS calculator has included RPN support for a very long time. Take a look at: https://support.apple.com/en-in/guide/calculator/welcome/mac for inspiration on a reasonably well done implementation.

michaelglasson commented 4 years ago

RPN is the best way I know to do nested calculations without the need for parentheses. I strongly support this proposal.

Artoriuz commented 3 years ago

Leaving this comment here as a form of appreciation. RPN mode would be amazing to have and a huge time saver for anyone used to using RPN calculators.

gustavoavellar commented 3 years ago

+1

bazzol commented 3 years ago

+1 this is really needed for many people!

div4d commented 3 years ago

@mcooley could you please send us an update on this one if you can? to me, RPN function could be implemented as per the Apple calculator default app on macs. on the "view" menu there is an option to enable the rpn logic and the magic is done. It is quite a useful option to implement from my point of view and there is no harm from all users that want to stick to the standard calculator. many thanks

akang6 commented 3 years ago

I would love this feature

sh-jeff commented 2 years ago

Going to +1 this. The easiest way to support this IMO would be to make it another mode. Perhaps this mode is a blend of the HP 12C and 15C? Another idea could be to bury it under options. This would also allow switching to prefix notation, but I don't know how it would interact with all of the modes.

Shamus03 commented 2 years ago

I'll just drop a plug here for an RPN calculator I made, designed to look and feel almost exactly the same as the Windows 10 calculator (when installed as a PWA):

https://ralc.shamus.dev

Source code is here: https://github.com/Shamus03/ralc

It also works great on mobile (I wanted a consistent calculator between mobile/desktop)

caelyx commented 2 years ago

+1

rbeesley commented 2 years ago

It also works great on mobile (I wanted a consistent calculator between mobile/desktop)

As a +1 for the work done on the Ralc calculator, I use it as a PWA on my mobile devices. I discovered an issue and it was quickly patched.

With respect to Windows Calculator, the only real value of Ralc is that it demonstrates effectively how the UI might work. To make this part of Windows Calculator, it would be important to leverage the existing calculator engine and extend the UI of the standard, scientific, and programming calculator modes. For the UI, changing the = key to an enter key would be a simple change.

eruschy commented 2 years ago

I would also love this feature. As long as it's absent I'm forced to use alternative apps, but I'd much rather use Windows Calculator.

mikenerone commented 1 year ago

Missing RPN/postfix is the reason I don't usually use Windows calculator.

idchoppers commented 1 year ago

This would be a great feature to add; You could make it an option in the settings menu that is easily changeable. Would love if this gets implemented!

davea1 commented 1 year ago

The single biggest missing feature IMO.

Thanks for keeping this request open for consideration.

Pigankle commented 1 year ago

We reviewed the pitch and would love to explore this idea further! I think this pitch is a great start, but there are still some open questions. Moving this into [planning](https://github.com/Microsoft/calculator/blob/master/docs/NewFeatureProcess.md#step-2-planning I created calculator-specs/rpn to track progress. For more information on next steps, check out our spec workflow.

I would like to rejuvenate the interest in adding this feature. Can you tell me if I am doing this right?

I created a fork of the calculator-specs repo, and copied the template into what I think is the right place:

https://github.com/Pigankle/calculator-specs/tree/master/active/RPN_Mode/

I think the next step is that I collaborate with people to get this spec sheet filled out in dazzling, utilitarian fashion then, when we think it is ready, we submit a pull request....is that correct?

pedrohakial commented 11 months ago

Request for RPN Financial Calculator Feature

Overview

I would like to propose the addition of a financial calculator feature to Windows that uses Reverse Polish Notation (RPN) and includes the same operations as the HP 12C calculator.

Rationale

There are several compelling reasons to consider this feature:

  1. Efficiency: RPN can be more efficient than standard calculators as it reduces the number of keystrokes needed for calculations. In a fast-paced financial environment, every second counts.

  2. Consistency: The HP 12C has been a staple in the financial industry for decades. Adding a similar calculator to Windows would provide a consistent user experience for those transitioning between physical calculators and digital platforms.

  3. Familiarity and Training: Many financial professionals are already trained to use the HP 12C. This would significantly reduce the learning curve for a Windows-based RPN financial calculator. Moreover, many finance courses and certifications (like CFA, CFP, etc.) actually teach financial concepts using the HP 12C.

  4. Precision and Error Reduction: With RPN, operations are performed immediately after the second operand is entered. This reduces the chance for errors in complex calculations.

  5. Complex Calculations: The HP 12C is not just a calculator; it's a financial problem-solving tool. It has functions for calculating NPV, IRR, mortgage payments, bond prices, and more. Integrating these capabilities into the Windows calculator would be a significant upgrade.

  6. Market Demand: If a significant portion of finance professionals are using Windows, there may be substantial demand for an RPN calculator like the HP 12C. This feature could become a selling point for Windows.

In conclusion, adding support for a financial calculator that uses RPN and the same operations as the HP 12C would bring efficiency, familiarity, and powerful financial problem-solving tools to the Windows platform. This could cater to a significant sector of the Windows user base and could even attract new users.

Shorono commented 9 months ago

+1 Here in Norway at least, the RPN calc is the default for quite a few engineering professions and basically all the economists I know, as one of the HP RPN calculators is the one you are being taught for in one of the biggest schools of economics here.

davea1 commented 9 months ago

When I was working toward my EE degree here in the US back in the late 80s and early 90s, all of my physics and engineering professors exclusively used HP RPN calculators.

I made the switch to my first HP RPN calculator (HP 15C) upon starting university as a new freshman. After that, I knew there was no going back!!!

IngmarPaetzold commented 5 months ago

I learned using RPN at university, and once you get it, you get a much better feeling of equations' inner structures. Because you solve the most coherent terms first from the inside out, not dully from left to right. Currently, I use a phone app that can do this. And I cannot understand that the MS calculator, which tries to shine as a "flag ship" with lots of glitter, still does not provide this mode that many serious engineers and scientists use for a reason.

llamahunter commented 4 months ago

Coming from MacOS to windows has been a horrible experience, only made worse by the fact that the Windows calculator does not support RPN.