Update 2 files

- /src/base/ftcalc.c
- /include/freetype/internal/ftcalc.h
This commit is contained in:
Alexei Podtelezhnikov 2023-09-13 17:02:31 +00:00
parent 16f311d725
commit 6eb5f2be40
2 changed files with 17 additions and 24 deletions

View File

@ -509,8 +509,8 @@ FT_BEGIN_HEADER
* @note:
* This function is not very fast.
*/
FT_BASE( FT_Int32 )
FT_SqrtFixed( FT_Int32 x );
FT_BASE( FT_UInt32 )
FT_SqrtFixed( FT_UInt32 x );
#endif /* 0 */

View File

@ -917,36 +917,29 @@
/* documentation is in ftcalc.h */
FT_BASE_DEF( FT_Int32 )
FT_SqrtFixed( FT_Int32 x )
/* Algorithm and code by Christophe Meessen (1993). */
FT_BASE_DEF( FT_UInt32 )
FT_SqrtFixed( FT_UInt32 r )
{
FT_UInt32 root, rem_hi, rem_lo, test_div;
FT_Int count;
FT_UInt32 t, q, b;
root = 0;
q = 0;
if ( x > 0 )
b = 0x40000000;
while ( b > 0x40 )
{
rem_hi = 0;
rem_lo = (FT_UInt32)x;
count = 24;
do
t = q + b;
if ( r >= t )
{
rem_hi = ( rem_hi << 2 ) | ( rem_lo >> 30 );
rem_lo <<= 2;
root <<= 1;
test_div = ( root << 1 ) + 1;
if ( rem_hi >= test_div )
{
rem_hi -= test_div;
root += 1;
}
} while ( --count );
r -= t;
q = t + b; /* equivalent to q += 2*b */
}
r <<= 1;
b >>= 1;
}
return (FT_Int32)root;
return q >> 8;
}
#endif /* 0 */