WP-34S Polar to Rectangular (no quadrant checking)
Post: #1
 BarryMead Senior Member Posts: 350 Joined: Feb 2014
WP-34S Polar to Rectangular (no quadrant checking)
Many HP calculators include special quadrant checking for the 0, 90, 180, 270 degree quadrant values when performing the Polar to Rectangular conversion. For instance if you have 90 degrees in the
Y register and 1 in the X register and press "f" "R<" (Polar to Rectangular) you get 3.799 E -38 for X and 1 for Y on the WP-34s (assuming Degrees mode), but on an HP-15C you get 0 (zero) for X and 1 for Y.
If the calculator were in GRADS mode these values would be 0, 100, 200, 300. Most HP calculators don't attempt to match quadrant angular values while in the RAD mode.

Adding special checks for these quadrant values could cost valuable flash memory space, but since the existing SIN and COS functions already include these special quadrant checks, it may be possible to fix the Polar to Rectangular function by using existing SIN and COS routines, hopefully eliminating the need for additional quadrant checks.
02-28-2014, 12:04 AM
Post: #2
 Paul Dale Senior Member Posts: 1,203 Joined: Dec 2013
RE: WP-34S Polar to Rectangular (no quadrant checking)
As a space saving measure these routines simply vector through the complex rectangular/polar conversions which assume radians and convert back afterwards.

It wouldn't be too hard to rework rectangular -> polar to using the trig routines that know about angular mode -- it will be slower since the dn_sincos() routine calculates both SIN and COS of its argument in radians together. There is no equivalent routine that knows about angular mode.

Another alternative, would be to move these two functions into XROM. I don't see any direct call to them or references from inside XROM so it should be possible. This would save some space too I imagine but at a cost of performance and accuracy in DP mode.

- Pauli
Post: #3
 BarryMead Senior Member Posts: 350 Joined: Feb 2014
RE: WP-34S Polar to Rectangular (no quadrant checking)
The "Rectangular to Polar" works just fine. It is only the "Polar to Rectangular" that has problems with three of the four quadrants! At angles 90, 180 and 270 the value that should return as zero comes back as a tiny value like 3.799 E -39 instead of zero. Since all other HP calculators that I can run tests on do the Polar to Rectangular conversion correctly (only the WP-34S has these inaccuracies), and since these four angles are more common than others, I would think that people would want this to be fixed. The new Polar to Rectangular function would be: NewX = X COS(Y) and NewY = X SIN(Y), using the existing SIN and COS functions that already handle these special quadrant angles properly.
02-28-2014, 06:18 AM
Post: #4
 walter b On Vacation Posts: 1,968 Joined: Dec 2013
RE: WP-34S Polar to Rectangular (no quadrant checking)
(02-28-2014 12:33 AM)BarryMead Wrote:  The new Polar to Rectangular function would be: NewX = X COS(Y) and NewY = X SIN(Y), using the existing SIN and COS functions that already handle these special quadrant angles properly.

Good idea Thanks for sharing.

d:-)
02-28-2014, 07:55 AM (This post was last modified: 02-28-2014 08:27 AM by Paul Dale.)
Post: #5
 Paul Dale Senior Member Posts: 1,203 Joined: Dec 2013
RE: WP-34S Polar to Rectangular (no quadrant checking)
I think the XROM code would be:

Code:
        XLBL "RECTPOLAR"                 XIN DYADIC                 RCL Y                 SIN                 RCL[times] Y                 [<->] YZXX                 COS                 [times]                 XOUT xOUT_NORMAL

It will be a lot slower than the C version and less accurate in DP mode but should deal with these orthogonal cases properly.

I'm not implementing and debugging this tonight however.

- Pauli
Post: #6
 BarryMead Senior Member Posts: 350 Joined: Feb 2014
RE: WP-34S Polar to Rectangular (no quadrant checking)
Wouldn't something like this work equally well in DP mode, be fast, and use less memory since the
function cmplxFromPolar could be eliminated.

Code:
 void op_p2r(enum nilop op) {   decNumber x, y, t, range, angle;   getXY(&range, &angle);   decNumberCos(&t, &angle);   dn_multiply(&x, &t, &range);   decNumberSin(&t, &angle);   dn_multiply(&y, &t, &range);   setlastX();   setXY(&x, &y); #ifdef RP_PREFIX   RectPolConv = 2; #endif }
03-01-2014, 11:26 PM
Post: #7
 Paul Dale Senior Member Posts: 1,203 Joined: Dec 2013
RE: WP-34S Polar to Rectangular (no quadrant checking)
It is possible to implement a C version of course, xrom routines are genearlly easier to debug

I've no certainty about the size difference without building both versions however I suspect your code will be slightly larger the cmplxFromPolar routine will have been inlined so there is no call there to save. Your code will be slow, the SIN and COS are by far the most expensive operations and they are being done separately rather than together -- the modulo reduction is quite a bit bit of these.

Will try to get a look at it this weekend.

- Pauli
03-02-2014, 01:52 AM
Post: #8
 Paul Dale Senior Member Posts: 1,203 Joined: Dec 2013
RE: WP-34S Polar to Rectangular (no quadrant checking)
This code change is in. Nothing is built yet.

- Pauli
03-02-2014, 03:03 PM
Post: #9
 Marcus von Cube Senior Member Posts: 745 Joined: Dec 2013
RE: WP-34S Polar to Rectangular (no quadrant checking)
(03-02-2014 01:52 AM)Paul Dale Wrote:  Nothing is built yet.
Really?

Marcus von Cube
Wehrheim, Germany
http://www.mvcsys.de
http://wp34s.sf.net
http://mvcsys.de/doc/basic-compare.html
03-02-2014, 07:22 PM
Post: #10
 pascal_meheut Member Posts: 124 Joined: Dec 2013
RE: WP-34S Polar to Rectangular (no quadrant checking)
At least the emulators are. I'll fix the iOS version later.
 « Next Oldest | Next Newest »

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