Unnecessary Macros (was Re: Unnecessary Parenthesis)

Robert Firth firth at sei.cmu.edu
Tue Oct 18 03:34:39 AEST 1988


In article <716 at accelerator.eng.ohio-state.edu>, rob at kaa.eng.ohio-state.edu (Rob Carriere) writes:

[The need for a maintainable and efficient way to write things like
   y := sin(x)^2 +1.7
]

I agree fully with Mr Carriere that most of the suggestions for hand
optimising this kind of thing are unworkable.  Scientific programs
typically contain not simple statements like the above, but statements
that run over three or four lines, full of sin(x)^n, sin(x)^(n-1),
2*sin(x-d)*cos(y+d), and so on, and on, and on.  These formulae have
been laboriously copied from a reference book or article, and they
are completely unmaintainable unless they follow as closely as possible
the original form.  In my experience, even something as simple as
multiplying two polynomials and simplifying the result can take an
hour or more to check thoroughly.

Let the compiler do the work, please.  As a corollary: use a language
sufficiently powerful that you can give the compiler enough information
to enable it to do the work.

(Aside: I stuffed the above expression into an Algol-60/Vax compiler,
 and duly got

	MOVF x,R0
	BSBW sin
	MULF2 R0,R0
	ADDF3 #1.7,R0,y
)



More information about the Comp.lang.c mailing list