Some 30b routines, revisited Message #1 Posted by Harry Jacobson on 11 Oct 2011, 4:13 a.m.
In Some 30b Routines Jeff O presents 10 routines Quote: In the absence of a complete repurposing of the 30b, I decided to come up with a set of key reassignments and/or programs to make the 30b more easily useable (to me, at least) as a scientific calculator. I decided to implement the following functions in the 10 available program slots:
SIN1
COS1
TAN1
Complex add
Complex subtract
Complex multiply
Complex divide
Complex Invert
Polar to Rectangular Conversion
Rectangular to Polar Conversion
Within the message thread program modifications were made so that all programs could have program labels and still fit in the 290 byte program memory of the 30b. Thomas Klemm contributed to the final set of programs.
I wondered if the programs could be shrunk further. Further shrinkage would have no practical purpose since there could be no more than 10 programs therefore no way to use the released program memory. Still, the exercise was enjoyable and successful. The shrunken programs revisited consume 272 bytes of 290 bytes of program memory.
I played with the 30b inverse trig functions sin1, cos1, and tan1. I discovered whether or not the 2nd or final Input is pressed, that when followed by an arithmetic (+, , X, /) or onenumber (x^2, 1/x, e^x, etc.) function the answer is the same. (My calculator's SW version 4 5 2010 1.) The advantage to not pressing the 2nd or final Input is the name of the inverse trig function (sin1, cos1, tan1) remains displayed. This eliminates the need for the 2nd message XXX1 step, a saving of 18 bytes total. Also, I made COS1 and TAN1 callable routines and renumbered labels.
Here are the ten programs, revisited. Programs 3, 4, and 9 are unchanged from the original message thread.
Prgm 0
Program Description: Arc Sine
bytes and checksum: 11.090
Step function comments
0 SH7 assign to shifthold 7
1 message SIN1 Program label
2 Math execute SIN1 function
3 Input execute SIN1 function
4 Down execute SIN1 function
5 Stop
Prgm 1
Program Description: Arc Cosine
bytes and checksum: 14.118
Step function comments
0 SH8 assign to shifthold 8
1 message COS1 Program label
2 Lbl11 Program label for call from R>P routine
3 Math execute COS1 function
4 Input execute COS1 function
5 Up execute COS1 function
6 Up execute COS1 function
7 RTN Return for call
Prgm 2
Program Description: Arc Tangent
bytes and checksum: 13.189
Step function comments
0 SH9 assign to shifthold 9
1 message TAN1 Program label
2 Lbl21 Program label for call from R>P routine
3 Math execute TAN1 function
4 Input execute TAN1 function
5 Up execute TAN1 function
6 RTN Return for call
Prgm 3
Program Description: Add two rectangular form complex numbers
bytes and checksum: 24.218
Step function comments
0 SH+ assign to shifthold +
1 message CPLX+ Program label
2 ) Swap
3 ( Rv Roll down
4 +
5 ( Rv Roll down
6 +
7 ( Rv Roll down
8 ( Rv Roll down
9 ( Rv Roll down
10 message CPLX+ display CPLX+ upon completion
11 Stop
Prgm 4
Program Description: Subtract two rectangular form complex numbers
bytes and checksum: 25.053
Step function comments
0 SH assign to shifthold 
1 message CPLX Program label
2 ) Swap
3 ( Rv Roll down
4 
5 ( Rv Roll down
6 ) Swap
7 
8 ( Rv Roll down
9 ( Rv Roll down
10 ( Rv Roll down
11 message CPLX display CPLX upon completion
12 Stop
Prgm 5
Program Description: Multiply two rectangular form complex numbers
bytes and checksum: 41.251
Step function comments
0 SH* assign to shifthold x
1 message CPLX* Program label
2 Lbl 51 Program label for call from divide routine
3 STO 1
4 ( Rv Roll down
5 STO 2
6 ) Swap
7 STO * 1
8 *
9 ( Rv Roll down
10 STO * 2
11 ) Swap
12 ( Rv Roll down
13 *
14 +
15 RCL 1
16 RCL  2
17 message CPLX* display CPLX* upon completion
18 RTN Return for Call
Prgm 6
Program Description: Divide two rectangular form complex numbers
bytes and checksum: 20.194
Step function comments
0 SH/ assign to shifthold /
1 message CPLX/ Program label
2 Call71 execute complex invert routine
3 Call51 execute complex multiply routine
4 message CPLX/ display CPLX/ upon completion
5 Stop
Prgm 7
Program Description: Invert a rectangular form complex number
bytes and checksum: 47.204
Step function comments
0 NPV assign to the NPV key
1 message CPLX x1 Program label
2 Lbl 71 Program label for call from divide routine
3 STO 1
4 ( Rv Roll down
5 ( Rv Roll down
6 ( Rv Roll down
7 STO 2 Store value that was at top of stack
8 ( Rv Roll down
9 STO * 1
10 ) Swap
11 +/
12 Input
13 x^2
14 RCL + 1
15 /
16 ) Swap
17 Ans
18 /
19 RCL 2
20 ( Rv Roll down
21 message CPLX x1 display CPLX x1 upon completion
22 RTN Return for Call
Prgm 8
Program Description: Rectangular to Polar Conversion
Bytes and checksum: 52.195
Step function comments
0 IRR assign to the IRR key
1 message R>P Program label
2 STO 1 store real component
3 x^2 square real component
4 ) Swap swap squared real component and imaginary component
5 STO 2 store imaginary component
6 x^2 square imaginary component
7 + add squared imaginary component
8 square root take square root to calculate magnitude
9 STO 3 store magnitude
10 Input duplicate magnitude to stack y since GF consumes stack x value
11 GF 82 branch to end if magnitude = 0
12 RCL + 1 add real component: r + x
13 Input duplicate r + x to stack y since GF consumes stack x value
14 GF 81 branch if magnitude + real component = 0
15 RCL 2 imaginary component: y
16 ) Swap swap y and r + x
17 / divide to calculate tangent of halfangle: y / (r + x)
18 Call21 execute TAN1 function
19 Input input TAN1 function
20 Gto 82 branch to end
21 Lbl 81 Routine to handle magnitude + real component = 0 part
22 Call11 execute COS1 function to obtain 180 (or Pi)
23 Input input COS1 function
24 Lbl 82 Label for branch in steps 11 and 20
25 2 enter two
26 * multiply halfangle by 2 to get angle
27 RCL 3 recall magnitude
28 message R>P display R>P upon completion
29 Stop
Prgm 9
Program Description: Polar to Rectangular Conversion
bytes and checksum: 25.058
Step function comments
0 CashFl assign to the CashFl key
1 message P>R Program label
2 STO 1 store magnitude
3 ( Rv Roll down to preserve stack
4 Cos take cosine of angle
5 Ans recall the angle
6 Sin take sine of angle
7 RCL * 1 calculate imaginary component
8 ) Swap
9 RCL * 1 calculate real component
10 message P>R display P>R upon completion
11 Stop
Edited: 11 Oct 2011, 4:29 a.m.
