(41C 32S): n = a^2 + b

07182021, 05:00 AM
Post: #1




(41C 32S): n = a^2 + b
The following program splits a positive integer n into the sum:
n = a^2 + b This technique is useful, especially with the HP 32S and HP 32SII. Normally, real numbers take up 9.5 bytes of memory on the HP 32S series. Integers 0  100 only consume 1.5 bytes of memory for the original HP 32S and the range is extended to 0  254 for the HP 32SII. When the program terminates, b is on the X stack while a is on the Y stack. Example: 684 Result: Y: 26 X: 8 (26^2 + 8 = 684) HP 41C/Swiss Micros DM41X Program: SQPLUS Code: 01 LBL^T SQPLUS HP 32S and HP 32SII Program: SQPLUS Code: S01 LBL S 

07182021, 06:17 AM
(This post was last modified: 07182021 06:52 AM by C.Ret.)
Post: #2




RE: (41C 32S): n = a^2 + b
Hello,
Interesting decomposition. I have not fully understand why this spare memory since, two registers may be more than one. Also, not clear why you are using the round function RND that need to chance display FIX format in the process. Can we envisage using a simpler version based on INT and stack arithmetic operations ? Such as: Code: 001 LBL "SQY2X And for system like the HP15C and classic that have no stack arithmetic facilities: Code: 01 LBL A Having the decomposition results of n = a² + b in the inverse order in the final registers Y: b and X: a may spare the X<>Y instruction then. EDIT: In this sunny sunday mornig, I was posting this message when by rereading it, a shorter and simpliest version pop up in my awaking brain that use a MOD instruction : Code: 01 LBL "SQYX2" Here the last X<>Y is missing so the final results are in the inverse stack order that was asked : Y: \( b\) X: \(a\) for the initial input \( n = a^2+b \). 

07182021, 09:19 AM
(This post was last modified: 07182021 09:23 AM by JF Garnier.)
Post: #3




RE: (41C 32S): n = a^2 + b
(07182021 05:00 AM)Eddie W. Shore Wrote: This technique is useful, especially with the HP 32S and HP 32SII. Normally, real numbers take up 9.5 bytes of memory on the HP 32S series. Integers 0  100 only consume 1.5 bytes of memory for the original HP 32S and the range is extended to 0  254 for the HP 32SII.I didn't remember that the range was up to 254 for the 32SII. That's perfectly correct of course. Thanks for reminding us. (07182021 06:17 AM)C.Ret Wrote: I have not fully understand why this spare memory since, two registers may be more than one.The 32S/32SII have so little memory that using numeric constants (other than the 0..99 or 0..254) in a program must be avoided. For instance, it is much better to do 12 +/ rather than 12). To enter large constants (e.g. 1000), we have better to do for instance 10 ENTER x^2 * or if speed is not a concern 3 10^x. Quote:EDIT:Unfortunately, the 32S/32SII lack the MOD function. JF 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)