2222#include "access/gist.h"
2323#include "access/stratnum.h"
2424#include "utils/builtins.h"
25+ #include "utils/float.h"
2526#include "utils/geo_decls.h"
2627
2728
@@ -33,15 +34,6 @@ static bool rtree_internal_consistent(BOX *key, BOX *query,
3334/* Minimum accepted ratio of split */
3435#define LIMIT_RATIO 0.3
3536
36- /* Convenience macros for NaN-aware comparisons */
37- #define FLOAT8_EQ (a ,b ) (float8_cmp_internal(a, b) == 0)
38- #define FLOAT8_LT (a ,b ) (float8_cmp_internal(a, b) < 0)
39- #define FLOAT8_LE (a ,b ) (float8_cmp_internal(a, b) <= 0)
40- #define FLOAT8_GT (a ,b ) (float8_cmp_internal(a, b) > 0)
41- #define FLOAT8_GE (a ,b ) (float8_cmp_internal(a, b) >= 0)
42- #define FLOAT8_MAX (a ,b ) (FLOAT8_GT(a, b) ? (a) : (b))
43- #define FLOAT8_MIN (a ,b ) (FLOAT8_LT(a, b) ? (a) : (b))
44-
4537
4638/**************************************************
4739 * Box ops
@@ -53,10 +45,10 @@ static bool rtree_internal_consistent(BOX *key, BOX *query,
5345static void
5446rt_box_union (BOX * n , const BOX * a , const BOX * b )
5547{
56- n -> high .x = FLOAT8_MAX (a -> high .x , b -> high .x );
57- n -> high .y = FLOAT8_MAX (a -> high .y , b -> high .y );
58- n -> low .x = FLOAT8_MIN (a -> low .x , b -> low .x );
59- n -> low .y = FLOAT8_MIN (a -> low .y , b -> low .y );
48+ n -> high .x = float8_max (a -> high .x , b -> high .x );
49+ n -> high .y = float8_max (a -> high .y , b -> high .y );
50+ n -> low .x = float8_min (a -> low .x , b -> low .x );
51+ n -> low .y = float8_min (a -> low .y , b -> low .y );
6052}
6153
6254/*
@@ -73,8 +65,8 @@ size_box(const BOX *box)
7365 *
7466 * The less-than cases should not happen, but if they do, say "zero".
7567 */
76- if (FLOAT8_LE (box -> high .x , box -> low .x ) ||
77- FLOAT8_LE (box -> high .y , box -> low .y ))
68+ if (float8_le (box -> high .x , box -> low .x ) ||
69+ float8_le (box -> high .y , box -> low .y ))
7870 return 0.0 ;
7971
8072 /*
@@ -143,13 +135,13 @@ gist_box_consistent(PG_FUNCTION_ARGS)
143135static void
144136adjustBox (BOX * b , const BOX * addon )
145137{
146- if (FLOAT8_LT (b -> high .x , addon -> high .x ))
138+ if (float8_lt (b -> high .x , addon -> high .x ))
147139 b -> high .x = addon -> high .x ;
148- if (FLOAT8_GT (b -> low .x , addon -> low .x ))
140+ if (float8_gt (b -> low .x , addon -> low .x ))
149141 b -> low .x = addon -> low .x ;
150- if (FLOAT8_LT (b -> high .y , addon -> high .y ))
142+ if (float8_lt (b -> high .y , addon -> high .y ))
151143 b -> high .y = addon -> high .y ;
152- if (FLOAT8_GT (b -> low .y , addon -> low .y ))
144+ if (float8_gt (b -> low .y , addon -> low .y ))
153145 b -> low .y = addon -> low .y ;
154146}
155147
@@ -615,9 +607,9 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
615607 * Find next lower bound of right group.
616608 */
617609 while (i1 < nentries &&
618- FLOAT8_EQ (rightLower , intervalsLower [i1 ].lower ))
610+ float8_eq (rightLower , intervalsLower [i1 ].lower ))
619611 {
620- if (FLOAT8_LT (leftUpper , intervalsLower [i1 ].upper ))
612+ if (float8_lt (leftUpper , intervalsLower [i1 ].upper ))
621613 leftUpper = intervalsLower [i1 ].upper ;
622614 i1 ++ ;
623615 }
@@ -630,7 +622,7 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
630622 * left group.
631623 */
632624 while (i2 < nentries &&
633- FLOAT8_LE (intervalsUpper [i2 ].upper , leftUpper ))
625+ float8_le (intervalsUpper [i2 ].upper , leftUpper ))
634626 i2 ++ ;
635627
636628 /*
@@ -652,9 +644,9 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
652644 /*
653645 * Find next upper bound of left group.
654646 */
655- while (i2 >= 0 && FLOAT8_EQ (leftUpper , intervalsUpper [i2 ].upper ))
647+ while (i2 >= 0 && float8_eq (leftUpper , intervalsUpper [i2 ].upper ))
656648 {
657- if (FLOAT8_GT (rightLower , intervalsUpper [i2 ].lower ))
649+ if (float8_gt (rightLower , intervalsUpper [i2 ].lower ))
658650 rightLower = intervalsUpper [i2 ].lower ;
659651 i2 -- ;
660652 }
@@ -666,7 +658,7 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
666658 * Find count of intervals which anyway should be placed to the
667659 * right group.
668660 */
669- while (i1 >= 0 && FLOAT8_GE (intervalsLower [i1 ].lower , rightLower ))
661+ while (i1 >= 0 && float8_ge (intervalsLower [i1 ].lower , rightLower ))
670662 i1 -- ;
671663
672664 /*
@@ -754,10 +746,10 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
754746 upper = box -> high .y ;
755747 }
756748
757- if (FLOAT8_LE (upper , context .leftUpper ))
749+ if (float8_le (upper , context .leftUpper ))
758750 {
759751 /* Fits to the left group */
760- if (FLOAT8_GE (lower , context .rightLower ))
752+ if (float8_ge (lower , context .rightLower ))
761753 {
762754 /* Fits also to the right group, so "common entry" */
763755 commonEntries [commonEntriesCount ++ ].index = i ;
@@ -775,7 +767,7 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
775767 * entry didn't fit on the left group, it better fit in the right
776768 * group.
777769 */
778- Assert (FLOAT8_GE (lower , context .rightLower ));
770+ Assert (float8_ge (lower , context .rightLower ));
779771
780772 /* Doesn't fit to the left group, so join to the right group */
781773 PLACE_RIGHT (box , i );
@@ -859,10 +851,10 @@ gist_box_same(PG_FUNCTION_ARGS)
859851 bool * result = (bool * ) PG_GETARG_POINTER (2 );
860852
861853 if (b1 && b2 )
862- * result = (FLOAT8_EQ (b1 -> low .x , b2 -> low .x ) &&
863- FLOAT8_EQ (b1 -> low .y , b2 -> low .y ) &&
864- FLOAT8_EQ (b1 -> high .x , b2 -> high .x ) &&
865- FLOAT8_EQ (b1 -> high .y , b2 -> high .y ));
854+ * result = (float8_eq (b1 -> low .x , b2 -> low .x ) &&
855+ float8_eq (b1 -> low .y , b2 -> low .y ) &&
856+ float8_eq (b1 -> high .x , b2 -> high .x ) &&
857+ float8_eq (b1 -> high .y , b2 -> high .y ));
866858 else
867859 * result = (b1 == NULL && b2 == NULL );
868860 PG_RETURN_POINTER (result );
0 commit comments