microoptimization, was Array indexing vs. pointers...

John R. Levine johnl at ima.ima.isc.com
Thu Oct 6 13:36:25 AEST 1988


In article <1703 at dataio.Data-IO.COM> bright at 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 at YALE.something
Rome fell, Babylon fell, Scarsdale will have its turn.  -G. B. Shaw



More information about the Comp.lang.c mailing list