[comp.lang.c] microoptimization, was Array indexing vs. pointers...

johnl@ima.ima.isc.com (John R. Levine) (10/06/88)

In article <1703@dataio.Data-IO.COM> bright@dataio.Data-IO.COM (Walter Bright) writes:
><<    o	Try very hard to replace divides with other operations, as in:
><<		x / 10
><<	with:
><<		x * .1
>	The result may differ in the last bit of the significand because
>	of this. However, in most cases, that is irrelevant and the
>	multiply will be significantly faster.

Oh, lord.  I hope I never have to use a program with optimizations like this.
Despite some common wisdom floating point results, though approximate, are
well defined. If you're making tweaks to the code please at least make them
tweaks that preserve the semantics.

(The Fortran-77 standard could be interpreted to admit transformations like
this, but that's a separate argument.)
-- 
John R. Levine, IECC, PO Box 349, Cambridge MA 02238-0349, +1 617 492 3869
{ bbn | think | decvax | harvard | yale }!ima!johnl, Levine@YALE.something
Rome fell, Babylon fell, Scarsdale will have its turn.  -G. B. Shaw