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/util.c | |
parent | 9ee9444a0adbf8f04081447d70d570f17c1a6e6a (diff) | |
download | sqlite-17c20bb15e5f51e12efd95fd3dc8806f939d8af8.tar.gz sqlite-17c20bb15e5f51e12efd95fd3dc8806f939d8af8.zip |
Improved rounding policy.
FossilOrigin-Name: 6f1122e942b8269552daaf13d647d200d8546ec25f36310d67037c6b58d09976
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 7 |
1 files changed, 4 insertions, 3 deletions
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; |