Equations in programs really are a nice feature of the 35s. They simply return the result in X and push the stack by one level, while no other stack registers – including LastX – are affected. So these programs simply move the original X to LastX (by means of the ABS command in line 004) before they finally return the two results in Y and X.

For those who are not that familiar with the 35s equation mode: REGZ and REGT are entered by pressing the [R↓] key and then selecting the respective register X, Y, Z or T from the menu.

Stack diagram for →P:

Code:

T: t t
Z: z z
Y: y => θ
X: x r

L: ? x

Stack diagram for →R:

Code:

T: t t
Z: z z
Y: θ => y
X: r x

L: ? r

Finally, if the state of flag 10 does not have to be preserved the code can be even shorter. In this case remove line 011...014 and replace line 002...003 with "CF 10".

Yes for the stack and flags, but No regarding LastX. Which is not preserved – on exit it contains a complex number or a vector, respectively.

Well, that should teach me! I read a post claiming all was preserved and while I bothered to check the flags (by reading code) and the stack contents (by testing), and all was confirmed, I did not check the LastX and extrapolated it too was safe. Never, ever assume...

Thanks for this alternate version Dieter. For the 2nd time in a week, after not touching it for a couple years, I've decided to enter programs in my 35S. If I learned about how useful and well-behaved equations are on the 35S when I got mine in 2007, I've totally forgotten it, so Pauli and your programs are good examples of how this feature can be used to build well-behaved functions pretty easily.

OK, this may happen anytime as all we got are 12 digits instead of 15 the 35s uses internally. But on average the more complicated formulas in post #10 seem to exibit less of such problems. In all three cases it returns accurate results. Maybe because sine and cosine of the angle are avoided (only their sign is considered).