1
0
mirror of https://github.com/sqlite/sqlite.git synced 2026-01-06 08:01:16 +03:00

Improved rounding even on systems with an 8-byte "long double" type.

FossilOrigin-Name: 15202aee150fa8e15fb90e90e5765c5e19a1eaf4896da2996a747636b76da8e6
This commit is contained in:
drh
2019-05-27 00:29:15 +00:00
parent c2b893a7e0
commit ef7d5187a7
4 changed files with 15 additions and 15 deletions

View File

@@ -527,7 +527,12 @@ void sqlite3_str_vappendf(
rounder = arRound[idx%10];
while( idx>=10 ){ rounder *= 1.0e-10; idx -= 10; }
if( xtype==etFLOAT ){
if( precision<17) rounder += realvalue*2.0e-16;
double rx = (double)realvalue;
sqlite3_uint64 u;
int ex;
memcpy(&u, &rx, sizeof(u));
ex = -1023 + (int)((u>>52)&0x7ff);
if( precision+(ex/3) < 15 ) rounder += realvalue*3e-16;
realvalue += rounder;
}
/* Normalize realvalue to within 10.0 > realvalue >= 1.0 */