Skip to content

Calculator example bugs and improvements #2576

Description

This may be the first example many people will look at so imho it deserves some love. Do you prefer very small grained PRs or dumping smaller things into this thread?

Anyway, the first issue that hit me is that "ln" and "log" do nothing. "ln" should be unary and adding it to the uops is straightforward and works as expected. "log" appears to be intended as binary and I can not see why it does not work.

Also the whole logic of the calculator suffers a bit from the problem that "basic" and "scientific" calculators almost always use different logic of evaluation: "basic" won't honour arithmetic precedence rules, scientific will. So it may be an idea to concentrate on the scientific branch and make it real good.

Activity

  1. xymus commented on Nov 14, 2017

    @xymus
    Contributor

    I agree, the calculator needs love. I've addressed a few issues you raised in #2579, but there is still work to do. I welcome small grained PRs and we can keep general discussions here.

    The calculator project was more of an excuse to test/showcase the UI system, I spent less time on the underlying logic and it has badly evolved. The scientific ops were added quickly and may very well have issues. Feel free to improve the logic or rewrite it, separating the scientific logic could be a good idea to preserve a simple behavior in the classic variant.

    My priority with the calculator is to keep the UI code simple and clean, but the logic can get more complex.

    I have a suggestion to implement the precedence rules (and support keyboard input as a bonus), you could use and extend the calc example of nitcc (the Nit Compiler Compiler). The calc example is basically a calculator interpreting a string: https://github.com/nitlang/nit/tree/master/contrib/nitcc/examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions