lpar / RPN

Simple everyday RPN calculator for Android
15 stars 17 forks source link

Needs Stack Rotation commands #9

Open bobpaul opened 4 years ago

bobpaul commented 4 years ago

Basic RPN calculators usually have Swap, Rotate Up, Rotate Down, and "Repeat last value". This implementation is missing the rotate functions. The rotate functions, when combined with swap are sufficient to completely re-order the stack into any position you'd like.

Rotate Up

Ex: If the stack is

832
114
23
15

[R↑] will set the stack to

114
23
15
832

Rotate Down

Ex: If the stack is

832
114
23
15

[R↓] will set the stack to

15
832
114
23

Because of how these operations are frequently combined, I would like to see the secondary screen organized as

[  ⇩  ][  R↑ ]       [ 1/x ]
[ DROP][  R↓ ]       [  xⁿ ]
       [  ↑↓ ]
       [Enter][SetDP]

But if it's important for muscle memory to keep the existing buttons where they are, I think this would also work well:

[  ⇩  ]              [ 1/x ]
[ DROP]              [  xⁿ ]
[  ↑↓ ][  R↑ ]
[Enter][  R↓ ][SetDP]

Example Usage. Sort the stack by numerically:

4
5
8
3
0

[ R↑ ][ ↑↓ ][ R↓ ][ ↑↓ ][ R↓ ][ R↓ ][ ↑↓ ][ R↓ ][ R↓ ] results in

8
5
4
3
0

When combined with [Enter] to duplicate the number on the bottom of the stack we end up with a powerful calculator that effectively have unlimited accumulators. While basic calculators often have MR, MC, M+ and M- to provide a single off-screen accumulator, the rotate functions make it easy to work on multiple, unrelated computations simultaneously without clearing the screen