|Stack preservation in the HP35S|
Message #1 Posted by Valentin Albillo on 25 July 2007, 1:05 p.m.
In a different thread (Gerson W. Barbosa's "alternative cos(x) and tan(x) [HP-33S]"), Les Wright posted:
f(X) = (X/e)^X*Sqrt(2*Pi*X)*(1+1/(12*X)+1/(288*X^2))
and you want it to behave as a built-in function as far as stack behaviour is concerned. You can achieve that in the HP35S without using any auxiliary registers or variables with this simple trick, key in this little proof-of-concept program in your HP35S:
A001 LBL A
where I've used "/" to denote the division key and "*" to denote the multiplication key, as well as "Pi" to denote the Pi key.
To run it, just key in you argument in ST X, and XEQ A [ENTER]: the result will be returned to ST X, the previous contents of ST X will be stored in LASTx, and the rest of the stack will be unaffected.
For instance, in FIX 4, press:
4 [ENTER] 3 [ENTER] 2 [ENTER]
5 [XEQ] A [ENTER] -> 120.0025
[ROLLDOWN] -> 2.0000
[ROLLDOWN] -> 3.0000
[ROLLDOWN] -> 4.0000
[LASTx] -> 5.0000
Perhaps this is a little slower than pure RPN, but quite convenient indeed. Of course the same trick will work with any f(X) you care to define as long as it can be defined as an equation.
I'll hope you'll like this little neat technique but if not, just stick to pure RPN and you'll be no worse than before :-)
Best regards from V.