Post Reply 
Best Pol/Rect and Complex Number Decomp for 35S
01-26-2019, 04:23 PM (This post was last modified: 01-26-2019 04:47 PM by Dieter.)
Post: #7
RE: Best Pol/Rect and Complex Number Decomp for 35S
(01-26-2019 01:04 PM)rprosperi Wrote:  ...if you look closely you'll see these routines preserve the stack (incl LastX) and flags...

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.

But it can be done. The following modified versions also preserve LastX:

P001  LBL P
P002  FS? 10
P003  GTO P011
P004: ABS
P005  X<>Y
P006  R↓
P007  R↓
P008  eqn ARG(LASTx+i*REGZ)
P009  eqn ABS(LASTx+i*REGT)
P010  RTN
P011: CF 10
P012  XEQ P004
P013  SF 10
P014  RTN

R001  LBL R
R002  FS? 10
R003  GTO R011
R004: ABS
R005  X<>Y
R006  R↓
R007  R↓
R008  eqn LASTx*SIN(REGZ)
R009  eqn LASTx*COS(REGT)
R010  RTN
R011: CF 10
R012  XEQ R004
R013  SF 10
R014  RTN

The R routine is even one step shorter. ;-)

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:
T:  t        t
Z:  z        z
Y:  y   =>   θ
X:  x        r

L:  ?        x

Stack diagram for →R:
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".

Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
RE: Best Pol/Rect and Complex Number Decomp for 35S - Dieter - 01-26-2019 04:23 PM

User(s) browsing this thread: 1 Guest(s)