コード例 #1
0
hsFract hsFracSqrt(hsFract value)
{
	UInt32	curr = 0;
	UInt32	root = 0;
	int		bits = 31;

	do {
		curr = (curr << 2) | TOP2BITS(value);
		value <<= 2;
		UInt32 guess = root << 2;
		root <<= 1;
		if (guess < curr)
		{	curr -= guess + 1;
			root |= 1;
		}
	} while (--bits);

	return root;
}
コード例 #2
0
UInt16 hsSqrt32(UInt32 value)
{
	UInt32	curr = 0;
	UInt32	root = 0;
	int		bits = 16;

	do {
		curr = (curr << 2) | TOP2BITS(value);
		value <<= 2;
		UInt32 guess = root << 2;
		root <<= 1;
		if (guess < curr)
		{	curr -= guess + 1;
			root |= 1;
		}
	} while (--bits);

	return UInt16(root);
}
コード例 #3
0
void usqrt(unsigned long x, struct int_sqrt *q)
{
	unsigned long a = 0L;			/* accumulator */
	unsigned long r = 0L;                   /* remainder */
	unsigned long e = 0L;                   /* trial product */

	int i;

	for (i = 0; i < BITSPERLONG; i++)	/* NOTE 1 */
	{
		r = (r << 2) + TOP2BITS(x); x <<= 2; /* NOTE 2 */
		a <<= 1;
		e = (a << 1) + 1;
		if (r >= e)
		{
			r -= e;
			a++;
		}
	}
	memcpy(q, &a, sizeof(long));
}
コード例 #4
0
ファイル: main.c プロジェクト: jgericke/RCE
void
US (unsigned long x, struct int_sqrt *q) 
{
  unsigned long a = 0L;
  unsigned long r = 0L;
  unsigned long e = 0L;
  int i;
  for (i = 0; i < BITSPERLONG; i++)	/* NOTE 1 */
    
    {
      r = (r << 2) + TOP2BITS (x);
      x <<= 2;			/* NOTE 2 */
      a <<= 1;
      e = (a << 1) + 1;
      if (r >= e)
	
	{
	  r -= e;
	  a++;
	}
    }
  memcpy (q, &a, sizeof (long));
} double