diff options
author | drh <> | 2023-07-01 17:56:00 +0000 |
---|---|---|
committer | drh <> | 2023-07-01 17:56:00 +0000 |
commit | 17c20bb15e5f51e12efd95fd3dc8806f939d8af8 (patch) | |
tree | ecd4c527d8768501cf79a1ef7be406996de46964 /src | |
parent | 9ee9444a0adbf8f04081447d70d570f17c1a6e6a (diff) | |
download | sqlite-17c20bb15e5f51e12efd95fd3dc8806f939d8af8.tar.gz sqlite-17c20bb15e5f51e12efd95fd3dc8806f939d8af8.zip |
Improved rounding policy.
FossilOrigin-Name: 6f1122e942b8269552daaf13d647d200d8546ec25f36310d67037c6b58d09976
Diffstat (limited to 'src')
-rw-r--r-- | src/func.c | 2 | ||||
-rw-r--r-- | src/printf.c | 2 | ||||
-rw-r--r-- | src/sqliteInt.h | 2 | ||||
-rw-r--r-- | src/util.c | 7 |
4 files changed, 7 insertions, 6 deletions
diff --git a/src/func.c b/src/func.c index b24359186..07ada2ef6 100644 --- a/src/func.c +++ b/src/func.c @@ -461,7 +461,7 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ }else if( n==0 ){ r = (double)((sqlite_int64)(r+(r<0?-0.5:+0.5))); }else{ - zBuf = sqlite3_mprintf("%.*f",n,r); + zBuf = sqlite3_mprintf("%!.*f",n,r); if( zBuf==0 ){ sqlite3_result_error_nomem(context); return; diff --git a/src/printf.c b/src/printf.c index 4de06c116..f00ad4cb2 100644 --- a/src/printf.c +++ b/src/printf.c @@ -502,7 +502,7 @@ void sqlite3_str_vappendf( }else{ iRound = precision+1; } - sqlite3FpDecode(&s, realvalue, iRound); + sqlite3FpDecode(&s, realvalue, iRound, flag_altform2 ? 26 : 16); if( s.isSpecial ){ if( s.isSpecial==2 ){ bufpt = flag_zeropad ? "null" : "NaN"; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 011a44bcb..5662ab4fd 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4610,7 +4610,7 @@ struct FpDecode { char z[24]; /* Significiant digits */ }; -void sqlite3FpDecode(FpDecode*,double,int); +void sqlite3FpDecode(FpDecode*,double,int,int); char *sqlite3MPrintf(sqlite3*,const char*, ...); char *sqlite3VMPrintf(sqlite3*,const char*, va_list); #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) diff --git a/src/util.c b/src/util.c index 0950d8427..41359ea2a 100644 --- a/src/util.c +++ b/src/util.c @@ -937,7 +937,7 @@ int sqlite3Atoi(const char *z){ ** decimal point if n is negative. No rounding is performed if ** n is zero. */ -void sqlite3FpDecode(FpDecode *p, double r, int iRound){ +void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){ int i; u64 v; int e, exp = 0; @@ -972,7 +972,7 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound){ while( r>=1.0e+119 ){ exp+=100; r /= 1.0e+100; } while( r>=1.0e+29 ){ exp+=10; r /= 1.0e+10; } while( r>=1.0e+19 ){ exp++; r /= 10.0; } - }else if( r<1.0e+17 ){ + }else{ while( r<1.0e-97 ){ exp-=100; r *= 1.0e+100; } while( r<1.0e+07 ){ exp-=10; r *= 1.0e+10; } while( r<1.0e+17 ){ exp--; r *= 10.0; } @@ -991,8 +991,9 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound){ p->iDP++; } } - if( iRound>0 && iRound<p->n ){ + if( iRound>0 && (iRound<p->n || p->n>mxRound) ){ char *z = &p->z[i+1]; + if( iRound>mxRound ) iRound = mxRound; p->n = iRound; if( z[iRound]>='5' ){ int j = iRound-1; |