FilterFactory - Function "sqr"

Back to function listing

Square root of x

Syntax

sqr(x)

Synonyms

sqrt(x) -- only in Premiere FilterFactory/TransitionFactory
It was added in the Inofficial patch.

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

5B pop ebx (param_x) .
83 FB 01 cmp ebx,$01 (1) .
7E 18 jle +$18 (@@2) if (param_x <= 1) goto @@1; // return param_x
8B CB mov ecx,ebx ecx = param_x;
D1 EB shr ebx,1 param_x /= $10;
B8 02 00 00 00 mov eax,$00000002 (2) eax = 2;
@@1: @@1:
3B D8 cmp ebx,eax .
7E 0B jle +$0b (@@2) if (param_x <= eax) goto @@2;
8B C1 mov eax,ecx eax = ecx;
99 cdq edx = signbit(eax);
F7 F3 div ebx eax /= param_x;
03 D8 add ebx,eax param_x += eax;
D1 EB shr ebx,1 param_x /= $10;
EB F1 jmp -$0f (@@1) goto @@1;
@@2: @@2:
53 push ebx return param_x;

C++ code

int sqr(int x) {
	int ebx = x;
	if (ebx > 1) {
		int ecx = ebx;
		ebx = ebx >> 1;
		int eax = 2;
		while (ebx > eax) {
			eax = ecx;
			eax /= ebx;
			ebx += eax;
			ebx = ebx >> 1;
		}
	}
	return ebx;
}