**HP 42S/DM 42/Free42: Argument, Real Part, Imaginary Part, and Sign Function**

**Introduction**

The HP 42S* has only one extraction function for complex numbers: ABS (absolute value) by default. To complete the list, here are some programs for ARG (argument), REAL (real part), and IMAG (imaginary part). The three functions take a complex number, in either rectangular or polar form.

Using stack commands and flag checks, I am able to get obtain results without affecting the stack much (although the z and t stacks will have the same value).

Also included is the SIGN (signum) function.

* This applies to the Swiss Micros DM42 (it should work), Free42 from Thomas Oakken, and any other HP 42S emulator apps. The print out is from Free42 (and I also have a physical HP 42S).**HP 42S Program: ARG**

00 { 19-Byte Prgm }

01▸LBL “ARG”

02 COMPLEX

03 X<>Y

04 FC? 73

05 →POL

06 R↑

07 STO ST Y

08 R↓

09 R↓

10 RTN

11 .END.**HP 42S Program: REAL**

00 { 21-Byte Prgm }

01▸LBL “REAL”

02 COMPLEX

03 X<>Y

04 FS? 73

05 →REC

06 X<>Y

07 R↑

08 STO ST Y

09 R↓

10 R↓

11 RTN

12 END

**HP 42S Program: IMAG**

00 { 20-Byte Prgm }

01▸LBL “IMAG”

02 COMPLEX

03 X<>Y

04 FS? 73

05 →REC

06 R↑

07 STO ST Y

08 R↓

09 R↓

10 RTN

11 END

Example – Rectangular Mode:

7+8i (7 [ENTER] 8 [ (shift) ] (COMPLEX) )

XEQ ARG: 48.8141 (Degrees)

XEQ REAL: 7.0000

XEQ IMAG: 8.0000

Example – Polar Mode: (Degrees):

4 ∡ 60 (4 [ENTER] 60 [ (shift) ] (COMPLEX) )

XEQ ARG: 60.0000

XEQ REAL: 2.0000

XEQ IMAG: 3.4641

**HP 42S Program: SIGN**

00 { 15-Byte Prgm }

01▸LBL “SIGN”

02 X=0?

03 RTN

04 ENTER

05 ABS

06 X<>Y

07 ÷

08 RTN

09 END

Example:

-1.4641 XEQ SIGN returns -1

5.525 XEQ SIGN returns 1

0 XEQ SIGN returns 0

Eddie

All original content copyright, © 2011-2018. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. Please contact the author if you have questions.