HP-15C fans --

Here is a compact library of seven complex-number utility functions for the HP-15C. It provides the "missing" basic operations for manipulating complex numbers in rectangular format, available under the CMPLX menu of the HP-28, as well as with other RPL-based models. (ABS, R->C, R->P, and P->R are already provided by the HP-15C. ARG can be performed by R->P followed by "Im" from this library.)

__Background__: http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv017.cgi?read=124707#124707

There was not enough room on the Voyager-series keyboard and backplate for HP to provide these operations natively as microcoded functions on the HP-15C. However, HP astutely specified that CLx and CHS in complex mode would operate *only on the real-valued part* of a number, ignoring the corresponding value in the parallel imaginary stack. While this can be a "gotcha" for the unwitting user, it enabled standard operations to be performed on complex numbers with only a few instructions.

This 30-line library utilizes labels 0 through 6, one for each function. Each instruction is one byte, so the total library needs four registers plus two bytes. It is designed as a permanent-residence program for users who frequently manipulate complex numbers. (If labels .0 through .6 were used, nine additional bytes would be needed, due to two-byte instructions.)

The labels are selected mnemonically:

- Functions "0" (clear) and "1" (negate) serve in effect to multiply a complex number by 0 and -1 respectively
*without disturbing the stack*, except that "clear" disables stack push.

- Function "2" (conjugate) is a subset of negation.

- Function "3" (signum -- a unit-magnitude number that preserves the sign of each component) is unrelated to the others, but fills the empty slot.

- Functions "4" (C->R decomposition; inverse of "f I"), "5" (extract real value), and "6" (extract imaginary value) are interrelated and combined.

-- Compactness is achieved by using labels as entry points to utilize common overlapping instructions.

-- Each function except "3" uses no extra stack levels. (Function "3" usually pushes the stack one level).

-- No function uses any memory register or flag.

-- Function "4" uses a GSB call to save a few instructions; this will cause an error condition only if it is called within a routine that already has seven pending subroutine calls.

-- Answers will be mathematically correct using real-valued or complex-valued inputs. However, each function will set complex mode, except for Function "3" with a real-valued input.

**FUNCTIONS:**

0 1 2 3 4 5 6

"Clear" "Neg" "Conj" "Signum" "C->R" "Re" "Im"

CLx CHS Re<->Im x=0? ENTER Re<->Im CLx

Re<->Im Re<->Im CHS RTN Re<->Im CLx Re<->Im

CLx CHS Re<->Im ENTER CLx Re<->Im

Re<->Im ABS Re<->Im

/ x<>y

CLx

Re<->Im

**LISTING:**

001- 42,21, 0 LBL 0 "Clear"

002- 43 35 CLx

003- 42 30 Re<->Im

004- 43 35 CLx

005- 43 32 RTN

006- 42,21, 1 LBL 1 "Neg"

007- 16 CHS

008- 42,21, 2 LBL 2 "Conj"

009- 42 30 Re<->Im

010- 16 CHS

011- 42 30 Re<->Im

012- 43 32 RTN

013- 42,21, 3 LBL 3 "Signum"

014- 43 20 x=0?

015- 43 32 RTN

016- 36 ENTER

017- 43 16 ABS

018- 10 /

019- 43 32 RTN

020- 42,21, 4 LBL 4 "C->R"

021- 36 ENTER

022- 32 5 GSB 5

023- 34 x<->y

024- 22 6 GTO 6

025- 42,21, 5 LBL 5 "Re"

026- 42 30 Re<->Im

027- 42,21, 6 LBL 6 "Im"

028- 43 35 CLx

029- 42 30 Re<->Im

030- 43 32 RTN

*Edited: 16 May 2008, 2:23 a.m. after one or more responses were posted*