/ Check-in [f607ad27]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Refactor the float-to-double rounding routines so that they compile without warnings.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | rtree-32bit-rounding
Files: files | file ages | folders
SHA1:f607ad27c1ede27af24dbee10ca867c8f7761ee3
User & Date: drh 2012-05-29 00:30:43
Context
2012-05-29
00:39
In the RTree module, make sure all double-to-float conversions round in a direction to increase the size of element bounding boxes. check-in: 0abdc290 user: drh tags: trunk
00:30
Refactor the float-to-double rounding routines so that they compile without warnings. Closed-Leaf check-in: f607ad27 user: drh tags: rtree-32bit-rounding
2012-05-28
20:16
Simplification to the coordinate rounding logic in RTree. check-in: df24072d user: drh tags: rtree-32bit-rounding
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to ext/rtree/rtree.c.

  2735   2735     }else{
  2736   2736       nodeRelease(pRtree, pRoot);
  2737   2737     }
  2738   2738   
  2739   2739     return rc;
  2740   2740   }
  2741   2741   
         2742  +/*
         2743  +** Rounding constants for float->double conversion.
         2744  +*/
         2745  +#define RNDTOWARDS  (1.0 - 1.0/8388608.0)  /* Round towards zero */
         2746  +#define RNDAWAY     (1.0 + 1.0/8388608.0)  /* Round away from zero */
         2747  +
  2742   2748   #if !defined(SQLITE_RTREE_INT_ONLY)
  2743   2749   /*
  2744   2750   ** Convert an sqlite3_value into an RtreeValue (presumably a float)
  2745   2751   ** while taking care to round toward negative or positive, respectively.
  2746   2752   */
  2747   2753   static RtreeValue rtreeValueDown(sqlite3_value *v){
  2748   2754     double d = sqlite3_value_double(v);
  2749   2755     float f = (float)d;
  2750   2756     if( f>d ){
  2751         -    if( f<0.0 ){
  2752         -      f += f/8388608.0;
  2753         -    }else{
  2754         -      f -= f/8388608.0;
  2755         -    }
         2757  +    f = (float)(d*(d<0 ? RNDAWAY : RNDTOWARDS));
  2756   2758     }
  2757   2759     return f;
  2758   2760   }
  2759   2761   static RtreeValue rtreeValueUp(sqlite3_value *v){
  2760   2762     double d = sqlite3_value_double(v);
  2761   2763     float f = (float)d;
  2762   2764     if( f<d ){
  2763         -    if( f<0.0 ){
  2764         -      f -= f/8388608.0;
  2765         -    }else{
  2766         -      f += f/8388608.0;
  2767         -    }
         2765  +    f = (float)(d*(d<0 ? RNDTOWARDS : RNDAWAY));
  2768   2766     }
  2769   2767     return f;
  2770   2768   }
  2771   2769   #endif /* !defined(SQLITE_RTREE_INT_ONLY) */
  2772   2770   
  2773   2771   
  2774   2772   /*