Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6bf0bc8

Browse files
committed
Provide separate header file for built-in float types
Some data types under adt/ have separate header files, but most simpleones do not, and their public functions are defined in builtins.h. Asthe patches improving geometric types will require making additionalfunctions public, this seems like a good opportunity to create a headerfor floats types.Commit1acf757 made _cmp functions public to solve NaN issues locallyfor GiST indexes. This patch reworks it in favour of a more widelyapplicable API. The API uses inline functions, as they are easier touse compared to macros, and avoid double-evaluation hazards.Author: Emre HasegeliReviewed-by: Kyotaro HoriguchiDiscussion:https://www.postgresql.org/message-id/CAE2gYzxF7-5djV6-cEvqQu-fNsnt%3DEqbOURx7ZDg%2BVv6ZMTWbg%40mail.gmail.com
1 parenta7dc63d commit6bf0bc8

File tree

20 files changed

+556
-513
lines changed

20 files changed

+556
-513
lines changed

‎contrib/btree_gin/btree_gin.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include"utils/bytea.h"
1111
#include"utils/cash.h"
1212
#include"utils/date.h"
13+
#include"utils/float.h"
1314
#include"utils/inet.h"
1415
#include"utils/numeric.h"
1516
#include"utils/timestamp.h"

‎contrib/btree_gist/btree_ts.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include"btree_utils_num.h"
1010
#include"utils/builtins.h"
1111
#include"utils/datetime.h"
12+
#include"utils/float.h"
1213

1314
typedefstruct
1415
{

‎contrib/cube/cube.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include"access/gist.h"
1414
#include"access/stratnum.h"
1515
#include"utils/array.h"
16-
#include"utils/builtins.h"
16+
#include"utils/float.h"
1717

1818
#include"cubedata.h"
1919

‎contrib/cube/cubeparse.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include"postgres.h"
88

99
#include"cubedata.h"
10-
#include"utils/builtins.h"
10+
#include"utils/float.h"
1111

1212
/* All grammar constructs return strings*/
1313
#defineYYSTYPEchar *

‎contrib/postgres_fdw/postgres_fdw.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include"optimizer/tlist.h"
3636
#include"parser/parsetree.h"
3737
#include"utils/builtins.h"
38+
#include"utils/float.h"
3839
#include"utils/guc.h"
3940
#include"utils/lsyscache.h"
4041
#include"utils/memutils.h"

‎src/backend/access/gist/gistget.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include"storage/predicate.h"
2323
#include"pgstat.h"
2424
#include"lib/pairingheap.h"
25-
#include"utils/builtins.h"
25+
#include"utils/float.h"
2626
#include"utils/memutils.h"
2727
#include"utils/rel.h"
2828

‎src/backend/access/gist/gistproc.c

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
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
#defineLIMIT_RATIO 0.3
3536

36-
/* Convenience macros for NaN-aware comparisons */
37-
#defineFLOAT8_EQ(a,b)(float8_cmp_internal(a, b) == 0)
38-
#defineFLOAT8_LT(a,b)(float8_cmp_internal(a, b) < 0)
39-
#defineFLOAT8_LE(a,b)(float8_cmp_internal(a, b) <= 0)
40-
#defineFLOAT8_GT(a,b)(float8_cmp_internal(a, b) > 0)
41-
#defineFLOAT8_GE(a,b)(float8_cmp_internal(a, b) >= 0)
42-
#defineFLOAT8_MAX(a,b) (FLOAT8_GT(a, b) ? (a) : (b))
43-
#defineFLOAT8_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,
5345
staticvoid
5446
rt_box_union(BOX*n,constBOX*a,constBOX*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
return0.0;
7971

8072
/*
@@ -143,13 +135,13 @@ gist_box_consistent(PG_FUNCTION_ARGS)
143135
staticvoid
144136
adjustBox(BOX*b,constBOX*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);

‎src/backend/access/gist/gistutil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include"catalog/pg_opclass.h"
2222
#include"storage/indexfsm.h"
2323
#include"storage/lmgr.h"
24-
#include"utils/builtins.h"
24+
#include"utils/float.h"
2525
#include"utils/syscache.h"
2626

2727

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp