From 30b0ce730354496fe30717b5871165b77c42ac33 Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Mon, 11 Sep 2023 16:34:36 +0000 Subject: [PATCH] src/psaux/psintrp.c (cf2_escSQRT): Improve initial guess. The worst number of iterations decreased from 11 to 5. --- src/psaux/psintrp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/psaux/psintrp.c b/src/psaux/psintrp.c index 6c640eebd..fcd49ee0e 100644 --- a/src/psaux/psintrp.c +++ b/src/psaux/psintrp.c @@ -37,6 +37,7 @@ #include "psft.h" +#include #include #include @@ -2276,9 +2277,8 @@ arg = cf2_stack_popFixed( opStack ); if ( arg > 0 ) { - /* use a start value that doesn't make */ - /* the algorithm's addition overflow */ - FT_Fixed root = arg < 10 ? arg : arg >> 1; + /* initial guess based on the most significant bit */ + FT_Fixed root = 1 << ( ( 17 + FT_MSB( arg ) ) >> 1 ); FT_Fixed new_root;