Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Percent sign ignores parenthesis #273

Open
Loading102 opened this issue Apr 19, 2023 · 4 comments
Open

Percent sign ignores parenthesis #273

Loading102 opened this issue Apr 19, 2023 · 4 comments
Labels
bug Something isn't working help wanted Extra attention is needed important Important things to do
Milestone

Comments

@Loading102
Copy link
Contributor

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

Screenshot_20230419-114004_Calculator

@Darkempire78 Darkempire78 added the bug Something isn't working label Apr 19, 2023
@ChinhQT
Copy link

ChinhQT commented May 11, 2023

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

@Loading102
Copy link
Contributor Author

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
Copy link

ChinhQT commented May 11, 2023 via email

@Darkempire78
Copy link
Owner

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

@Darkempire78 Darkempire78 added this to the 3.0.x milestone Jun 19, 2023
@Darkempire78 Darkempire78 added the important Important things to do label Jul 28, 2023
@Darkempire78 Darkempire78 modified the milestones: 3.0.x, 3.0.0 Nov 1, 2023
@Darkempire78 Darkempire78 pinned this issue Nov 1, 2023
@Darkempire78 Darkempire78 added the help wanted Extra attention is needed label Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed important Important things to do
Projects
None yet
Development

No branches or pull requests

3 participants