diff --git a/include/freetype/internal/ftcalc.h b/include/freetype/internal/ftcalc.h index d9aea2360..fa5e4050f 100644 --- a/include/freetype/internal/ftcalc.h +++ b/include/freetype/internal/ftcalc.h @@ -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 */ diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c index c5bc7e3b1..ba4d5e3fd 100644 --- a/src/base/ftcalc.c +++ b/src/base/ftcalc.c @@ -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 */