Skip to content

Commit

Permalink
Whether or not to use the long-double floating point conversion techn…
Browse files Browse the repository at this point in the history
…ique

is now a test-control setting.

FossilOrigin-Name: 02ae6caff1f7925c696ad263fe78b1036364d24b6373e1baec10d53aafb14a12
  • Loading branch information
drh committed Jul 3, 2023
1 parent 0478d1d commit 1b3c6e7
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 17 deletions.
24 changes: 12 additions & 12 deletions manifest
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
C New\stest\scases\sfor\sfloating-point\sconversions.
D 2023-07-03T12:58:18.851
C Whether\sor\snot\sto\suse\sthe\slong-double\sfloating\spoint\sconversion\stechnique\nis\snow\sa\stest-control\ssetting.
D 2023-07-03T14:56:49.741
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
Expand Down Expand Up @@ -591,7 +591,7 @@ F src/expr.c 8d1656b65e26af3e34f78e947ac423f0d20c214ed25a67486e433bf16ca6b543
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
F src/fkey.c a7fcbf7e66d14dbb73cf49f31489ebf66d0e6006c62b95246924a3bae9f37b36
F src/func.c 6028c160f693bdd018b651b5468a0a8e790f4e01e200796916b2d10a5d3237aa
F src/global.c bd0892ade7289f6e20bff44c07d06371f2ff9b53cea359e7854b9b72f65adc30
F src/global.c a16553245e315ee0cda8f9b0bf744efef9dc99f86e9d77f58975ea58824ded92
F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220
F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6
Expand All @@ -600,7 +600,7 @@ F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276
F src/json.c 14c474fb1249a46eb44e878e2361f36abfe686b134039b0d1883d93d61505b4a
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 176d6b2cb18a6ad73b133db17f6fc351c4d9a2d510deebdb76c22bde9cfd1465
F src/main.c 5fd4b65d61ae6155f36756ed508a39b38b49355b031188961e8d923f43f4bc49
F src/main.c 7bc04e53851c813454b73083e21f84fd8a6d3d32eaa242bb4974eda870e28fef
F src/malloc.c 47b82c5daad557d9b963e3873e99c22570fb470719082c6658bf64e3012f7d23
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c 3bb59158c38e05f6270e761a9f435bf19827a264c13d1631c58b84bdc96d73b2
Expand Down Expand Up @@ -638,16 +638,16 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c 37953a5f36c60bea413c3c04efcd433b6177009f508ef2ace0494728912fe2e9
F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
F src/select.c 3ab1186290a311a8ceed1286c0e286209f7fe97b2d02c7593258004ce295dd88
F src/shell.c.in 2c02c819349de410d63fcc0217763dfe5a42dbe58f2d68046d4ea8a376d12c26
F src/sqlite.h.in 3076d78836b6dac53b3ab0875fc8fd15bca8077aad4d33c85336e05af6aef8c7
F src/shell.c.in e01d7e1d8a6b158320c97c955e1b14763289b82a73e3a155fa8efe0d546f0567
F src/sqlite.h.in f999ef3642f381d69679b2516b430dbcb6c5a2a951b7f5e43dc4751b474a5774
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h da473ce2b3d0ae407a6300c4a164589b9a6bfdbec9462688a8593ff16f3bb6e4
F src/sqliteInt.h 3d4125cc1c38777f307e7d374890f085d09f6e15298e09a4f74919744ec2ad62
F src/sqliteInt.h f6c5470b7db42318a3de1115757e94b76570ad7697ac547823e01f1166756f1d
F src/sqliteLimit.h 33b1c9baba578d34efe7dfdb43193b366111cdf41476b1e82699e14c11ee1fb6
F src/status.c 160c445d7d28c984a0eae38c144f6419311ed3eace59b44ac6dafc20db4af749
F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
F src/tclsqlite.c ecbc3c99c0d0c3ed122a913f143026c26d38d57f33e06bb71185dd5c1efe37cd
F src/test1.c ac81daaee5135d210f926e7d1501d6065d396decac57af94083e677cf7e175bd
F src/test1.c 86099cc02f22069d75b04ae9c105acde0edbce9033d5ac37262bad2e461e6000
F src/test2.c 827446e259a3b7ab949da1542953edda7b5117982576d3e6f1c24a0dd20a5cef
F src/test3.c e5178558c41ff53236ae0271e9acb3d6885a94981d2eb939536ee6474598840e
F src/test4.c 4533b76419e7feb41b40582554663ed3cd77aaa54e135cf76b3205098cd6e664
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 97f9a7a1a22db23984ca3ced12ed666327c17beeaf8481c3325a0c74369060dc
F src/util.c 452f1e5e4a85b7869daf15d9b6468ac754836467004fa04c3419f2bd628eb6ad
F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104
F src/vdbe.c 74282a947234513872a83b0bab1b8c644ece64b3e27b053ef17677c8ff9c81e0
F src/vdbe.h 41485521f68e9437fdb7ec4a90f9d86ab294e9bb8281e33b235915e29122cfc0
Expand Down Expand Up @@ -2042,8 +2042,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 51f492b440728151ce64168d5436ba87ca60d84b89408e47c593fa731355afe4
R 610c019b12f01dbb4053eb803e9a81bd
P 9435ed76cd9bb1be02768b3853a2323834f67bda75d3e3f76f6aa7bd0bade3d7
R c19a4cd19e732c53bd925a8fc2b0f976
U drh
Z 391291e9df52bc2766a8acd3f9c94d15
Z ccc178a785227b10fda86cb46a381790
# 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 @@
9435ed76cd9bb1be02768b3853a2323834f67bda75d3e3f76f6aa7bd0bade3d7
02ae6caff1f7925c696ad263fe78b1036364d24b6373e1baec10d53aafb14a12
1 change: 1 addition & 0 deletions src/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = {
SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
0, /* bSmallMalloc */
1, /* bExtraSchemaChecks */
sizeof(long double)>8, /* bUseLongDouble */
0x7ffffffe, /* mxStrlen */
0, /* neverCorrupt */
SQLITE_DEFAULT_LOOKASIDE, /* szLookaside, nLookaside */
Expand Down
12 changes: 12 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4470,6 +4470,18 @@ int sqlite3_test_control(int op, ...){
break;
}

/* sqlite3_test_control(SQLITE_TESTCTRL_USELONGDOUBLE, int X);
**
** Enable long double usage if X>0. Disable if X==0. No-op if X<0.
** Return the status of long double usage afterwards.
*/
case SQLITE_TESTCTRL_USELONGDOUBLE: {
int b = va_arg(ap, int);
if( b>=0 ) sqlite3Config.bUseLongDouble = b>0;
rc = sqlite3Config.bUseLongDouble!=0;
break;
}


#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_WSD)
/* sqlite3_test_control(SQLITE_TESTCTRL_TUNE, id, *piValue)
Expand Down
9 changes: 9 additions & 0 deletions src/shell.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -10876,6 +10876,7 @@ static int do_meta_command(char *zLine, ShellState *p){
{"seek_count", SQLITE_TESTCTRL_SEEK_COUNT, 0, "" },
{"sorter_mmap", SQLITE_TESTCTRL_SORTER_MMAP, 0, "NMAX" },
{"tune", SQLITE_TESTCTRL_TUNE, 1, "ID VALUE" },
{"uselongdouble", SQLITE_TESTCTRL_USELONGDOUBLE,0,"BOOLEAN" },
};
int testctrl = -1;
int iCtrl = -1;
Expand Down Expand Up @@ -10997,6 +10998,14 @@ static int do_meta_command(char *zLine, ShellState *p){
}
break;

/* sqlite3_test_control(int, int) */
case SQLITE_TESTCTRL_USELONGDOUBLE: {
int opt = nArg==3 ? booleanValue(azArg[2]) : -1;
rc2 = sqlite3_test_control(testctrl, opt);
isOk = 1;
break;
}

/* sqlite3_test_control(sqlite3*) */
case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
rc2 = sqlite3_test_control(testctrl, p->db);
Expand Down
3 changes: 2 additions & 1 deletion src/sqlite.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -8176,7 +8176,8 @@ int sqlite3_test_control(int op, ...);
#define SQLITE_TESTCTRL_TRACEFLAGS 31
#define SQLITE_TESTCTRL_TUNE 32
#define SQLITE_TESTCTRL_LOGEST 33
#define SQLITE_TESTCTRL_LAST 33 /* Largest TESTCTRL */
#define SQLITE_TESTCTRL_USELONGDOUBLE 34
#define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */

/*
** CAPI3REF: SQL Keyword Checking
Expand Down
1 change: 1 addition & 0 deletions src/sqliteInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -4090,6 +4090,7 @@ struct Sqlite3Config {
u8 bUseCis; /* Use covering indices for full-scans */
u8 bSmallMalloc; /* Avoid large memory allocations if true */
u8 bExtraSchemaChecks; /* Verify type,name,tbl_name in schema */
u8 bUseLongDouble; /* Make use of long double */
int mxStrlen; /* Maximum string length */
int neverCorrupt; /* Database is always well-formed */
int szLookaside; /* Default lookaside buffer size */
Expand Down
25 changes: 25 additions & 0 deletions src/test1.c
Original file line number Diff line number Diff line change
Expand Up @@ -7098,6 +7098,30 @@ static int SQLITE_TCLAPI extra_schema_checks(
return TCL_OK;
}

/*
** tclcmd: use_long_double INT
**
** Enable or disable the use of long double. Enable if the argument is
** positive. Disable if the argument is zero. No-op if the argument is
** negative.
**
** Return the new setting.
*/
static int SQLITE_TCLAPI use_long_double(
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int objc, /* Number of arguments */
Tcl_Obj *CONST objv[] /* Command arguments */
){
int i = -1;
if( objc==2 ){
if( Tcl_GetBooleanFromObj(interp,objv[1],&i) ) return TCL_ERROR;
}
i = sqlite3_test_control(SQLITE_TESTCTRL_USELONGDOUBLE, i);
Tcl_SetObjResult(interp, Tcl_NewIntObj(i));
return TCL_OK;
}

/*
** tclcmd: database_may_be_corrupt
**
Expand Down Expand Up @@ -8986,6 +9010,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "reset_prng_state", reset_prng_state, 0 },
{ "prng_seed", prng_seed, 0 },
{ "extra_schema_checks", extra_schema_checks, 0},
{ "use_long_double", use_long_double, 0},
{ "database_never_corrupt", database_never_corrupt, 0},
{ "database_may_be_corrupt", database_may_be_corrupt, 0},
{ "optimization_control", optimization_control,0},
Expand Down
6 changes: 3 additions & 3 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){
/* Multiply r by powers of ten until it lands somewhere in between
** 1.0e+19 and 1.0e+17.
*/
if( sizeof(LONGDOUBLE_TYPE)>8 ){
if( sqlite3Config.bUseLongDouble ){
LONGDOUBLE_TYPE rr = r;
if( rr>=1.0e+19 ){
while( rr>=1.0e+119L ){ exp+=100; rr *= 1.0e-100L; }
Expand Down Expand Up @@ -1049,7 +1049,7 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){
dekkerMul2(r, rr, 1.0e+01, 0.0, &r, &rr);
}
}
v = (u64)(r)+(u64)(rr);
v = rr<0.0 ? (u64)r-(u64)(-rr) : (u64)r+(u64)rr;
}


Expand Down Expand Up @@ -1089,7 +1089,7 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){
}
}
memmove(p->z, &p->z[i+1], p->n);
while( p->n>0 && p->z[p->n-1]=='0' ){ p->n--; }
while( ALWAYS(p->n>0) && p->z[p->n-1]=='0' ){ p->n--; }
}

/*
Expand Down

0 comments on commit 1b3c6e7

Please sign in to comment.