From: drh Date: Tue, 29 May 2012 00:30:43 +0000 (+0000) Subject: Refactor the float-to-double rounding routines so that they compile without X-Git-Tag: version-3.7.13~20^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0e3037ac36d29df8f3cbe3da4b3f4e54f3b46a3e;p=thirdparty%2Fsqlite.git Refactor the float-to-double rounding routines so that they compile without warnings. FossilOrigin-Name: f607ad27c1ede27af24dbee10ca867c8f7761ee3 --- diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index ca06d8a2f2..66da481e0f 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -2739,6 +2739,12 @@ static int rtreeDeleteRowid(Rtree *pRtree, sqlite3_int64 iDelete){ return rc; } +/* +** Rounding constants for float->double conversion. +*/ +#define RNDTOWARDS (1.0 - 1.0/8388608.0) /* Round towards zero */ +#define RNDAWAY (1.0 + 1.0/8388608.0) /* Round away from zero */ + #if !defined(SQLITE_RTREE_INT_ONLY) /* ** Convert an sqlite3_value into an RtreeValue (presumably a float) @@ -2748,11 +2754,7 @@ static RtreeValue rtreeValueDown(sqlite3_value *v){ double d = sqlite3_value_double(v); float f = (float)d; if( f>d ){ - if( f<0.0 ){ - f += f/8388608.0; - }else{ - f -= f/8388608.0; - } + f = (float)(d*(d<0 ? RNDAWAY : RNDTOWARDS)); } return f; } @@ -2760,11 +2762,7 @@ static RtreeValue rtreeValueUp(sqlite3_value *v){ double d = sqlite3_value_double(v); float f = (float)d; if( f