Another way (How not to write a loop)

Rahul Dhesi dhesi at bsu-cs.UUCP
Fri Feb 19 03:27:59 AEST 1988


>> >	Floating point numbers should never be used for counting.

>> Never say never....At least one
>> widely-used implementation of Snobol4 successfully uses a floating
>> point register to count the number of statements executed...

>We have a misunderstanding of the word "should", apparently.

There might be confusion between "should not" and "should never".
Floating point numbers should not be used for counting except when such
use gains us a remarkable degree of badly-needed efficiency.  In the
Snobol (actually SPITBOL) example, the choice was between the
equivalents of the following:

     count -=1;		/* integer arithmetic with software test */
     if (count == 0)
	abort_program;

and

     count +=x;	/* fast hardware floating add */
     /* actually   AUR   SCNT,SINC  on IBM 360 */

Note that the language required one or the other of the above to
be done before every statement executed.
-- 
Rahul Dhesi         UUCP:  <backbones>!{iuvax,pur-ee,uunet}!bsu-cs!dhesi



More information about the Comp.lang.c mailing list