]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Improvements to the layout and comments for the new round() implementation. round-up-2
authordrh <>
Wed, 12 Jun 2024 10:17:36 +0000 (10:17 +0000)
committerdrh <>
Wed, 12 Jun 2024 10:17:36 +0000 (10:17 +0000)
FossilOrigin-Name: d6b1df1a224e06b1fae3c217c334bc0480fa4d824e4a84d6ea690159382d6e18

manifest
manifest.uuid
src/func.c

index d9476859c766d9dde68355fbb19bbd71957ab280..561651a3d97a34954ad86010a0e670e8aff7851d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Test\scases\sfor\sthe\sround()\sfunction\sfor\svalues\swithin\sone\sepsilon\sof\sthe\s5\nround-up\sthreshold.
-D 2024-06-12T00:30:37.110
+C Improvements\sto\sthe\slayout\sand\scomments\sfor\sthe\snew\sround()\simplementation.
+D 2024-06-12T10:17:36.770
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -708,7 +708,7 @@ F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500
 F src/expr.c af9c9242be0df17280faf36c9810339de9df3d7a64ac8d33a5190a1400086ee5
 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
 F src/fkey.c 852f93c0ef995e0c2b8983059a2b97151c194cc8259e21f5bc2b7ac508348c2a
-F src/func.c a7c6f4af5fa85ece25e5ff3228d182b4928461aaf5e5450e3c6f88767ff01d64
+F src/func.c 36437df3ade81376d188bf5d055caf05247c23b46ac208be4daa8c9c14129fc4
 F src/global.c 61a419dd9e993b9be0f91de4c4ccf322b053eb829868e089f0321dd669be3b90
 F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220
 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
@@ -2196,9 +2196,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 44dd632896e688a7d73707f43261577b237628a587800b94f1b77d3ab0cedc2e
-Q +4a790d3b28685f08bbb722057cd6a97aea08a2b2a6098562c6373fd3b5b7206c
-R 654d15fd5bfaa578239c1ec4318433f9
+P 552b1b106691eddb5b503c94065a1ae08d86a24f573e93fe874c48623dc28b99
+R 9fe3498fb426f55769f36e23c6d85e1b
 U drh
-Z 7012d98fd09019b22f3f917305a9afdf
+Z 84d74ac6bf55702c81bdfdb6de3981f8
 # Remove this line to create a well-formed Fossil manifest.
index cccc17ba9593af5f39c8567658c2f7da5ba21978..2dcc9f0555b20d4b2e7e99fa8c381633ff17eb68 100644 (file)
@@ -1 +1 @@
-552b1b106691eddb5b503c94065a1ae08d86a24f573e93fe874c48623dc28b99
\ No newline at end of file
+d6b1df1a224e06b1fae3c217c334bc0480fa4d824e4a84d6ea690159382d6e18
\ No newline at end of file
index 99949dd44e72382c5c7dbb11761953edb34c3354..ef3d83d6614e7c4dad403c7625ee38ea84ea2120 100644 (file)
@@ -457,6 +457,13 @@ static double sqlite3Round(double x){
 }
 #endif
 
+/*
+** This is the value of the least significant bit of the significand
+** relative to the total magnitude of the number for an IEEE754 binary64.
+** Since the significant is 53 bits, this is pow(2,-52).
+*/
+#define SQLITE_DOUBLE_EPSILON 2.220446049250313080847263336181640625e-16
+
 /*
 ** Implementation of the round() function
 */
@@ -465,13 +472,19 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
   int n = 0;        /* Second argument. Digits to the right of decimal point */
   double r;         /* First argument.  Value to be rounded */
   double rX = 1.0;  /* Scaling factor.  pow(10,n) */
-  double rSgn;      /* Sign of the first first */
-  static const double rTwoPowerMinus52 =  /* pow(2,-52) */
-                           2.220446049250313080847263336181640625e-16;
+  double rSgn;      /* Sign of the first argument */
   assert( argc==1 || argc==2 );
+  if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
+  r = sqlite3_value_double(argv[0]);
+  if( r<0 ){
+    rSgn = -1.0;
+    r = -r;
+  }else{
+    rSgn = 1.0;
+  }
   if( argc==2 ){
-    double rY = 10;
-    int i;
+    double rY = 10.0;   /* Use to compute rX */
+    int i;              /* Loop counter for computing rX */
     if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return;
     n = sqlite3_value_int(argv[1]);
     if( n>30 ) n = 30;
@@ -480,15 +493,7 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
       if( i&1 ) rX *= rY;
     }
   }
-  if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
-  r = sqlite3_value_double(argv[0]);
-  if( r<0 ){
-    rSgn = -1.0;
-    r = -r;
-  }else{
-    rSgn = 1.0;
-  }
-  r = rSgn*sqlite3Round(r*rX + rX*r*rTwoPowerMinus52)/rX;
+  r = rSgn*sqlite3Round(r*rX + rX*r*SQLITE_DOUBLE_EPSILON)/rX;
   sqlite3_result_double(context, r);
 }
 #endif