sqlite3AtoF()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

sqlite3AtoF()

Cezary H. Noweta
Hello,

Could you consider an exponentiation by squaring (in the main release)
instead of current n-multiplication of exponents? I've observed that an
average time spent in sqlite3AtoF() is greatly reduced by 12% to over
30%, depending on an exponent's magnitude and a compiler. It is nothing
more then 3 lines of code and a noticeable advantage, for example:

======
--- util.c 2017-10-25 02:25:56.000000000 +0200
+++ util-esqr.c 2017-12-25 07:02:20.101110300 +0100
@@ -475,11 +475,12 @@
      if( e==0 ){
/*OPTIMIZATION-IF-TRUE*/
        result = (double)s;
      }else{
-      LONGDOUBLE_TYPE scale = 1.0;
+      LONGDOUBLE_TYPE scale = 1.0, t;
        /* attempt to handle extremely small/large numbers better */
        if( e>307 ){
/*OPTIMIZATION-IF-TRUE*/
          if( e<342 ){
/*OPTIMIZATION-IF-TRUE*/
-          while( e%308 ) { scale *= 1.0e+1; e -= 1; }
+          for ( e -= 308, t = 1.0e+1; 1 < e; e >>= 1, t *= t ) { if ( 1
& e ) scale *= t; }
+          if ( e ) scale *= t;
            if( esign<0 ){
              result = s / scale;
              result /= 1.0e+308;
@@ -499,10 +500,8 @@
            }
          }
        }else{
-        /* 1.0e+22 is the largest power of 10 than can be
-        ** represented exactly. */
-        while( e%22 ) { scale *= 1.0e+1; e -= 1; }
-        while( e>0 ) { scale *= 1.0e+22; e -= 22; }
+        for ( t = 1.0e+1; 1 < e; e >>= 1, t *= t ) { if ( 1 & e ) scale
*= t; }
+        scale *= t;
          if( esign<0 ){
            result = s / scale;
          }else{
======

-- best regards

Cezary H. Noweta
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: sqlite3AtoF()

Richard Hipp-3
On 12/25/17, Cezary H. Noweta <[hidden email]> wrote:
>
> Could you consider an exponentiation by squaring (in the main release)
> instead of current n-multiplication of exponents?

Please test the latest trunk version (or any version after check-in
https://www.sqlite.org/src/timeline?c=fd2e0e7a) and confirm that the
modifications work for you.  Thanks for the suggested algorithm
improvement.

--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: sqlite3AtoF()

Cezary H. Noweta
Hello,

On 2017-12-29 02:25, Richard Hipp wrote:
> Please test the latest trunk version (or any version after check-in
> https://www.sqlite.org/src/timeline?c=fd2e0e7a) and confirm that the
> modifications work for you.

It works as expected. Thank you.

-- best regards

Cezary H. Noweta
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users