HP Forums

Full Version: WP-34S Polar to Rectangular (no quadrant checking)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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
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 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 Smile Thanks for sharing.

I think the XROM code would be:

                XIN DYADIC
                RCL Y
                RCL[times] Y
                [<->] YZXX
                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
Wouldn't something like this work equally well in DP mode, be fast, and use less memory since the
function cmplxFromPolar could be eliminated.


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);
  setXY(&x, &y);
#ifdef RP_PREFIX
  RectPolConv = 2;
It is possible to implement a C version of course, xrom routines are genearlly easier to debug Smile

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
This code change is in. Nothing is built yet.

- Pauli
(03-02-2014 01:52 AM)Paul Dale Wrote: [ -> ]Nothing is built yet.
Really? Wink
At least the emulators are. I'll fix the iOS version later.
Reference URL's