/ Check-in [0abdc290]
Login

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

Overview
Comment:In the RTree module, make sure all double-to-float conversions round in a direction to increase the size of element bounding boxes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0abdc2903d8b3f86cad426e1bac2a959d1b1f7dd
User & Date: drh 2012-05-29 00:39:50
Context
2012-05-29
17:02
Changes some NDEBUG macros to SQLITE_DEBUG in os_unix.c. The is a notational change only and really should not effect the code. check-in: 8e302570 user: drh tags: trunk
00:48
Merge the 64-to-32-bit RTree rounding fixes from trunk into the sessions branch. check-in: 7eff45c2 user: drh tags: sessions
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:22
Fix the MSVC makefile so that it works with the unicode61 tokenizer. check-in: 48015814 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/rtree/rtree.c.

  2734   2734       rc = nodeRelease(pRtree, pRoot);
  2735   2735     }else{
  2736   2736       nodeRelease(pRtree, pRoot);
  2737   2737     }
  2738   2738   
  2739   2739     return rc;
  2740   2740   }
         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  +
         2748  +#if !defined(SQLITE_RTREE_INT_ONLY)
         2749  +/*
         2750  +** Convert an sqlite3_value into an RtreeValue (presumably a float)
         2751  +** while taking care to round toward negative or positive, respectively.
         2752  +*/
         2753  +static RtreeValue rtreeValueDown(sqlite3_value *v){
         2754  +  double d = sqlite3_value_double(v);
         2755  +  float f = (float)d;
         2756  +  if( f>d ){
         2757  +    f = (float)(d*(d<0 ? RNDAWAY : RNDTOWARDS));
         2758  +  }
         2759  +  return f;
         2760  +}
         2761  +static RtreeValue rtreeValueUp(sqlite3_value *v){
         2762  +  double d = sqlite3_value_double(v);
         2763  +  float f = (float)d;
         2764  +  if( f<d ){
         2765  +    f = (float)(d*(d<0 ? RNDTOWARDS : RNDAWAY));
         2766  +  }
         2767  +  return f;
         2768  +}
         2769  +#endif /* !defined(SQLITE_RTREE_INT_ONLY) */
         2770  +
  2741   2771   
  2742   2772   /*
  2743   2773   ** The xUpdate method for rtree module virtual tables.
  2744   2774   */
  2745   2775   static int rtreeUpdate(
  2746   2776     sqlite3_vtab *pVtab, 
  2747   2777     int nData, 
................................................................................
  2771   2801       int ii;
  2772   2802   
  2773   2803       /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
  2774   2804       assert( nData==(pRtree->nDim*2 + 3) );
  2775   2805   #ifndef SQLITE_RTREE_INT_ONLY
  2776   2806       if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
  2777   2807         for(ii=0; ii<(pRtree->nDim*2); ii+=2){
  2778         -        cell.aCoord[ii].f = (RtreeValue)sqlite3_value_double(azData[ii+3]);
  2779         -        cell.aCoord[ii+1].f = (RtreeValue)sqlite3_value_double(azData[ii+4]);
         2808  +        cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
         2809  +        cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]);
  2780   2810           if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
  2781   2811             rc = SQLITE_CONSTRAINT;
  2782   2812             goto constraint;
  2783   2813           }
  2784   2814         }
  2785   2815       }else
  2786   2816   #endif