microsoft / calculator

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

Develop a parser for arbitrary expressions in the calc engine #526

Open mcooley opened 5 years ago

mcooley commented 5 years ago

Problem Statement Currently, Calculator executes all operations in immediate mode--press an operator, get a new answer. For multiple scenarios, it would be useful for the user to enter an expression like "(5 + 2) * 3" and have Calculator parse and compute the result.

Evidence or User Insights Several proposed features could leverage this work:

Proposal Add code and tests to the calc engine to parse mathematical expressions as strings.

Goals

Non-Goals

Requested Assignment I'm happy to help with this, but would be great for someone else to implement.

ghost commented 5 years ago

This pitch looks like it has everything it needs for review. In the meantime, we'll keep this idea open for discussion so the community has the chance to provide feedback. Check out our New Feedback Process for more info on the user-centered process we follow for new feature development.

ghost commented 5 years ago

This pitch looks like it has everything it needs for review. In the meantime, we'll keep this idea open for discussion so the community has the chance to provide feedback. Check out our New Feedback Process for more info on the user-centered process we follow for new feature development.

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.

rudyhuyn commented 5 years ago

For information, I already built an expression parser to improve the PasteManager and managing a lot of operations not currently supported (ln, log, sqrt, etc...) and already covering all your needs (history edition, ink, edition in scientific):

https://github.com/microsoft/calculator/issues/344 (and proto-PR here: https://github.com/rudyhuyn/calculator/tree/AddExpressionParser)

Don't hesitate to take a look

leduyquang753 commented 4 years ago

If this will be implemented, I suggest making the mathematical operators customizable, as they are regional, cultural and personal preferences. For example, I would write "16 + 28 × 5 – 27 ÷ 3" as "16 + 78.5 – 27:3".

ghost commented 4 years ago

We reviewed the pitch and would love to explore this idea further! The pitch is a great start, but there are still some open questions. I am moving this issue into planning to iron out some of those details and I created calculator-specs/expressionParser to track progress. A human will follow up with some feedback on your pitch shortly. Keep in mind that not all ideas that make it into the planning phase are guaranteed to make it to release. For more information on next steps, check out our spec workflow.

grochocki commented 4 years ago

Overall, this seems like a great improvement! A couple comments/questions:

I suggest making the mathematical operators customizable, as they are regional, cultural and personal preferences.

@leduyquang753 I am not sure I understand your example; can you clarify? I agree we should support any standard input methods, but I don't think it makes sense to support custom operator input assignment.

rudyhuyn commented 4 years ago

I agree, custom operators will require a lot more work (including a dialog to modify them) and can create many issues with shortcuts or when new features will be added to the Calculator.

@leduyquang753 Based on your example, when you write "personal preferences", I suppose you don't mean Users can select a random character but "the user must be able to use the symbols of his/her/their choice from among the official symbols".

If it's the case, I agree with that, all official symbols should be supported, it's the case of the proto I wrote some months ago. Of course, except when they create a conflict.

The goal should be to allow a user to copy & paste a formula from a website, whatever the language of the website and make it work without any modification. For example:

Multiplication:

Division:

leduyquang753 commented 4 years ago

⋅ (note: this is not the period symbol, already used as a decimal separator in some languages)

Actually Vietnam uses the period to indicate multiplication (officially used in education, textbook images can be included if needed). In order not to create conflicts (if the decimal separator is already period), a check can be easily implemented.

HowardWolosky commented 4 years ago

It may be worthwhile to review what @rudyhuyn started in #344 when working through the spec'ing for this issue.

crutkas commented 3 years ago

Like to state, PowerToys would very much like this :)

crutkas commented 3 years ago

is there a list of expressions this will support? Example: bin2dec or arcsin

gounaman commented 3 years ago

so like is anything happening with this?