diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 28 | ||||
-rw-r--r-- | src/vdbeaux.c | 2 |
2 files changed, 27 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c index d69ebf75b..59f90197f 100644 --- a/src/main.c +++ b/src/main.c @@ -160,6 +160,26 @@ char *sqlite3_temp_directory = 0; char *sqlite3_data_directory = 0; /* +** Determine what the default bUseLongDouble value should be and set it. +*/ +static SQLITE_NOINLINE int hasHighPrecisionDouble(int rc){ + if( sizeof(LONGDOUBLE_TYPE)<=8 ){ + return 0; + }else{ + /* Just because sizeof(long double)>8 does not mean that the underlying + ** hardware actually supports high-precision floating point. Do a test + ** to verify that it really does */ + 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; + } +} + + +/* ** Initialize SQLite. ** ** This routine must be called to initialize the memory allocation, @@ -354,6 +374,10 @@ int sqlite3_initialize(void){ } #endif + /* Experimentally determine if high-precision floating point is + ** available. */ + sqlite3Config.bUseLongDouble = hasHighPrecisionDouble(rc); + return rc; } @@ -4554,11 +4578,11 @@ int sqlite3_test_control(int op, ...){ ** 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 + ** X>=2 Set bUseLongDouble to its default value for this platform */ case SQLITE_TESTCTRL_USELONGDOUBLE: { int b = va_arg(ap, int); - if( b==2 ) b = sizeof(LONGDOUBLE_TYPE)>8; + if( b>=2 ) b = hasHighPrecisionDouble(b); if( b>=0 ) sqlite3Config.bUseLongDouble = b>0; rc = sqlite3Config.bUseLongDouble!=0; break; diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 225c8d12c..106b8073c 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -4467,7 +4467,7 @@ SQLITE_NOINLINE int sqlite3BlobCompare(const Mem *pB1, const Mem *pB2){ ** equal to, or greater than the second (double). */ int sqlite3IntFloatCompare(i64 i, double r){ - if( sizeof(LONGDOUBLE_TYPE)>8 ){ + if( sqlite3Config.bUseLongDouble ){ LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i; testcase( x<r ); testcase( x>r ); |