Skip to content

Commit

Permalink
Improved rounding policy.
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 6f1122e942b8269552daaf13d647d200d8546ec25f36310d67037c6b58d09976
  • Loading branch information
drh committed Jul 1, 2023
1 parent 9ee9444 commit 17c20bb
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
20 changes: 10 additions & 10 deletions manifest
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
C Improved\sresponse\sto\sInfinity\sand\sNaN.\s\sRemove\sthe\stermporary\sfpdecode()\nfunction.
D 2023-07-01T15:23:24.956
C Improved\srounding\spolicy.
D 2023-07-01T17:56:00.664
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
Expand Down Expand Up @@ -590,7 +590,7 @@ F src/delete.c cd5f5cd06ed0b6a882ec1a8c2a0d73b3cecb28479ad19e9931c4706c5e2182be
F src/expr.c 8d1656b65e26af3e34f78e947ac423f0d20c214ed25a67486e433bf16ca6b543
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
F src/fkey.c a7fcbf7e66d14dbb73cf49f31489ebf66d0e6006c62b95246924a3bae9f37b36
F src/func.c 6b4804738b4d869f40625958b476a8f964d3df65b626e72a530d76051863cf32
F src/func.c 02ad65dea00c07db33df86ad649a81a503ac7b8a259e89d00e7a81e16ae9d2d6
F src/global.c bd0892ade7289f6e20bff44c07d06371f2ff9b53cea359e7854b9b72f65adc30
F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220
F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
Expand Down Expand Up @@ -633,7 +633,7 @@ F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00
F src/pragma.c 37b8fb02d090262280c86e1e2654bf59d8dbfbfe8dc6733f2b968a11374c095a
F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7
F src/prepare.c d6c4354f8ea0dc06962fbabc4b68c4471a45276a2918c929be00f9f537f69eb1
F src/printf.c 161c522372d34eccb6fbc75b62c40533559ce3f7816a95854dc17e1fa4b4c0d7
F src/printf.c 1d2d5ba8c2d6446b89ca4afeeb5e99f8c09ca8cfd6947e33493112771ea7532a
F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c 37953a5f36c60bea413c3c04efcd433b6177009f508ef2ace0494728912fe2e9
F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
Expand All @@ -642,7 +642,7 @@ F src/shell.c.in 2c02c819349de410d63fcc0217763dfe5a42dbe58f2d68046d4ea8a376d12c2
F src/sqlite.h.in 3076d78836b6dac53b3ab0875fc8fd15bca8077aad4d33c85336e05af6aef8c7
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h da473ce2b3d0ae407a6300c4a164589b9a6bfdbec9462688a8593ff16f3bb6e4
F src/sqliteInt.h 8c1922b2780624225223fd407f995b04392175d33dfcbbca37fe1f00e1abfd0a
F src/sqliteInt.h 3d4125cc1c38777f307e7d374890f085d09f6e15298e09a4f74919744ec2ad62
F src/sqliteLimit.h 33b1c9baba578d34efe7dfdb43193b366111cdf41476b1e82699e14c11ee1fb6
F src/status.c 160c445d7d28c984a0eae38c144f6419311ed3eace59b44ac6dafc20db4af749
F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
Expand Down Expand Up @@ -705,7 +705,7 @@ F src/trigger.c ad6ab9452715fa9a8075442e15196022275b414b9141b566af8cdb7a1605f2b0
F src/update.c 0aa36561167a7c40d01163238c297297962f31a15a8d742216b3c37cdf25f731
F src/upsert.c 5303dc6c518fa7d4b280ec65170f465c7a70b7ac2b22491598f6d0b4875b3145
F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0
F src/util.c 9cddb6a7b31656609e8585475c30e6148a442273b73bfbb3eaabd56e04f157dd
F src/util.c 87e6762b026cd733312838b0e9b9acb43d3a3c88c5e612e8077a7320c2bc1692
F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104
F src/vdbe.c 74282a947234513872a83b0bab1b8c644ece64b3e27b053ef17677c8ff9c81e0
F src/vdbe.h 41485521f68e9437fdb7ec4a90f9d86ab294e9bb8281e33b235915e29122cfc0
Expand Down Expand Up @@ -1399,7 +1399,7 @@ F test/returningfault.test ae4c4b5e8745813287a359d9ccdb9d5c883c2e68afb18fb076793
F test/rollback.test 06680159bc6746d0f26276e339e3ae2f951c64812468308838e0a3362d911eaa
F test/rollback2.test 3f3a4e20401825017df7e7671e9f31b6de5fae5620c2b9b49917f52f8c160a8f
F test/rollbackfault.test 0e646aeab8840c399cfbfa43daab46fd609cf04a
F test/round1.test 1bb32cf3fc505eed9e86b5e523d07e15d4428189665524587512fbcc85d114bb
F test/round1.test 29c3c9039936ed024d672f003c4d35ee11c14c0acb75c5f7d6188ff16190cfd4
F test/rowallock.test 3f88ec6819489d0b2341c7a7528ae17c053ab7cc
F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81
F test/rowid.test e29025be95baf6b32f0d5edef59a7633028325896a98f1caa8019559ca910350
Expand Down Expand Up @@ -2041,8 +2041,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 1138b8d16edef16d2943d407e289d07d546a14e64c3efa3c94127631e06fafeb
R 9f9cd9357c9913af2aa19cc840191091
P 76ab8ae809a47a66688e2d50c20dc87ce946d82e9ffebb3adda55c451fad07fc
R bac28918fe04cf4bb6c5ec2b0ffa1827
U drh
Z 1a305ec6bce26e8306c1bccf245f209e
Z 6ffcf546adee0eb6c01fe1a8fc34f949
# Remove this line to create a well-formed Fossil manifest.
2 changes: 1 addition & 1 deletion manifest.uuid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
76ab8ae809a47a66688e2d50c20dc87ce946d82e9ffebb3adda55c451fad07fc
6f1122e942b8269552daaf13d647d200d8546ec25f36310d67037c6b58d09976
2 changes: 1 addition & 1 deletion src/func.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
}else if( n==0 ){
r = (double)((sqlite_int64)(r+(r<0?-0.5:+0.5)));
}else{
zBuf = sqlite3_mprintf("%.*f",n,r);
zBuf = sqlite3_mprintf("%!.*f",n,r);
if( zBuf==0 ){
sqlite3_result_error_nomem(context);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ void sqlite3_str_vappendf(
}else{
iRound = precision+1;
}
sqlite3FpDecode(&s, realvalue, iRound);
sqlite3FpDecode(&s, realvalue, iRound, flag_altform2 ? 26 : 16);
if( s.isSpecial ){
if( s.isSpecial==2 ){
bufpt = flag_zeropad ? "null" : "NaN";
Expand Down
2 changes: 1 addition & 1 deletion src/sqliteInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -4610,7 +4610,7 @@ struct FpDecode {
char z[24]; /* Significiant digits */
};

void sqlite3FpDecode(FpDecode*,double,int);
void sqlite3FpDecode(FpDecode*,double,int,int);
char *sqlite3MPrintf(sqlite3*,const char*, ...);
char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
Expand Down
7 changes: 4 additions & 3 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ int sqlite3Atoi(const char *z){
** decimal point if n is negative. No rounding is performed if
** n is zero.
*/
void sqlite3FpDecode(FpDecode *p, double r, int iRound){
void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){
int i;
u64 v;
int e, exp = 0;
Expand Down Expand Up @@ -972,7 +972,7 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound){
while( r>=1.0e+119 ){ exp+=100; r /= 1.0e+100; }
while( r>=1.0e+29 ){ exp+=10; r /= 1.0e+10; }
while( r>=1.0e+19 ){ exp++; r /= 10.0; }
}else if( r<1.0e+17 ){
}else{
while( r<1.0e-97 ){ exp-=100; r *= 1.0e+100; }
while( r<1.0e+07 ){ exp-=10; r *= 1.0e+10; }
while( r<1.0e+17 ){ exp--; r *= 10.0; }
Expand All @@ -991,8 +991,9 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound){
p->iDP++;
}
}
if( iRound>0 && iRound<p->n ){
if( iRound>0 && (iRound<p->n || p->n>mxRound) ){
char *z = &p->z[i+1];
if( iRound>mxRound ) iRound = mxRound;
p->n = iRound;
if( z[iRound]>='5' ){
int j = iRound-1;
Expand Down
4 changes: 2 additions & 2 deletions test/round1.test
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ for {set iTest 1} {$iTest<=50000} {incr iTest} {
set r2 $x1.$x4
set ans [string trimright $r2 0]
if {[string match *. $ans]} {set ans ${ans}0}
do_test $iTest/$n/${r}5=>$ans {
set x [db one "SELECT round(${r}5,$n)"]
do_test $iTest/$n/${r}6=>$ans {
set x [db one "SELECT round(${r}6,$n)"]
} $ans
}

Expand Down

0 comments on commit 17c20bb

Please sign in to comment.