C language hacking

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Fri Nov 16 23:55:00 AEST 1984


>> 	It would also be nice if sin( x ) and cos( x ) could be
>> 	computed simultaneously with reduced cost.  I doubt if this is
>> 	possible but would like to know if it is.

> 	sine = sin(x);
> 	cosine = sqrt(1.0 - sine*sine);

I wish people would check things out before posting them.  On our
4.2BSD system, the sqrt() approach is actually SLOWER than using
cos().  (Under UNIX System V it is very slightly faster.)  Now,
if I wanted cos(x)^2, I would certainly use 1 - sin(x)^2, which
I already knew about (I too went to high school).

What I had in mind was more along the lines of a CORDIC algorithm
or some other obscure but useful approach.



More information about the Comp.lang.c mailing list