|Re: WP34s: complex SLVQ|
Message #28 Posted by Paul Dale on 13 Aug 2011, 8:30 p.m.,
in response to message #22 by Walter B
How about taking "A" instead?
No no no no no!!!!!!! Lettered things are special and shouldn't be used in libraries.
Fortunately, this is intended for XROM. With a suitable prologue and epilogue added to the code, there are another five registers available. These are numbers 00 through 04 and they are completely separate from the same numbered registers the user sees. There are also fifteen extra flags 00-14 FWIW. XROM also operates with a stack size of four regardless of what the user sets -- this might cause problems with stack drop.
So, what I'd be doing is to preserve T & I in two of these extra registers, use a third for the temporary storage of the value. A fourth preserving X if you want Last X done like an internal operation.
Then do the calculation and finally fix things up at the end. Yes this will take more steps. Often quite a few more.
For the b^2 - 4ac calculation use a complex multiply.
Assuming a, b & c are in X, Y & Z respectively (also should work for c, b & a in X, Y & Z).
4 a b c T
* 4a b c T
RCL Y b 4a b c
cpx * b^2-4ac b(4a+c) b c
x<>y b(4a+c) b^2-4ac b c if only we'd kept the DROPY instruction :-)
DROP b^2-4ac b c c
Which, assuming I've got that correct, will calculate the difference without any loss of precision. Also, 4a is still in I.
Edited: 13 Aug 2011, 8:32 p.m.