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

Calculator doesn't calculate #9

Closed
joaquinvacas opened this issue Oct 11, 2024 · 13 comments · Fixed by #20
Closed

Calculator doesn't calculate #9

joaquinvacas opened this issue Oct 11, 2024 · 13 comments · Fixed by #20

Comments

@joaquinvacas
Copy link

I think I don't have to explain further → A picture is worth a thousand words

image

@joaquinvacas
Copy link
Author

Forgot to mention: Release is the latest from Flathub, 0.1.0

@edfloreshz
Copy link
Member

Thanks for opening this issue, I'll try to fix this in the next couple days.

@Joomsy
Copy link

Joomsy commented Oct 12, 2024

Forgot to mention: Release is the latest from Flathub, 0.1.0

Same issue exists when built from source. I had to double take after doing some subtraction, because the result was far from being correct. I'd also get something random each time when trying to do addition.

Also, this is a little OT, but numpad support would be greatly appreciated. :)

@edfloreshz
Copy link
Member

This should be fixed by 046bec0, I'll await for feedback before closing this.

@Joomsy
Copy link

Joomsy commented Oct 14, 2024

This should be fixed by 046bec0, I'll await for feedback before closing this.

Sorry for the late response. I work weekends, so I wasn't able to get back to this until now. Something still seems a little off. At first, addition gave me something wildly incorrect (8+8=66), but after plugging in more things, it seems to have corrected itself. I can't get it to reproduce an incorrect output. Algebraic expressions, however, do give the wrong output. This is actually supposed to be 30.

screenshot-2024-10-14-22-50-01

@l-const
Copy link

l-const commented Oct 28, 2024

Yeah, the calculator-rs dependency doesn't handle operator precedence without parenthesis, so it's AST is kind of wrong, if you want to make it work correctly and in an easy way just copy the implementation of the parser & evaluator from here: https://github.com/balajisivaraman/basic_calculator_rs/blob/master/src/main.rs it uses the nom parser library : https://github.com/rust-bakery/nom , famous for those kind of things, there is a book here: https://tfpk.github.io/nominomicon/introduction.html , cc @edfloreshz

@edfloreshz
Copy link
Member

Thank you, I'll look into it as soon as possible.

@uciharis
Copy link

screenshot-2024-12-31-11-54-55

bro, i dont have any idea what i see

@l-const
Copy link

l-const commented Jan 6, 2025

I have some fixes (there may be other bugs) in an open PR here: https://github.com/0byteme/calculator/pull/1/commits or on my main branch on my fork: https://github.com/l-const/calculator cc @edfloreshz . Also this line here does integer division: https://github.com/0byteme/calculator/blob/main/src/lib.rs#L151. e.g: 4 / 5 = 0 not 0.8 it calls this: https://doc.rust-lang.org/std/primitive.i64.html#impl-Div-for-i64 , not sure this is what we want but didn't check it much further. Actually, opened a separate issue for this one to question the impl: 0byteme/calculator#2, @uciharis that is integer division most probably. https://gist.github.com/rust-play/21f0af3fb853da359f3af66b1690bc60

@mmstick
Copy link

mmstick commented Jan 6, 2025

calculator-rs doesn't seem to be actively developed or maintained. Perhaps it'd be better to use evalexpr instead. It's still being actively developed.

@edfloreshz
Copy link
Member

Thanks, I've been busy with other projects but I'll try to make some time for calculator next weekend.

@edfloreshz
Copy link
Member

Should be solved, we can reopen if we find issues again.

@l-const
Copy link

l-const commented Jan 11, 2025

did you check integer division @edfloreshz , i am not sure it is handling appropriately from this comment: ISibboI/evalexpr#125 (comment) they are using a programming evaluation context and not one for gui calculation one? what 4 / 5 outputs? Nevermind, it actually works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants