aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/global.c1
-rw-r--r--src/main.c12
-rw-r--r--src/shell.c.in9
-rw-r--r--src/sqlite.h.in3
-rw-r--r--src/sqliteInt.h1
-rw-r--r--src/test1.c25
-rw-r--r--src/util.c6
7 files changed, 53 insertions, 4 deletions
diff --git a/src/global.c b/src/global.c
index fcba7d7fa..dc765522e 100644
--- a/src/global.c
+++ b/src/global.c
@@ -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 */
diff --git a/src/main.c b/src/main.c
index 7e3fab886..19f65dac6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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)
diff --git a/src/shell.c.in b/src/shell.c.in
index 2b0884e1c..295d405cb 100644
--- a/src/shell.c.in
+++ b/src/shell.c.in
@@ -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;
@@ -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);
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index c5a50c01b..59d9986c5 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -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
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 5662ab4fd..8eae8d166 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -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 */
diff --git a/src/test1.c b/src/test1.c
index 013adcbcb..acae44c8a 100644
--- a/src/test1.c
+++ b/src/test1.c
@@ -7099,6 +7099,30 @@ static int SQLITE_TCLAPI extra_schema_checks(
}
/*
+** 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
**
** Indicate that database files might be corrupt. In other words, set the normal
@@ -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},
diff --git a/src/util.c b/src/util.c
index 7642a29bc..dbf31d30f 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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; }
@@ -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;
}
@@ -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--; }
}
/*