diff options
author | drh <> | 2024-10-01 20:29:43 +0000 |
---|---|---|
committer | drh <> | 2024-10-01 20:29:43 +0000 |
commit | e8b2c92240388cad4d41e83a7383b179b7a78acd (patch) | |
tree | 4c0ced6fcb8a22a9d9ebffb563d0d48733271ec1 /src | |
parent | 7151010919cff7ab5134173f5d22fdf534104c34 (diff) | |
download | sqlite-e8b2c92240388cad4d41e83a7383b179b7a78acd.tar.gz sqlite-e8b2c92240388cad4d41e83a7383b179b7a78acd.zip |
Remove all code that makes use of the C-language "long double" datatype.
FossilOrigin-Name: f622b52024c8bec1d241b1dc480fbbd839fc1af50b6220f012812503de2c656e
Diffstat (limited to 'src')
-rw-r--r-- | src/global.c | 1 | ||||
-rw-r--r-- | src/main.c | 56 | ||||
-rw-r--r-- | src/shell.c.in | 16 | ||||
-rw-r--r-- | src/sqlite.h.in | 2 | ||||
-rw-r--r-- | src/sqliteInt.h | 40 | ||||
-rw-r--r-- | src/test1.c | 35 | ||||
-rw-r--r-- | src/test_config.c | 4 | ||||
-rw-r--r-- | src/util.c | 181 | ||||
-rw-r--r-- | src/vdbeaux.c | 13 |
9 files changed, 70 insertions, 278 deletions
diff --git a/src/global.c b/src/global.c index 121b3f6d6..b4864a446 100644 --- a/src/global.c +++ b/src/global.c @@ -243,7 +243,6 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = { SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */ 0, /* bSmallMalloc */ 1, /* bExtraSchemaChecks */ - sizeof(LONGDOUBLE_TYPE)>8, /* bUseLongDouble */ #ifdef SQLITE_DEBUG 0, /* bJsonSelfcheck */ #endif diff --git a/src/main.c b/src/main.c index bd0cbc731..4ed7e08cb 100644 --- a/src/main.c +++ b/src/main.c @@ -159,33 +159,6 @@ char *sqlite3_temp_directory = 0; */ char *sqlite3_data_directory = 0; -#if !defined(SQLITE_OMIT_WSD) && !defined(SQLITE_USE_LONG_DOUBLE) -/* -** Determine whether or not high-precision (long double) floating point -** math works correctly on CPU currently running. -*/ -static SQLITE_NOINLINE int hasHighPrecisionDouble(int rc){ - if( sizeof(LONGDOUBLE_TYPE)<=8 ){ - /* If the size of "long double" is not more than 8, then - ** high-precision math is not possible. */ - return 0; - }else{ - /* Just because sizeof(long double)>8 does not mean that the underlying - ** hardware actually supports high-precision floating point. For example, - ** clearing the 0x100 bit in the floating-point control word on Intel - ** processors will make long double work like double, even though long - ** double takes up more space. The only way to determine if long double - ** actually works is to run an experiment. */ - LONGDOUBLE_TYPE a, b, c; - rc++; - a = 1.0+rc*0.1; - b = 1.0e+18+rc*25.0; - c = a+b; - return b!=c; - } -} -#endif /* !SQLITE_OMIT_WSD && !SQLITE_USE_LONG_DOUBLE */ - /* ** Initialize SQLite. ** @@ -380,11 +353,6 @@ int sqlite3_initialize(void){ rc = SQLITE_EXTRA_INIT(0); } #endif - -#if !defined(SQLITE_OMIT_WSD) && !defined(SQLITE_USE_LONG_DOUBLE) - sqlite3Config.bUseLongDouble = hasHighPrecisionDouble(rc); -#endif - return rc; } @@ -4637,30 +4605,6 @@ int sqlite3_test_control(int op, ...){ break; } -#if !defined(SQLITE_OMIT_WSD) - /* sqlite3_test_control(SQLITE_TESTCTRL_USELONGDOUBLE, int X); - ** - ** X<0 Make no changes to the bUseLongDouble. Just report value. - ** X==0 Disable bUseLongDouble - ** X==1 Enable bUseLongDouble - ** X>=2 Set bUseLongDouble to its default value for this platform - ** - ** If the SQLITE_USE_LONG_DOUBLE compile-time option has been used, then - ** the bUseLongDouble setting is fixed. This test-control becomes a - ** no-op, except that it still reports the fixed setting. - */ - case SQLITE_TESTCTRL_USELONGDOUBLE: { -#if !defined(SQLITE_USE_LONG_DOUBLE) - int b = va_arg(ap, int); - if( b>=2 ) b = hasHighPrecisionDouble(b); - if( b>=0 ) sqlite3Config.bUseLongDouble = b>0; -#endif - rc = SqliteUseLongDouble!=0; - break; - } -#endif - - #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 35b9b089f..140fd0d9d 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -11257,7 +11257,6 @@ 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|\"default\"?"}, }; int testctrl = -1; int iCtrl = -1; @@ -11491,21 +11490,6 @@ static int do_meta_command(char *zLine, ShellState *p){ } break; - /* sqlite3_test_control(int, int) */ - case SQLITE_TESTCTRL_USELONGDOUBLE: { - int opt = -1; - if( nArg==3 ){ - if( cli_strcmp(azArg[2],"default")==0 ){ - opt = 2; - }else{ - opt = booleanValue(azArg[2]); - } - } - 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 72190beec..4fff4b750 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -8368,7 +8368,7 @@ int sqlite3_test_control(int op, ...); #define SQLITE_TESTCTRL_TRACEFLAGS 31 #define SQLITE_TESTCTRL_TUNE 32 #define SQLITE_TESTCTRL_LOGEST 33 -#define SQLITE_TESTCTRL_USELONGDOUBLE 34 +#define SQLITE_TESTCTRL_USELONGDOUBLE 34 /* NOT USED */ #define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */ /* diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 5b166d9a3..2b800abd9 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -660,7 +660,6 @@ # define float sqlite_int64 # define fabs(X) ((X)<0?-(X):(X)) # define sqlite3IsOverflow(X) 0 -# define LONGDOUBLE_TYPE sqlite_int64 # ifndef SQLITE_BIG_DBL # define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50) # endif @@ -835,9 +834,6 @@ # define INT8_TYPE signed char # endif #endif -#ifndef LONGDOUBLE_TYPE -# define LONGDOUBLE_TYPE long double -#endif typedef sqlite_int64 i64; /* 8-byte signed integer */ typedef sqlite_uint64 u64; /* 8-byte unsigned integer */ typedef UINT32_TYPE u32; /* 4-byte unsigned integer */ @@ -4249,41 +4245,6 @@ typedef struct { # define Tuning(X) 0 #endif -/* By default, SQLite will use long double if the long double type -** actually provides higher resolution than double. This use or non-use -** of long double is switchable at run-time by a test-control. Dekker -** algorithms are used for high-precision floating point when long double -** is not available. -** -** Having the run-time option to enable/disable long double support -** causes problems for some compiler tool chains. So the following -** compile-time option is available to permanently enable/disable the use -** of long double. -** -** -DSQLITE_USE_LONG_DOUBLE=0 Omit all use of "long double" from -** the code. Instead, the Dekker algorithm -** is always used when high-precision -** floating point is required. -** -** -DSQLITE_USE_LONG_DOUBLE=1 Always use long double when high -** precision is needed. Never fall back -** to using Dekker algorithms. -** -** If the SQLITE_USE_LONG_DOUBLE macro is not defined, then the determination -** of whether or not to use long double is made at run-time. -*/ -#ifndef SQLITE_USE_LONG_DOUBLE -# define SqliteUseLongDouble sqlite3Config.bUseLongDouble -#elif SQLITE_USE_LONG_DOUBLE+0==1 -# define SqliteUseLongDouble 1 -#elif SQLITE_USE_LONG_DOUBLE+0==0 -# undef LONGDOUBLE_TYPE -# define LONGDOUBLE_TYPE double -# define SqliteUseLongDouble 0 -#else -# error "SQLITE_USE_LONG_DOUBLE should be set to either 0 or 1" -#endif - /* ** Structure containing global configuration data for the SQLite library. ** @@ -4297,7 +4258,6 @@ 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 */ #ifdef SQLITE_DEBUG u8 bJsonSelfcheck; /* Double-check JSON parsing */ #endif diff --git a/src/test1.c b/src/test1.c index 38ea6229e..5af066c6b 100644 --- a/src/test1.c +++ b/src/test1.c @@ -7314,37 +7314,6 @@ static int SQLITE_TCLAPI extra_schema_checks( } /* -** tclcmd: use_long_double BOOLEAN|"default" -** -** If no argument, report the current value of the use-long-double flag. -** -** If argument is "default", set the use-long-double flag to the default -** value for this build, based on the size of LONGDOUBLE_TYPE. -** -** If argument is a boolean, set the use-long-double flag accordingly. -** -** 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( strcmp(Tcl_GetString(objv[1]),"default")==0 ){ - i = 2; - }else{ - 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 @@ -9150,7 +9119,6 @@ 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}, @@ -9299,7 +9267,6 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ #endif }; static int bitmask_size = sizeof(Bitmask)*8; - static int longdouble_size = sizeof(LONGDOUBLE_TYPE); int i; extern int sqlite3_sync_count, sqlite3_fullsync_count; extern int sqlite3_opentemp_count; @@ -9400,8 +9367,6 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ (char*)&sqlite3_data_directory, TCL_LINK_STRING); Tcl_LinkVar(interp, "bitmask_size", (char*)&bitmask_size, TCL_LINK_INT|TCL_LINK_READ_ONLY); - Tcl_LinkVar(interp, "longdouble_size", - (char*)&longdouble_size, TCL_LINK_INT|TCL_LINK_READ_ONLY); Tcl_LinkVar(interp, "sqlite_sync_count", (char*)&sqlite3_sync_count, TCL_LINK_INT); Tcl_LinkVar(interp, "sqlite_fullsync_count", diff --git a/src/test_config.c b/src/test_config.c index 49527861a..ad315c723 100644 --- a/src/test_config.c +++ b/src/test_config.c @@ -512,10 +512,6 @@ static void set_options(Tcl_Interp *interp){ Tcl_SetVar2(interp, "sqlite_options", "lookaside", "1", TCL_GLOBAL_ONLY); #endif -Tcl_SetVar2(interp, "sqlite_options", "long_double", - sizeof(LONGDOUBLE_TYPE)>sizeof(double) ? "1" : "0", - TCL_GLOBAL_ONLY); - #ifdef SQLITE_OMIT_MEMORYDB Tcl_SetVar2(interp, "sqlite_options", "memorydb", "0", TCL_GLOBAL_ONLY); #else diff --git a/src/util.c b/src/util.c index 6725306ed..9ad294016 100644 --- a/src/util.c +++ b/src/util.c @@ -458,7 +458,6 @@ u8 sqlite3StrIHash(const char *z){ return h; } -#if !defined(SQLITE_USE_LONG_DOUBLE) || SQLITE_USE_LONG_DOUBLE+0==0 /* Double-Double multiplication. (x[0],x[1]) *= (y,yy) ** ** Reference: @@ -494,9 +493,6 @@ static void dekkerMul2(volatile double *x, double y, double yy){ x[1] = c - x[0]; x[1] += cc; } -#else -# define dekkerMul2(A,B,C) /* No-op if SqliteUseLongDouble is always true */ -#endif /* ** The string z[] is an text representation of a real number. @@ -543,6 +539,8 @@ int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){ int eValid = 1; /* True exponent is either not used or is well-formed */ int nDigit = 0; /* Number of digits processed */ int eType = 1; /* 1: pure integer, 2+: fractional -1 or less: bad UTF16 */ + double rr[2]; + u64 s2; assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); *pResult = 0.0; /* Default return value, in case of an error */ @@ -654,68 +652,41 @@ do_atof_calc: e++; } - if( e==0 ){ - *pResult = s; - }else if( SqliteUseLongDouble ){ - LONGDOUBLE_TYPE r = (LONGDOUBLE_TYPE)s; - if( e>0 ){ - while( e>=100 ){ e-=100; r *= 1.0e+100L; } - while( e>=10 ){ e-=10; r *= 1.0e+10L; } - while( e>=1 ){ e-=1; r *= 1.0e+01L; } - }else{ - while( e<=-100 ){ e+=100; r *= 1.0e-100L; } - while( e<=-10 ){ e+=10; r *= 1.0e-10L; } - while( e<=-1 ){ e+=1; r *= 1.0e-01L; } - } - assert( r>=0.0 ); - if( r>+1.7976931348623157081452742373e+308L ){ -#ifdef INFINITY - *pResult = +INFINITY; -#else - *pResult = 1.0e308*10.0; + rr[0] = (double)s; + s2 = (u64)rr[0]; +#if defined(_MSC_VER) && _MSC_VER<1700 + if( s2==0x8000000000000000LL ){ s2 = 2*(u64)(0.5*rr[0]); } #endif - }else{ - *pResult = (double)r; + rr[1] = s>=s2 ? (double)(s - s2) : -(double)(s2 - s); + if( e>0 ){ + while( e>=100 ){ + e -= 100; + dekkerMul2(rr, 1.0e+100, -1.5902891109759918046e+83); + } + while( e>=10 ){ + e -= 10; + dekkerMul2(rr, 1.0e+10, 0.0); + } + while( e>=1 ){ + e -= 1; + dekkerMul2(rr, 1.0e+01, 0.0); } }else{ - double rr[2]; - u64 s2; - rr[0] = (double)s; - s2 = (u64)rr[0]; -#if defined(_MSC_VER) && _MSC_VER<1700 - if( s2==0x8000000000000000LL ){ s2 = 2*(u64)(0.5*rr[0]); } -#endif - rr[1] = s>=s2 ? (double)(s - s2) : -(double)(s2 - s); - if( e>0 ){ - while( e>=100 ){ - e -= 100; - dekkerMul2(rr, 1.0e+100, -1.5902891109759918046e+83); - } - while( e>=10 ){ - e -= 10; - dekkerMul2(rr, 1.0e+10, 0.0); - } - while( e>=1 ){ - e -= 1; - dekkerMul2(rr, 1.0e+01, 0.0); - } - }else{ - while( e<=-100 ){ - e += 100; - dekkerMul2(rr, 1.0e-100, -1.99918998026028836196e-117); - } - while( e<=-10 ){ - e += 10; - dekkerMul2(rr, 1.0e-10, -3.6432197315497741579e-27); - } - while( e<=-1 ){ - e += 1; - dekkerMul2(rr, 1.0e-01, -5.5511151231257827021e-18); - } + while( e<=-100 ){ + e += 100; + dekkerMul2(rr, 1.0e-100, -1.99918998026028836196e-117); + } + while( e<=-10 ){ + e += 10; + dekkerMul2(rr, 1.0e-10, -3.6432197315497741579e-27); + } + while( e<=-1 ){ + e += 1; + dekkerMul2(rr, 1.0e-01, -5.5511151231257827021e-18); } - *pResult = rr[0]+rr[1]; - if( sqlite3IsNaN(*pResult) ) *pResult = 1e300*1e300; } + *pResult = rr[0]+rr[1]; + if( sqlite3IsNaN(*pResult) ) *pResult = 1e300*1e300; if( sign<0 ) *pResult = -*pResult; assert( !sqlite3IsNaN(*pResult) ); @@ -1036,9 +1007,10 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){ int i; u64 v; int e, exp = 0; + double rr[2]; + p->isSpecial = 0; p->z = p->zBuf; - assert( mxRound>0 ); /* Convert negative numbers to positive. Deal with Infinity, 0.0, and @@ -1066,62 +1038,45 @@ 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. + ** + ** Use Dekker-style double-double computation to increase the + ** precision. + ** + ** The error terms on constants like 1.0e+100 computed using the + ** decimal extension, for example as follows: + ** + ** SELECT decimal_exp(decimal_sub('1.0e+100',decimal(1.0e+100))); */ - if( SqliteUseLongDouble ){ - LONGDOUBLE_TYPE rr = r; - if( rr>=1.0e+19 ){ - while( rr>=1.0e+119L ){ exp+=100; rr *= 1.0e-100L; } - while( rr>=1.0e+29L ){ exp+=10; rr *= 1.0e-10L; } - while( rr>=1.0e+19L ){ exp++; rr *= 1.0e-1L; } - }else{ - while( rr<1.0e-97L ){ exp-=100; rr *= 1.0e+100L; } - while( rr<1.0e+07L ){ exp-=10; rr *= 1.0e+10L; } - while( rr<1.0e+17L ){ exp--; rr *= 1.0e+1L; } + rr[0] = r; + rr[1] = 0.0; + if( rr[0]>9.223372036854774784e+18 ){ + while( rr[0]>9.223372036854774784e+118 ){ + exp += 100; + dekkerMul2(rr, 1.0e-100, -1.99918998026028836196e-117); + } + while( rr[0]>9.223372036854774784e+28 ){ + exp += 10; + dekkerMul2(rr, 1.0e-10, -3.6432197315497741579e-27); + } + while( rr[0]>9.223372036854774784e+18 ){ + exp += 1; + dekkerMul2(rr, 1.0e-01, -5.5511151231257827021e-18); } - v = (u64)rr; }else{ - /* If high-precision floating point is not available using "long double", - ** then use Dekker-style double-double computation to increase the - ** precision. - ** - ** The error terms on constants like 1.0e+100 computed using the - ** decimal extension, for example as follows: - ** - ** SELECT decimal_exp(decimal_sub('1.0e+100',decimal(1.0e+100))); - */ - double rr[2]; - rr[0] = r; - rr[1] = 0.0; - if( rr[0]>9.223372036854774784e+18 ){ - while( rr[0]>9.223372036854774784e+118 ){ - exp += 100; - dekkerMul2(rr, 1.0e-100, -1.99918998026028836196e-117); - } - while( rr[0]>9.223372036854774784e+28 ){ - exp += 10; - dekkerMul2(rr, 1.0e-10, -3.6432197315497741579e-27); - } - while( rr[0]>9.223372036854774784e+18 ){ - exp += 1; - dekkerMul2(rr, 1.0e-01, -5.5511151231257827021e-18); - } - }else{ - while( rr[0]<9.223372036854774784e-83 ){ - exp -= 100; - dekkerMul2(rr, 1.0e+100, -1.5902891109759918046e+83); - } - while( rr[0]<9.223372036854774784e+07 ){ - exp -= 10; - dekkerMul2(rr, 1.0e+10, 0.0); - } - while( rr[0]<9.22337203685477478e+17 ){ - exp -= 1; - dekkerMul2(rr, 1.0e+01, 0.0); - } + while( rr[0]<9.223372036854774784e-83 ){ + exp -= 100; + dekkerMul2(rr, 1.0e+100, -1.5902891109759918046e+83); + } + while( rr[0]<9.223372036854774784e+07 ){ + exp -= 10; + dekkerMul2(rr, 1.0e+10, 0.0); + } + while( rr[0]<9.22337203685477478e+17 ){ + exp -= 1; + dekkerMul2(rr, 1.0e+01, 0.0); } - v = rr[1]<0.0 ? (u64)rr[0]-(u64)(-rr[1]) : (u64)rr[0]+(u64)rr[1]; } - + v = rr[1]<0.0 ? (u64)rr[0]-(u64)(-rr[1]) : (u64)rr[0]+(u64)rr[1]; /* Extract significant digits. */ i = sizeof(p->zBuf)-1; diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 5ff4ca928..8120536b9 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -4512,13 +4512,9 @@ SQLITE_NOINLINE int sqlite3BlobCompare(const Mem *pB1, const Mem *pB2){ ** We must use separate SQLITE_NOINLINE functions here, since otherwise ** optimizer code movement causes gcov to become very confused. */ -#if (defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)) \ - && (!defined(SQLITE_USE_LONG_DOUBLE) || SQLITE_USE_LONG_DOUBLE+0==0) +#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG) static int SQLITE_NOINLINE doubleLt(double a, double b){ return a<b; } static int SQLITE_NOINLINE doubleEq(double a, double b){ return a==b; } -#else -# define doubleLt(A,B) 1 -# define doubleEq(A,B) 1 #endif /* @@ -4531,13 +4527,6 @@ int sqlite3IntFloatCompare(i64 i, double r){ /* SQLite considers NaN to be a NULL. And all integer values are greater ** than NULL */ return 1; - } - if( SqliteUseLongDouble ){ - LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i; - testcase( x<r ); - testcase( x>r ); - testcase( x==r ); - return (x<r) ? -1 : (x>r); }else{ i64 y; if( r<-9223372036854775808.0 ) return +1; |