PocketCalc – Programmable Pocket Calculator
Start by clicking a green flag. You can click the buttons on screen or use the keyboard: N="±", V="√", C="C", Z="AC", P=".", T="%", M="*", A="+", Q="?", D="/", S="-", E="=", L="MC", R="MR", I="M-", U="M+", Y="MS", X="X". (Scratch-programs can only use arrow-keys, 0-9, and a-z (and doesn't know shift-key status), except in answer-boxes where all characters can be typed.)
The question-mark-button "?" enters the program editor. You use the same symbols when programming as on the buttons on-screen, except that you use "*" and "/", and you can use "n" and "v" instead of "±" and "√". The programs are case-insensitive and unknown commands are ignored.
An example program computing √10 using Newton–Raphson method is stored (AC MC 1 M+ A0 10 / MR - MR / 2 M+ JT0 MR). Press Enter or click the OK-button to run the current program or type in a new.
The labels/anchors are A0 to A9 and there are five jump-commands: JU (unconditional), JT (true), JF (false), J+ (>=0), and J- (<0), e.g. JT0 goes to anchor A0 if the display is not close to zero (i.e. |display| > 9E-16).
You can select memory by using e.g. 7 MS (short for Memory Select). The M-commands then use memory 7. The default-memory is 0 and you can use as many memories as the Scratch Player allows. I believe this indirect addressing of memory together with the conditional jump-commands makes PocketCalc Turing-complete. You can eXchange the display with a hold-memory using X (similar to Sed).
You can call a subroutine/procedure/function if you precede a jump-command with _ e.g. _JU1. You can return from a subroutine using a jump with the special anchor/label ^ e.g. JU^. If you use ^ as a command it pops the return-stack but ignores the result. Actually _ pushes the program-counter to the return-stack.
There is a pause-command p that stops execution, to resume click ? and OK-button (or press Q and Enter). While pausing you can use the calculator as you normally would.
This example computes nCr (combination), e.g. possible poker-hands (5 cards) from 52 cards: 52 q
Enter 5 q Enter
Should show about 2598960.
Another example: Simpson's Rule compute the integral for y=2x^2+3x-1 in the interval 1 to 5 with 6 divisions: 6 q
Enter 5 q Enter 1 q Enter
Should show 114.66667.
You can change the integrand by editing between a1 and ju^.
This is a simple pocket calculator but with constant function and percent add and subtract. It appeared on Scratch front-page 2013-Dec-17. Thanks to @EH7meow for curating it! Thanks to all for commenting!!
It is based on PocketCalc in Java by myself in 1995: http://www.df.lth.se.orbin.se/~mikaelb/pocketcalc.html . I had some earlier prototype in Visual Basic (actually EXObasic, part of EXO4).
This is bug-corrected compared to the Java-version and is also programmable. I intend to develop this further with e.g. seven-segment display, and it should be draggable, and rotatable.
You can also test it in the HTML5-player:
There is also an older RasPi-version of this program in the studio "Raspberry Pi Tested" http://scratch.mit.edu/studios/244489/