Page 1 of 1

acs sin and cos are broken

Posted: Sat Jan 15, 2005 4:10 am
by Jonathan
Andrew Stine stated on irc that he was having trouble with the sin and cos functions of acs. In particular, they seemed to not be returning correct values for certain angle ranges. In sin's case 180 - 360, and for cos 270-360.

I had a quick look at the corresponding code in ZDoom, p_acs.cpp:

Code: Select all

case PCD_SIN:
	STACK(1) = finesine[(STACK(1)<<16)>>ANGLETOFINESHIFT];
	break;
Now I'm not familiar with ZDoom's handling of trig and angles in general, but it looks to me as if the problem is in the shifting of the stack value << 16. STACK(1) is a signed double, so shifting anything above 0x8000 up 16 places will give a negative value, which will then be used as the index to the finesine table, which can't be good.

Posted: Sat Jan 15, 2005 10:04 pm
by randi
Right you are. That should be unsigned math there. Oopsy.