home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
RISC DISC 3
/
RISC_DISC_3.iso
/
resources
/
etexts
/
gems
/
gemsv
/
ch1_3
/
fixsqrt.c
Wrap
Text File
|
1995-03-04
|
855b
|
28 lines
/* The definitions below yield 2 integer bits, 30 fractional bits */
#define FRACBITS 30 /* Must be even! */
#define ITERS (15 + (FRACBITS >> 1))
typedef long TFract;
TFract
FFracSqrt(TFract x)
{
register unsigned long root, remHi, remLo, testDiv, count;
root = 0; /* Clear root */
remHi = 0; /* Clear high part of partial remainder */
remLo = x; /* Get argument into low part of partial remainder */
count = ITERS; /* Load loop counter */
do {
remHi = (remHi << 2) | (remLo >> 30); remLo <<= 2; /* get 2 bits of arg */
root <<= 1; /* Get ready for the next bit in the root */
testDiv = (root << 1) + 1; /* Test radical */
if (remHi >= testDiv) {
remHi -= testDiv;
root += 1;
}
} while (count-- != 0);
return(root);
}