Re: How to redefine arithmetic operators.



In article <438C47D8.5020905@xxxxxxxxxxxxxxxx> jacob navia <jacob@xxxxxxxxxxxxxxxx> writes:
....
> Consider this:
> qfloat a;
> qfloat q = (sqrt(a+1)/sqrt(a-1))*(cos(a+1)/cos(a-1));
>
> compared with:
>
> tmp1 = qadd(a,1);
> tmp2 = sqrtq(tmp1);
> tmp3 = qsub(a,1);
> tmp4 = sqrt(tmp3);
> tmp5 = qdiv(tmp1,tmp3);
> tmp6 = cosq(tmp1);
> tmp7 = cosq(tmp3);
> tmp8 = qdiv(tmp6,tmp7);
> result = qmul(tmp8,tmp5);
>
> This does the *same* stuff but which expression would
> you prefer???

This is obviously a distortion of what is possible, how many of those
tmp's do you really need?
aplus1 = qadd(a, 1);
asub1 = qsub(a, 1);
result = qmul(qdiv(qsqrt(aplus1),qsqrt(asub1)),
qdiv(qcos(aplus1),qcos(asub1)));
which has the added advantage that it is correct.

Does your compiler calculate a+1 and a-1 only once? I have no idea, and
cannot check. I have no access to a win32 machine.
--
*** t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~***/
.


Quantcast