22
22
#include "access/gist.h"
23
23
#include "access/stratnum.h"
24
24
#include "utils/builtins.h"
25
+ #include "utils/float.h"
25
26
#include "utils/geo_decls.h"
26
27
27
28
@@ -33,15 +34,6 @@ static bool rtree_internal_consistent(BOX *key, BOX *query,
33
34
/* Minimum accepted ratio of split */
34
35
#define LIMIT_RATIO 0.3
35
36
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
-
45
37
46
38
/**************************************************
47
39
* Box ops
@@ -53,10 +45,10 @@ static bool rtree_internal_consistent(BOX *key, BOX *query,
53
45
static void
54
46
rt_box_union (BOX * n , const BOX * a , const BOX * b )
55
47
{
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 );
60
52
}
61
53
62
54
/*
@@ -73,8 +65,8 @@ size_box(const BOX *box)
73
65
*
74
66
* The less-than cases should not happen, but if they do, say "zero".
75
67
*/
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 ))
78
70
return 0.0 ;
79
71
80
72
/*
@@ -143,13 +135,13 @@ gist_box_consistent(PG_FUNCTION_ARGS)
143
135
static void
144
136
adjustBox (BOX * b , const BOX * addon )
145
137
{
146
- if (FLOAT8_LT (b -> high .x , addon -> high .x ))
138
+ if (float8_lt (b -> high .x , addon -> high .x ))
147
139
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 ))
149
141
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 ))
151
143
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 ))
153
145
b -> low .y = addon -> low .y ;
154
146
}
155
147
@@ -615,9 +607,9 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
615
607
* Find next lower bound of right group.
616
608
*/
617
609
while (i1 < nentries &&
618
- FLOAT8_EQ (rightLower , intervalsLower [i1 ].lower ))
610
+ float8_eq (rightLower , intervalsLower [i1 ].lower ))
619
611
{
620
- if (FLOAT8_LT (leftUpper , intervalsLower [i1 ].upper ))
612
+ if (float8_lt (leftUpper , intervalsLower [i1 ].upper ))
621
613
leftUpper = intervalsLower [i1 ].upper ;
622
614
i1 ++ ;
623
615
}
@@ -630,7 +622,7 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
630
622
* left group.
631
623
*/
632
624
while (i2 < nentries &&
633
- FLOAT8_LE (intervalsUpper [i2 ].upper , leftUpper ))
625
+ float8_le (intervalsUpper [i2 ].upper , leftUpper ))
634
626
i2 ++ ;
635
627
636
628
/*
@@ -652,9 +644,9 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
652
644
/*
653
645
* Find next upper bound of left group.
654
646
*/
655
- while (i2 >= 0 && FLOAT8_EQ (leftUpper , intervalsUpper [i2 ].upper ))
647
+ while (i2 >= 0 && float8_eq (leftUpper , intervalsUpper [i2 ].upper ))
656
648
{
657
- if (FLOAT8_GT (rightLower , intervalsUpper [i2 ].lower ))
649
+ if (float8_gt (rightLower , intervalsUpper [i2 ].lower ))
658
650
rightLower = intervalsUpper [i2 ].lower ;
659
651
i2 -- ;
660
652
}
@@ -666,7 +658,7 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
666
658
* Find count of intervals which anyway should be placed to the
667
659
* right group.
668
660
*/
669
- while (i1 >= 0 && FLOAT8_GE (intervalsLower [i1 ].lower , rightLower ))
661
+ while (i1 >= 0 && float8_ge (intervalsLower [i1 ].lower , rightLower ))
670
662
i1 -- ;
671
663
672
664
/*
@@ -754,10 +746,10 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
754
746
upper = box -> high .y ;
755
747
}
756
748
757
- if (FLOAT8_LE (upper , context .leftUpper ))
749
+ if (float8_le (upper , context .leftUpper ))
758
750
{
759
751
/* Fits to the left group */
760
- if (FLOAT8_GE (lower , context .rightLower ))
752
+ if (float8_ge (lower , context .rightLower ))
761
753
{
762
754
/* Fits also to the right group, so "common entry" */
763
755
commonEntries [commonEntriesCount ++ ].index = i ;
@@ -775,7 +767,7 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
775
767
* entry didn't fit on the left group, it better fit in the right
776
768
* group.
777
769
*/
778
- Assert (FLOAT8_GE (lower , context .rightLower ));
770
+ Assert (float8_ge (lower , context .rightLower ));
779
771
780
772
/* Doesn't fit to the left group, so join to the right group */
781
773
PLACE_RIGHT (box , i );
@@ -859,10 +851,10 @@ gist_box_same(PG_FUNCTION_ARGS)
859
851
bool * result = (bool * ) PG_GETARG_POINTER (2 );
860
852
861
853
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 ));
866
858
else
867
859
* result = (b1 == NULL && b2 == NULL );
868
860
PG_RETURN_POINTER (result );
0 commit comments