The Museum of HP Calculators

HP Forum Archive 14

[ Return to Index | Top of Index ]

Quadratic Equation solved in ONE step.
Message #1 Posted by Angel Martin on 30 Nov 2003, 2:49 a.m.

I've seen recent postings referring to solving the quadratic equation on the 41. Here's a solution that only takes ONE program line (of user code, of course :=)

Equation: aX^2 + bX + c = 0

Input: a, b, c in Z, Y, and X of the stack.

Output: - if Z=0, then Y=Im(Z), X=Re(Z) complex roots
- if Z#0, then Y=X1, X=X2 real roots

As expected, no data registers, user flags, or any other dependencies needed. Different acoustic tones will sound depending whether real or complex roots. It is *very* fast.

Hope you enjoy, any comments/improvements are welcome.And if you're not into MCODE, then wait until the new SANDBOX Rom comes out, it will of course have it included (together with Hyperbolics and Complex Arithmetic also as machine code functions).

Best, AM

2A0 SETDEC
0F8 READ 3(X)
2BE C=-C-1 MS
10E A=C ALL
078 READ 1(Z)
261060 ?NC XQ ->1898
128 WRIT 4(L)
078 READ 1(Z)
10E A=C ALL
01D060 ?NC XQ ->1807
10E A=C ALL
0B8 READ 2(Y)
2BE C=-C-1 MS
0AE A<>C ALL
261060 ?NC XQ ->1898
0E8 WRIT 3(X)
10E A=C ALL
135060 ?NC XQ ->184D
10E A=C ALL
138 READ 4(L)
01D060 ?NC XQ ->1807
104 CLRF 8
2FE ?C#0 MS
01B JNC +03
2BE C=-C-1 MS
108 SETF 8
2F9060 ?NC XQ ->18BE
10C ?FSET 8
03B JNC +07
0A8 WRIT 2(Y)
04E C=0 ALL
068 WRIT 1(Z)
130050 LDI S&X CON: 80
083 JNC +10
128 WRIT 4(L)
10E A=C ALL
0F8 READ 3(X)
01D060 ?NC XQ ->1807
0A8 WRIT 2(Y)
138 READ 4(L)
2BE C=-C-1 MS
10E A=C ALL
0F8 READ3(X)
01D060 ?NC XQ ->1807
0E8 WRIT 3(X)
1300C6 LDI S&X CON: 198
358 ST=C XP
379058 ?NC XQ ->16DE
260 SETHEX
3E0 RTN


[ Return to Index | Top of Index ]

Go back to the main exhibit hall