-
Notifications
You must be signed in to change notification settings - Fork 32
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
[rpncalc] NEG command #185
Comments
I'm attaching here the diffs for an implementation of NEG and DUP (DUP is not a new command, but PUSH was modified so that consecutive PUSHes behave as DUP --This is the same behaviour of the Enter key in the HP48). They are straightforward, as you can see. I tested them and they work.
Feel free to add them to your source if you consider them interesting (for me they are a must, as I said 😄 |
do you want to pr them or should I just commit it? thanks for the code!! |
Feel free to commit it, because I don't have a properly prepared github workflow yet and this weekend is going to be very busy for me. If you prefer I can send you the source (I was going to do so in my message, but github doesn't allow to attach source code, so I did the diffs instead). BTW, I continued working on it, moving the buttons so that they are closer to the position they have in the HP48, because it's the calculator I always use. I removed some buttons, added new buttons, added a couple that don't exist in the HP48 (toDEG and toRAD, for converting to degrees and radians). I didn't create a new directory for this new code, but I rename the executable to rpncalc48 when I build it, to differentiate it from your executable. Of course it's not an HP48 emulator, nor a simulator. I'm in fact (in another project of my own) developing a new RPN language which I started last month, but it's not a clone of the HP48 language (although it has some things in common, of course). If I finish my RPN language (I hope so), I'll port it to the rm tablet, but it will take time. It's currently a UNIX terminal program. Back to the new changes I did to rpncalc (rpncalc48): Also added an "angle mode" button. You can see it in the lower right (see screenshot below). It's a hack (very dirty hack: I just overwrite the text in the button flipping it from RAD to DEG and vice versa), but lets you work with trigonometry both in degrees and in radians. I also removed the sinh, cosh, and tanh, because asin, acos, and atan are much more commonly needed (I never use the hyperbolic functions, but I use asin, atan, acos much more frequently). Another change I did is to print all significant digits of a double (using printf() and DBL_DIG), because the HP48 by default printed all digits (except trailing zeroes). I did this using "%G" printf format with DBL_DIG precision --now it's not needed to remove trailing zeroes anymore ("%G" does it automatically for you). Because of these changes, now the code has a non-elegant mix of C and C++ ...I was a C++ programmer for quite a few years, but I got tired of them deprecating lots of stuff in every new version of the standard, and so I decided to get back to C. Much better for me, my mind is definitely more C-friendly than C++-friendly. If you ask me what language I'd take to a desert island it would be C 😄 I will see if I can make the stack infinitely large, so that you never lose numbers no matter how many pushes you do. I think a push_back() at the push command should make the trick, but I need to check because I don't know how the stack GUI gets the values from the stack items. If you are interested in these changes, tell me and I send you the code so that you can make the diffs yourself. It's in fact just a few diffs, not so much of a change. You can see that I modified the layout to have the buttons closer to the HP48 position. Look: |
It's not easy to make the stack grow/shrink dynamically, because the stack items are actually UI texts. So I'm postponing that addition for the moment. |
the +/- command would also be useful to enter very small numbers in scientific format. Like 15e-3 = 0.015 or 3e-12 etc. |
the NEG command was committed, but not the +/- yet |
Another very important command is missing: NEG (it flips the sign of the last item in the stack, becoming negative if it was positive and vice versa). This command is very important, because it's the only way for entering negative numbers. Try it yourself: try to calculate 57 * (-5) and you'll see you cannot enter -5 😄
In the HP48, the NEG command was triggered by the '+/-' key.
The text was updated successfully, but these errors were encountered: