The Museum of HP Calculators

HP Forum Archive 20

[ Return to Index | Top of Index ]

34S SUM PROD change request ccccc >= fff
Message #1 Posted by Egan Ford on 1 Oct 2011, 11:53 a.m.

Could you please change "ccccc > fff" to "ccccc >= fff" so that ccccc can count down to and include 0.

Thanks.

      
Re: 34S SUM PROD change request ccccc >= fff
Message #2 Posted by Paul Dale on 1 Oct 2011, 8:14 p.m.,
in response to message #1 by Egan Ford

This is somewhat limited by the definition of DSE unfortunately.

Here is the sum and product code as it currently exists in the firmware image. It is just a plain old keystroke program. Feel free to submit a patch :-)

The stack will always be four levels deep when this code is run and registers 0-4 and flags 0-14 are freely available.

Then again, I could look into adding DSL and ISE as instructions.

- Pauli

/**************************************************************************/
/* Sigma and products
 * Register use:
 * 0	I
 * 1	product/sum
 * 2	carry for sum
 * 3	saved I
 */
		LBL 99					/* Entry: SUMMATION */
			XEQ entry
			SPEC?
				JMP sum_product_okay
			STO 00
			STO 03				/* Save for LastX*/
			IP				/* First function call is separate*/
			FILL				/* to avoid Kahan summing from zero*/
			XEQUSR				/* six extra instructions save nine*/
			SPEC?				/* from executing*/
				JMP sum_product_nan
			STO 01
			iC 0
			STO 02
			JMP sum_entry

sum_loop:: RCL 00 IP FILL XEQUSR SPEC? JMP sum_product_nan RCL- 02 ENTER[^] RCL+ 01 ENTER[^] RCL- 01 RCL- Z x[<->]y [cmplx]STO 01

sum_entry:: DSE 00 JMP sum_loop JMP sum_product_okay

LBL 98 /* Entry: PRODUCT */ XEQ entry SPEC? JMP sum_product_okay STO 00 STO 03 IP /* First function call is separate*/ FILL /* to avoid a multiply*/ XEQUSR SPEC? JMP sum_product_nan STO 01 JMP product_entry

product_loop:: RCL 00 IP FILL XEQUSR SPEC? JMP sum_product_nan STO[times] 01 product_entry:: DSE 00 JMP product_loop

sum_product_okay:: RCL 03 STO L iC 0 FILL RCL 01 JMP exit

sum_product_nan:: RCL 03

sum_product_error:: STO L iC 0 FILL # NaN JMP exit

            
Re: 34S SUM PROD change request ccccc >= fff
Message #3 Posted by Paul Dale on 1 Oct 2011, 10:58 p.m.,
in response to message #2 by Paul Dale

DSL and ISE are now present :-)

- Pauli

                  
Re: 34S SUM PROD change request ccccc >= fff
Message #4 Posted by Walter B on 2 Oct 2011, 2:37 a.m.,
in response to message #3 by Paul Dale

... and documented in the manual :-)

Walter

            
Re: 34S SUM PROD change request ccccc >= fff
Message #5 Posted by Marcus von Cube, Germany on 2 Oct 2011, 6:39 a.m.,
in response to message #2 by Paul Dale

Pauli, what is the reasoning behind the complicated summation. It must have to do with increasing accuracy but how does it work?

If you want to make the code shorter, the two loops may easily be merged and the operation selected by a flag inside the loop.

                  
Re: 34S SUM PROD change request ccccc >= fff
Message #6 Posted by Paul Dale on 2 Oct 2011, 7:47 a.m.,
in response to message #5 by Marcus von Cube, Germany

The summation is indeed an attempt to improve precision. The algorithm used is known as the Kahan sum.

Essentially, it maintains the sum and some of the digits lost off the end in two registers. The lost digits act as a correction term as each new item is added in.

Yes, the two loops could be merged. I didn't investigate this option since neither is very large.

- Pauli

                        
Re: 34S SUM PROD change request ccccc >= fff
Message #7 Posted by Marcus von Cube, Germany on 2 Oct 2011, 8:06 a.m.,
in response to message #6 by Paul Dale

We will certainly be fighting for a handful of bytes again...


[ Return to Index | Top of Index ]

Go back to the main exhibit hall