-
-
Notifications
You must be signed in to change notification settings - Fork 938
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
Simple calculator #1483
base: main
Are you sure you want to change the base?
Simple calculator #1483
Conversation
I feel like the original design from #375 was simpler and cleaner, the multifunctional +/- and */ buttons might be too much of a hassle for regular use. |
About the printing of the value, I think that doing something like what's done here should be fine:
Edit: looking at the code, seems like you're already using something like this. I would say that it would be better to use fixed width integers instead of long ints, so that it's obvious what the min and max values are. |
@joseph58tech, you mean the design with two keyboard layers? @FintasticMan, I can change |
You can either leave the format string as |
This looks amazing, thanks for making it! The UI looks really nicely designed with a good balance of button size and ability to do most of the major operations you would need. Personally I prefer the simplicity of this app though I see advantages in both. I also love the inclusion of I would love to one of the calculator apps merged in an upcoming release and I'll probably be using it on my PT until then. It feels like the biggest thing currently "missing" from the PineTime to me. Along with the usefulness of having a calculator close by, a small part of that is probably from reminiscing about these calculator watches from childhood, haha. |
Thank you! 😊 Nice to hear that you want to try it already. This may help with finding any eventual bugs. I haven't tried the last two commits on my watch because I have another test build running right now. |
Looks good, I've tried this on my watch and it works quite nicely. I do think that it is better to use floats rather than doubles for the pow calculation. Why did you switch to doubles? |
Thanks! I thought I had worked through all the replacements of float for double. Where did you find a double?
From: ***@***.***>
Sent: Monday, December 12, 2022 4:44 PM
To: ***@***.***>
Cc: ***@***.***>
Subject: Re: [InfiniTimeOrg/InfiniTime] Simple calculator (PR #1483)
Looks good, I've tried this on my watch and it works quite nicely. I do think that it is better to use floats rather than doubles for the pow calculation. Why did you switch to doubles?
—
Reply to this email directly, view it on GitHub<#1483 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A3C6AGUV6STVDJILC6TNB23WM6TD3ANCNFSM6AAAAAASYQQYU4>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
I thought that double matches the 64-bit integers better than float. Is that correct? 🤔 |
I switched to floats instead of doubles to see if the compiler would make use of the FPU. And I was very pleased to see big performance increase (something like 10x). So I assume the FPU is in use.
From: Max ***@***.***>
Sent: Monday, December 12, 2022 5:22 PM
To: ***@***.***>
Cc: ***@***.***>; ***@***.***>
Subject: Re: [InfiniTimeOrg/InfiniTime] Simple calculator (PR #1483)
I thought that double matches the 64-bit integers better than float. Is that correct? 🤔
The workaround is necessary because I wanted to have a power function and could not find one the works with the fixed point numbers. Speed should be no concern for one calculation.
—
Reply to this email directly, view it on GitHub<#1483 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A3C6AGUHY7CZYVJSGQM3CE3WM6XR7ANCNFSM6AAAAAASYQQYU4>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Oh, and the datasheet specifies that the FPU is restricted to float.
From: Max ***@***.***>
Sent: Monday, December 12, 2022 5:22 PM
To: ***@***.***>
Cc: ***@***.***>; ***@***.***>
Subject: Re: [InfiniTimeOrg/InfiniTime] Simple calculator (PR #1483)
I thought that double matches the 64-bit integers better than float. Is that correct? 🤔
The workaround is necessary because I wanted to have a power function and could not find one the works with the fixed point numbers. Speed should be no concern for one calculation.
—
Reply to this email directly, view it on GitHub<#1483 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A3C6AGUHY7CZYVJSGQM3CE3WM6XR7ANCNFSM6AAAAAASYQQYU4>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Ok, I will test both types on the watch. Thank you for the input! |
So sorry, I thought this was related to my recent pull request and responded in that context. Anyway, you might try powf() with floats.
From: Max ***@***.***>
Sent: Monday, December 12, 2022 6:27 PM
To: ***@***.***>
Cc: ***@***.***>; ***@***.***>
Subject: Re: [InfiniTimeOrg/InfiniTime] Simple calculator (PR #1483)
Ok, I will test both types on the watch. Thank you for the input!
—
Reply to this email directly, view it on GitHub<#1483 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A3C6AGQO2EACQDE7LOS6PI3WM67FHANCNFSM6AAAAAASYQQYU4>.
You are receiving this because you commented.Message ID: ***@***.***>
|
I apologize for any confusion, I thought this was related to a pull request I made.
From: ***@***.***>
Sent: Monday, December 12, 2022 4:44 PM
To: ***@***.***>
Cc: ***@***.***>
Subject: Re: [InfiniTimeOrg/InfiniTime] Simple calculator (PR #1483)
Looks good, I've tried this on my watch and it works quite nicely. I do think that it is better to use floats rather than doubles for the pow calculation. Why did you switch to doubles?
—
Reply to this email directly, view it on GitHub<#1483 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A3C6AGUV6STVDJILC6TNB23WM6TD3ANCNFSM6AAAAAASYQQYU4>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
While doubles are 64 bits wide, that doesn't make a difference for int > float and float > int conversion. 32-bit floats will definitely have enough precision for this calculation, and as Ceimour already said, the FPU in the nRF 52832 is for 32-bit floats only, so double calculations will be done much less efficiently. |
This says that there are 9 digits for float and 17 for double. 9 is not enough. That is only 6 integer digits. |
Hey @minacode, if the variable used to store the calculated value overflows, the watch reboots... |
Thank you for testing this! It doesn't happen in the simulator so I wonder what makes the watch crash. Edit: I tested the last changes on the watch and it seems like a lot broke. Maybe we have to revert some of the changes. |
@minacode : I've been using the calculator for a little while now. Overall for most calculations it's working great, doing just what it's supposed to, and has been very useful-- gonna keep using it on my build and I would love to see it included in an upcoming milestone! Basically it has worked flawlessly for me with any small integer operations (small meaning anything not huge, like less than 10^12). Deviating from small integers, there are a few bugs to iron out:
I hope this is helpful-- FYI these are all on PineTime hardware, I haven't tested any of these in the sim! If I have time in the upcoming days, I might poke around the code and see if I can help troubleshoot the causes for some of these. |
Thank you so much for this detailed feedback! You even gave examples to reproduce. This is very helpful. There seems to be a difference in behaviour between the simulator (x86) and the watch. I am currently diving in the details to get everything a little more safer. The format strings are way less forgiving on the watch it seems. At first I ignored the issues around overflows but I get that the UX would be heavily improved by a controlled maximum value.
This is a good idea. It would also be a lot more forgiving since it would not delete the result instantly. I don't know about a |
That's usually "repeat the last operation" |
Then this shall be it. |
Glad it is helpful-- thanks for your diligence!
I was thinking the same thing at first: probably very few users would need to perform calculations at the level needed to cause overflow. It's more the kind of bug that comes out of the user looking for ways to break the app. But out of principle it is best to foolproof it such that the user is incapable of causing a crash with any combination of inputs, and to make it clear when the user passes into too-large territory where the calculations or interface start to break down. 🙂
Agree! That would be a more expected behavior for PS: This might be a good |
Just wanted to add briefly -- In case it is helpful with troubleshooting this one: this bug also happens with division of non-divisible integers. For example, 52/53 and 1/2 both evaluate to 0.48957. |
Ok, so I changed some things in the last commits. It's not done yet, but we are getting there.
All changes are only tested in the simulator for now. And I have a question: How exactly do you expect the Currently it calculates a new result and keeps the value and operation untouched. Therefore you can press it multiple times for repeated calculation. But this causes two issues:
One could use the backspace but it seems very inconvenient to me. |
The last commit is an experiment for the UX. Instead of standard button presses you can now hold the touch and drag it accross the button matrix. The current button is colored with a different background. Releasing triggers the button handle. I hope that this help with pressing the correct buttons on the small screen. If anyone has a good suggestion for the focus color I will add it. I am not good with colors 😀 |
Awesome, thanks for your work on this-- love the changes!! Tested new build on PineTime hardware and can confirm that:
The way Here's the way I would recommend addressing those two issues: i. I agree this is confusing. I would make it so that pressing the operation buttons never causes a calculation-- only changes the current operation. The ONLY way to cause a calculation therefore would be pressing ii. I like your solution-- when
This sounds like a great idea, excited to try it out! (Of course, feel free to take or leave any of the suggestions above at your discretion! Just my thoughts but others might think differently and it is your app 🙂) |
Again thank you for the feedback! It means a lot 😊
|
I did some updates:
There are some minor issues left that I will continue working on. |
Awesome updates! Thanks for your work 👍 Testing latest build on PineTime hardware and all the bugs number 1-7 reported above are resolved from my end ✔️ I love the design changes like the touch/drag coloring, and coloring the currently active operation! Very clever & sleek. (Also, regarding the fixed vs floating point, that makes sense 🙂 I agree, I've become familiar with it and think fixed point is probably favorable for simplicity of design.) |
Instead of always adding the new digit it now gets multipled with a sign, based on whether value is negative or not. Thus, the addition becomes a subtraction for negative numbers.
Co-authored-by: SuIông N. <[email protected]>
This is necessary to ensure correct calculations. Themaximum int64 has 19 digits. Therefore, 18 digits are safe to use. But in order to calculate exact multiplication we need twice the number of digits after the comma, so I decided to go with 12 digits before the comman and 3 after it.
This commit updates the codebase to use the new interface for compile-time optional apps.
621fa7f
to
accd666
Compare
This comment in the other calculator implementation is interesting. Saving it here for later. |
Turns out that adding this Runs well on my watch for a day now. |
Nice! |
I don't know, but I will try. |
I think |
The last commit did not change something, so I guess that was all we will get. |
Oh they're equivalent, it's that constexpr is nicer to use in general as it is a guarantee of compile time evaluation (if it cannot be evaluated at compile time compilation fails). The way you had previously is the way to do it in C, with constexpr added to C++ |
So we just leave it like this, because more const -> more good? 😀 |
The const immediately after constexpr is redundant (constexpr implies const) so I'd remove that personally but it doesn't make a difference in terms of semantics |
Because it is redundant
This PR implements a simple fixed-point calculator. In contrast to #375 it aims to be simpler by not parsing whole equations but just evaluating one operation at a time over an accumulated result.
It takes an operation and a value (digit-wise) and applies the value to the result with the chosen operation whenever a new operation is chosen or
=
is pressed.=
: evaluate current input<
: removes the input charwise or reset the result if the input is zero.(-)
: toggle the sign of the current input (thanks @FintasticMan)+ -
/* /
: press the button to cycle through the operators and "no-operator".It uses fixed-point numbers and checks for errors like too big results and zero division.
Known issues:
from @yusufmte's comment below:
Bug with crashing on large operations (thanks to @CCF100 too!)
Bug when typing a number larger than the interface allows
Bug with any use of the decimal point
Bug where if the result exceeds 12 digits, you will only see the last 12.
Bug when pressing ^, sometimes it will repeat whichever number you last placed
UI gripe / Suggestion (not a bug); backspace and extra clear button
=
should repeat the last operation (thanks @Avamander!)Check power overflow.
Show error messages.
Add power button toggle.
Fix button colors.
Set one check feature.
-3 * -5 results in "too large"
-6 repeatedly divided by -2 does not swap the sign right
number input is broken when value is negative
operator should only be removed if value is zero
987654321*100 does not trigger a "too large" warning
implement the interface for optional apps