@@ -55,7 +55,7 @@ rt_box_union(BOX *n, const BOX *a, const BOX *b)
5555 * Size of a BOX for penalty-calculation purposes.
5656 * The result can be +Infinity, but not NaN.
5757 */
58- static double
58+ static float8
5959size_box (const BOX * box )
6060{
6161/*
@@ -76,20 +76,21 @@ size_box(const BOX *box)
7676 */
7777if (isnan (box -> high .x )|| isnan (box -> high .y ))
7878return get_float8_infinity ();
79- return (box -> high .x - box -> low .x )* (box -> high .y - box -> low .y );
79+ return float8_mul (float8_mi (box -> high .x ,box -> low .x ),
80+ float8_mi (box -> high .y ,box -> low .y ));
8081}
8182
8283/*
8384 * Return amount by which the union of the two boxes is larger than
8485 * the original BOX's area. The result can be +Infinity, but not NaN.
8586 */
86- static double
87+ static float8
8788box_penalty (const BOX * original ,const BOX * new )
8889{
8990BOX unionbox ;
9091
9192rt_box_union (& unionbox ,original ,new );
92- return size_box (& unionbox )- size_box (original );
93+ return float8_mi ( size_box (& unionbox ), size_box (original ) );
9394}
9495
9596/*
@@ -263,7 +264,7 @@ typedef struct
263264/* Index of entry in the initial array */
264265int index ;
265266/* Delta between penalties of entry insertion into different groups */
266- double delta ;
267+ float8 delta ;
267268}CommonEntry ;
268269
269270/*
@@ -279,13 +280,13 @@ typedef struct
279280
280281bool first ;/* true if no split was selected yet */
281282
282- double leftUpper ;/* upper bound of left interval */
283- double rightLower ;/* lower bound of right interval */
283+ float8 leftUpper ;/* upper bound of left interval */
284+ float8 rightLower ;/* lower bound of right interval */
284285
285286float4 ratio ;
286287float4 overlap ;
287288int dim ;/* axis of this split */
288- double range ;/* width of general MBR projection to the
289+ float8 range ;/* width of general MBR projection to the
289290 * selected axis */
290291}ConsiderSplitContext ;
291292
@@ -294,7 +295,7 @@ typedef struct
294295 */
295296typedef struct
296297{
297- double lower ,
298+ float8 lower ,
298299upper ;
299300}SplitInterval ;
300301
@@ -304,7 +305,7 @@ typedef struct
304305static int
305306interval_cmp_lower (const void * i1 ,const void * i2 )
306307{
307- double lower1 = ((const SplitInterval * )i1 )-> lower ,
308+ float8 lower1 = ((const SplitInterval * )i1 )-> lower ,
308309lower2 = ((const SplitInterval * )i2 )-> lower ;
309310
310311return float8_cmp_internal (lower1 ,lower2 );
@@ -316,7 +317,7 @@ interval_cmp_lower(const void *i1, const void *i2)
316317static int
317318interval_cmp_upper (const void * i1 ,const void * i2 )
318319{
319- double upper1 = ((const SplitInterval * )i1 )-> upper ,
320+ float8 upper1 = ((const SplitInterval * )i1 )-> upper ,
320321upper2 = ((const SplitInterval * )i2 )-> upper ;
321322
322323return float8_cmp_internal (upper1 ,upper2 );
@@ -339,14 +340,14 @@ non_negative(float val)
339340 */
340341static inline void
341342g_box_consider_split (ConsiderSplitContext * context ,int dimNum ,
342- double rightLower ,int minLeftCount ,
343- double leftUpper ,int maxLeftCount )
343+ float8 rightLower ,int minLeftCount ,
344+ float8 leftUpper ,int maxLeftCount )
344345{
345346int leftCount ,
346347rightCount ;
347348float4 ratio ,
348349overlap ;
349- double range ;
350+ float8 range ;
350351
351352/*
352353 * Calculate entries distribution ratio assuming most uniform distribution
@@ -369,8 +370,7 @@ g_box_consider_split(ConsiderSplitContext *context, int dimNum,
369370 * Ratio of split - quotient between size of lesser group and total
370371 * entries count.
371372 */
372- ratio = ((float4 )Min (leftCount ,rightCount )) /
373- ((float4 )context -> entriesCount );
373+ ratio = float4_div (Min (leftCount ,rightCount ),context -> entriesCount );
374374
375375if (ratio > LIMIT_RATIO )
376376{
@@ -384,11 +384,13 @@ g_box_consider_split(ConsiderSplitContext *context, int dimNum,
384384 * or less range with same overlap.
385385 */
386386if (dimNum == 0 )
387- range = context -> boundingBox .high .x - context -> boundingBox .low .x ;
387+ range = float8_mi (context -> boundingBox .high .x ,
388+ context -> boundingBox .low .x );
388389else
389- range = context -> boundingBox .high .y - context -> boundingBox .low .y ;
390+ range = float8_mi (context -> boundingBox .high .y ,
391+ context -> boundingBox .low .y );
390392
391- overlap = ( leftUpper - rightLower ) / range ;
393+ overlap = float8_div ( float8_mi ( leftUpper , rightLower ), range ) ;
392394
393395/* If there is no previous selection, select this */
394396if (context -> first )
@@ -444,20 +446,14 @@ g_box_consider_split(ConsiderSplitContext *context, int dimNum,
444446
445447/*
446448 * Compare common entries by their deltas.
447- * (We assume the deltas can't be NaN.)
448449 */
449450static int
450451common_entry_cmp (const void * i1 ,const void * i2 )
451452{
452- double delta1 = ((const CommonEntry * )i1 )-> delta ,
453+ float8 delta1 = ((const CommonEntry * )i1 )-> delta ,
453454delta2 = ((const CommonEntry * )i2 )-> delta ;
454455
455- if (delta1 < delta2 )
456- return -1 ;
457- else if (delta1 > delta2 )
458- return 1 ;
459- else
460- return 0 ;
456+ return float8_cmp_internal (delta1 ,delta2 );
461457}
462458
463459/*
@@ -531,7 +527,7 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
531527context .first = true;/* nothing selected yet */
532528for (dim = 0 ;dim < 2 ;dim ++ )
533529{
534- double leftUpper ,
530+ float8 leftUpper ,
535531rightLower ;
536532int i1 ,
537533i2 ;
@@ -728,7 +724,7 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
728724 */
729725for (i = FirstOffsetNumber ;i <=maxoff ;i = OffsetNumberNext (i ))
730726{
731- double lower ,
727+ float8 lower ,
732728upper ;
733729
734730/*
@@ -783,7 +779,7 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
783779 * Calculate minimum number of entries that must be placed in both
784780 * groups, to reach LIMIT_RATIO.
785781 */
786- int m = ceil (LIMIT_RATIO * ( double ) nentries );
782+ int m = ceil (LIMIT_RATIO * nentries );
787783
788784/*
789785 * Calculate delta between penalties of join "common entries" to
@@ -792,8 +788,8 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
792788for (i = 0 ;i < commonEntriesCount ;i ++ )
793789{
794790box = DatumGetBoxP (entryvec -> vector [commonEntries [i ].index ].key );
795- commonEntries [i ].delta = Abs (box_penalty (leftBox ,box )-
796- box_penalty (rightBox ,box ));
791+ commonEntries [i ].delta = Abs (float8_mi ( box_penalty (leftBox ,box ),
792+ box_penalty (rightBox ,box ) ));
797793}
798794
799795/*
@@ -1107,10 +1103,10 @@ gist_circle_compress(PG_FUNCTION_ARGS)
11071103BOX * r ;
11081104
11091105r = (BOX * )palloc (sizeof (BOX ));
1110- r -> high .x = in -> center .x + in -> radius ;
1111- r -> low .x = in -> center .x - in -> radius ;
1112- r -> high .y = in -> center .y + in -> radius ;
1113- r -> low .y = in -> center .y - in -> radius ;
1106+ r -> high .x = float8_pl ( in -> center .x , in -> radius ) ;
1107+ r -> low .x = float8_mi ( in -> center .x , in -> radius ) ;
1108+ r -> high .y = float8_pl ( in -> center .y , in -> radius ) ;
1109+ r -> low .y = float8_mi ( in -> center .y , in -> radius ) ;
11141110
11151111retval = (GISTENTRY * )palloc (sizeof (GISTENTRY ));
11161112gistentryinit (* retval ,PointerGetDatum (r ),
@@ -1148,10 +1144,10 @@ gist_circle_consistent(PG_FUNCTION_ARGS)
11481144 * rtree_internal_consistent even at leaf nodes. (This works in part
11491145 * because the index entries are bounding boxes not circles.)
11501146 */
1151- bbox .high .x = query -> center .x + query -> radius ;
1152- bbox .low .x = query -> center .x - query -> radius ;
1153- bbox .high .y = query -> center .y + query -> radius ;
1154- bbox .low .y = query -> center .y - query -> radius ;
1147+ bbox .high .x = float8_pl ( query -> center .x , query -> radius ) ;
1148+ bbox .low .x = float8_mi ( query -> center .x , query -> radius ) ;
1149+ bbox .high .y = float8_pl ( query -> center .y , query -> radius ) ;
1150+ bbox .low .y = float8_mi ( query -> center .y , query -> radius ) ;
11551151
11561152result = rtree_internal_consistent (DatumGetBoxP (entry -> key ),
11571153& bbox ,strategy );
@@ -1216,10 +1212,10 @@ gist_point_fetch(PG_FUNCTION_ARGS)
12161212DatumGetFloat8(DirectFunctionCall2(point_distance, \
12171213 PointPGetDatum(p1), PointPGetDatum(p2)))
12181214
1219- static double
1215+ static float8
12201216computeDistance (bool isLeaf ,BOX * box ,Point * point )
12211217{
1222- double result = 0.0 ;
1218+ float8 result = 0.0 ;
12231219
12241220if (isLeaf )
12251221{
@@ -1237,9 +1233,9 @@ computeDistance(bool isLeaf, BOX *box, Point *point)
12371233/* point is over or below box */
12381234Assert (box -> low .y <=box -> high .y );
12391235if (point -> y > box -> high .y )
1240- result = point -> y - box -> high .y ;
1236+ result = float8_mi ( point -> y , box -> high .y ) ;
12411237else if (point -> y < box -> low .y )
1242- result = box -> low .y - point -> y ;
1238+ result = float8_mi ( box -> low .y , point -> y ) ;
12431239else
12441240elog (ERROR ,"inconsistent point values" );
12451241}
@@ -1248,17 +1244,17 @@ computeDistance(bool isLeaf, BOX *box, Point *point)
12481244/* point is to left or right of box */
12491245Assert (box -> low .x <=box -> high .x );
12501246if (point -> x > box -> high .x )
1251- result = point -> x - box -> high .x ;
1247+ result = float8_mi ( point -> x , box -> high .x ) ;
12521248else if (point -> x < box -> low .x )
1253- result = box -> low .x - point -> x ;
1249+ result = float8_mi ( box -> low .x , point -> x ) ;
12541250else
12551251elog (ERROR ,"inconsistent point values" );
12561252}
12571253else
12581254{
12591255/* closest point will be a vertex */
12601256Point p ;
1261- double subresult ;
1257+ float8 subresult ;
12621258
12631259result = point_point_distance (point ,& box -> low );
12641260
@@ -1449,7 +1445,7 @@ gist_point_distance(PG_FUNCTION_ARGS)
14491445{
14501446GISTENTRY * entry = (GISTENTRY * )PG_GETARG_POINTER (0 );
14511447StrategyNumber strategy = (StrategyNumber )PG_GETARG_UINT16 (2 );
1452- double distance ;
1448+ float8 distance ;
14531449StrategyNumber strategyGroup = strategy /GeoStrategyNumberOffset ;
14541450
14551451switch (strategyGroup )
@@ -1478,11 +1474,11 @@ gist_point_distance(PG_FUNCTION_ARGS)
14781474 * This is a lower bound estimate of distance from point to indexed geometric
14791475 * type.
14801476 */
1481- static double
1477+ static float8
14821478gist_bbox_distance (GISTENTRY * entry ,Datum query ,
14831479StrategyNumber strategy ,bool * recheck )
14841480{
1485- double distance ;
1481+ float8 distance ;
14861482StrategyNumber strategyGroup = strategy /GeoStrategyNumberOffset ;
14871483
14881484/* Bounding box distance is always inexact. */
@@ -1512,7 +1508,7 @@ gist_circle_distance(PG_FUNCTION_ARGS)
15121508
15131509/* Oid subtype = PG_GETARG_OID(3); */
15141510bool * recheck = (bool * )PG_GETARG_POINTER (4 );
1515- double distance ;
1511+ float8 distance ;
15161512
15171513distance = gist_bbox_distance (entry ,query ,strategy ,recheck );
15181514
@@ -1528,7 +1524,7 @@ gist_poly_distance(PG_FUNCTION_ARGS)
15281524
15291525/* Oid subtype = PG_GETARG_OID(3); */
15301526bool * recheck = (bool * )PG_GETARG_POINTER (4 );
1531- double distance ;
1527+ float8 distance ;
15321528
15331529distance = gist_bbox_distance (entry ,query ,strategy ,recheck );
15341530