1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

Determine at start time whether or not the underlying hardware supports

high-precision long double computations.

FossilOrigin-Name: 9a854b919667e0e679a259542b2ee444ee416dbd73ecd9458f6ced35d9d3f264
This commit is contained in:
drh
2023-09-13 20:06:46 +00:00
parent 1eca330a08
commit 5b5d4492f2
4 changed files with 39 additions and 12 deletions

View File

@@ -159,6 +159,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.
**
@@ -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;