Unnecessary Macros (was Re: Unnecessary Parenthesis)
Rob Carriere
rob at kaa.eng.ohio-state.edu
Thu Oct 6 08:42:32 AEST 1988
In article <8629 at smoke.ARPA> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>In article <701 at accelerator.eng.ohio-state.edu> rob at kaa.eng.ohio-state.edu
>(Rob Carriere) writes:
>>In article <8590 at smoke.ARPA> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>>>One wonders whether [the inability to define a square macro] is much of a
>>>problem.
>>How about the following, deep in some inner loop:
>>foo = square( sin( x )) + 1.7;
>
>Another silly example. I can't imagine a real algorithm that would want
>this computation in it.
If you leave off the ``+1.7'' that was there for decoration anyway,
try an FFT.
>Most programmers wouldn't have any trouble with
> foo = sin(x);
> foo = foo*foo + 1.7;
>
>I agree that an exponentiation operator would be handy,
>but a "square" macro doesn't seem to help readability.
1) If you have a text in front of you that says sin(x)^2 + 1.7 (LaTeX
notation, not C), then there *is* a problem with the temporary: you
have to go back and check it every time you read the statement. If
the sin(x) gets more complicated, this just about destroys
readability (I've had cases where it took pencil, paper and five
minutes of algebra to verify that all the temporaries did what they
were supposed to do -- not my definition of high readability)
2) I used the ``square'' macro, because that was the original example.
I agree that what is needed is a way of doing small integer powers
in general, but that just changes the problem to: why can't I write
power( sin(x), 2 ) [1] or some such.
Rob Carriere
[1] not pow( sin(x), 2). I want something that will become 1
evalution of sin(x) and 1 multiply.
More information about the Comp.lang.c
mailing list