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: * @note:
* This function is not very fast. * This function is not very fast.
*/ */
FT_BASE( FT_Int32 ) FT_BASE( FT_UInt32 )
FT_SqrtFixed( FT_Int32 x ); FT_SqrtFixed( FT_UInt32 x );
#endif /* 0 */ #endif /* 0 */

View File

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