diff options
author | drh <> | 2023-09-13 20:06:46 +0000 |
---|---|---|
committer | drh <> | 2023-09-13 20:06:46 +0000 |
commit | 5b5d4492f2f76e16d32c2328e17c0facbe8440e9 (patch) | |
tree | 6f221228145e11a96127a60c70705c5d29cec513 /src/main.c | |
parent | 1eca330a08e18fd0930491302802141f5ce6298e (diff) | |
download | sqlite-5b5d4492f2f76e16d32c2328e17c0facbe8440e9.tar.gz sqlite-5b5d4492f2f76e16d32c2328e17c0facbe8440e9.zip |
Determine at start time whether or not the underlying hardware supports
high-precision long double computations.
FossilOrigin-Name: 9a854b919667e0e679a259542b2ee444ee416dbd73ecd9458f6ced35d9d3f264
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 28 |
1 files changed, 26 insertions, 2 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; |