Filter Factory - Function "cos"

Back to function listing

Cosine function of x, where x is an integer between 0 and 1024, inclusive, and the value returned is an integer between -512 and 512, inclusive (Windows) or -1024 and 1024, inclusive (Mac OS)

Click here for a diagram of sin, cos, tan

Syntax

cos(x)

Original Machine Code (in OPER resource) of Filter Factory 3.0 and 3.0.4 for Photoshop/Win32

58 pop eax (param_x)
8B D8 mov ebx,eax
C1 FB 1F sar ebx,$1f (31)
33 C3 xor eax,ebx
2B C3 sub eax,ebx
25 FF 03 00 00 and eax,$000003ff (1023)
0F BF 84 47 78 05 00 00 movsx eax,[edi+eax*2+$00000578] (COS_LOOKUP)
C1 F8 05 sar eax,$05 (5)
50 push eax

C++ code

int factory_cos(int parm) {
	int res;
	if (parm < 0) parm = -parm;
	parm &= 0x3ff; // 1023
	res = COS_LOOKUP[parm];
	return res >= 0 ? (res / 32) : res / 32 - 1;
}