> From: Daniel Serpell[SMTP:daniel@ATMLAB.UTFSM.CL] > Sent: Monday, February 02, 2004 4:06 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC:] divide by 10 question > El Fri, Jan 30, 2004 at 05:31:39PM -0500, John N. Power escribio: >> >> Should be: >> >> B = N + (N >> 1); >> for ( i = 0, quotient = 0; i < MAX_ITERS; i++ ) { >> quotient = quotient + (B >> 4); >> B = (B >> 4 ); >> } >> > Note that your routine, as writen, gives bad output for > a number of input data, ie: 10 . . . . > That's the problem with many algorithms that treat > division as multiplication by constants (you are > multiplying by 0.001100110011....), roundolf errors. My original post labelled the code as "pseudo code" and referred the reader to a following paragraph which identified the need for carrying a fractional part. The above post was just a correction to the original program. John Power -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body