Darkempire78 / OpenCalc

A simple and beautiful calculator for Android
GNU General Public License v3.0
737 stars 82 forks source link

Percent sign ignores parenthesis #273

Open Loading102 opened 1 year ago

Loading102 commented 1 year ago

The percent sign seems to have a higher precedence than parenthesis, which seems... wrong...

Screenshot_20230419-114004_Calculator

ChinhQT commented 1 year ago

Do you any suggestion to resolve the problem ? I want to read some ideal to resolve one.

Loading102 commented 1 year ago

The +x% is generally a problematic way of using the percent sign, as it's not mathematically defined. But you could stick to the idea that the percent doesn't mean just ÷100 only when it's directly following a number, and that number is a direct part of some sum/substraction. Then before parsing the equation you enclose all previous elements of this sum in parenthesis, and change the +x% to ×(1+x÷100). However, I don't know how this calculator parses it's input, so maybe there's a better solution.

ChinhQT commented 1 year ago

Do you know any algorithm to discuss about this topic ? I used the Google’s Calculator, it works well. So, I want to develop one. But, currently, I don’t have any solution to resolve. By the way, Which algorithm you used to evaluate the expression string ? As the shunting yard algorithm ?

On 11 May 2023, at 16:41, Mateusz Zmuda @.***> wrote:

The +x% is generally a problematic way of using the percent sign, as it's not mathematically defined. But you could stick to the idea that the percent doesn't mean just ÷100 only when it's directly following a number, and that number is a direct part of some sum/substraction. Then before parsing the equation you enclose all previous elements of this sum in parenthesis, and change the +x% to ×(1+x÷100). However, I don't know how this calculator parses it's input, so maybe there's a better solution.

— Reply to this email directly, view it on GitHub https://github.com/Darkempire78/OpenCalc/issues/273#issuecomment-1543675652, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADIQB26P2HH52HKT6OMFIETXFSX27ANCNFSM6AAAAAAXDZ36LM. You are receiving this because you commented.

Darkempire78 commented 1 year ago

Do you know any algorithm to discuss about this topic ? I used the Google’s Calculator, it works well. So, I want to develop one. But, currently, I don’t have any solution to resolve. By the way, Which algorithm you used to evaluate the expression string ? As the shunting yard algorithm ? On 11 May 2023, at 16:41, Mateusz Zmuda @.***> wrote: The +x% is generally a problematic way of using the percent sign, as it's not mathematically defined. But you could stick to the idea that the percent doesn't mean just ÷100 only when it's directly following a number, and that number is a direct part of some sum/substraction. Then before parsing the equation you enclose all previous elements of this sum in parenthesis, and change the +x% to ×(1+x÷100). However, I don't know how this calculator parses it's input, so maybe there's a better solution. — Reply to this email directly, view it on GitHub <#273 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADIQB26P2HH52HKT6OMFIETXFSX27ANCNFSM6AAAAAAXDZ36LM. You are receiving this because you commented.

The problem is with the function that create the expression https://github.com/Darkempire78/OpenCalc/blob/main/app/src/main/java/com/darkempire78/opencalculator/Expression.kt#L43