Skip to content

Commit fb93eb4

Browse files
authored
Merge pull request #62 from vitcpp/gcc-bug-323
Fix overlaps.sql test fail on 32 bit Debian due to gcc bug 323
2 parents 2385d5d + 8e7c92f commit fb93eb4

File tree

6 files changed

+86
-4
lines changed

6 files changed

+86
-4
lines changed

Diff for: Makefile

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PGSPHERE_VERSION = 1.3.0
1+
PGSPHERE_VERSION = 1.3.1
22
EXTENSION = pg_sphere
33
RELEASE_SQL = $(EXTENSION)--$(PGSPHERE_VERSION).sql
44
USE_PGXS = 1
@@ -28,7 +28,8 @@ DATA_built = $(RELEASE_SQL) \
2828
pg_sphere--1.2.0--1.2.1.sql \
2929
pg_sphere--1.2.1--1.2.2.sql \
3030
pg_sphere--1.2.2--1.2.3.sql \
31-
pg_sphere--1.2.3--1.3.0.sql
31+
pg_sphere--1.2.3--1.3.0.sql \
32+
pg_sphere--1.3.0--1.3.1.sql
3233

3334
DOCS = README.pg_sphere COPYRIGHT.pg_sphere
3435
REGRESS = init tables points euler circle line ellipse poly path box index \
@@ -265,6 +266,9 @@ pg_sphere--1.2.2--1.2.3.sql:
265266
pg_sphere--1.2.3--1.3.0.sql: pgs_brin.sql.in
266267
cat upgrade_scripts/$@.in $^ > $@
267268

269+
pg_sphere--1.3.0--1.3.1.sql:
270+
cat upgrade_scripts/$@.in > $@
271+
268272
# end of local stuff
269273

270274
src/sscan.o : src/sparse.c

Diff for: expected/init.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ CREATE EXTENSION pg_sphere;
66
select pg_sphere_version();
77
pg_sphere_version
88
-------------------
9-
1.3.0
9+
1.3.1
1010
(1 row)
1111

File renamed without changes.

Diff for: pg_sphere.control

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pg_sphere extension
22
comment = 'spherical objects with useful functions, operators and index support'
3-
default_version = '1.3.0'
3+
default_version = '1.3.1'
44
module_pathname = '$libdir/pg_sphere'
55
relocatable = true

Diff for: src/pg_sphere.h

+77
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,85 @@
4545

4646
#include "pgs_util.h"
4747

48+
/* On some 32 bit platforms, there is a gcc bug that makes floating point
49+
* calculations and comparisons unstable (see the link below). The problem
50+
* originates in FPU 80 bits registers where double values are not truncated
51+
* to 64 bit values. When gcc compiles some code with enabled optimizations,
52+
* the intermediate results may be kept in the FPU registers without truncation
53+
* to 64 bit values. Extra bits may produce unstable results when comparing
54+
* the numbers.
55+
*
56+
* The generic solution is to save the intermediate results in the memory where
57+
* the values are truncated to 64 bit values. It affects the performance but
58+
* makes the tests stable on all platforms.
59+
*
60+
* PGSPHERE_FLOAT_STORE macro enables storing of intermediate results for FPxx
61+
* operations in the memory. It is enabled by default for 32 bit platforms.
62+
* It can be explicitly enabled or disabled in CFLAGS. To enable it for all
63+
* code the gcc option -ffloat-store may be used as well.
64+
*
65+
* Link to gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=323
66+
*/
67+
#if !defined(PGSPHERE_FLOAT_STORE)
68+
#if _WIN64 || (__GNUC__ && __x86_64__)
69+
#define PGSPHERE_FLOAT_STORE 0
70+
#elif _WIN32 || __GNUC__
71+
#define PGSPHERE_FLOAT_STORE 1
72+
#else
73+
#define PGSPHERE_FLOAT_STORE 0
74+
#endif
75+
#endif // PGSPHERE_FLOAT_STORE
76+
4877
#define EPSILON 1.0E-09
4978

5079
#define FPzero(A) (fabs(A) <= EPSILON)
5180

81+
#if PGSPHERE_FLOAT_STORE
82+
83+
static inline bool
84+
FPeq(double A, double B)
85+
{
86+
const volatile double AB = A - B;
87+
return A == B || fabs(AB) <= EPSILON;
88+
}
89+
90+
static inline bool
91+
FPne(double A, double B)
92+
{
93+
const volatile double AB = A - B;
94+
return A != B && fabs(AB) > EPSILON;
95+
}
96+
97+
static inline bool
98+
FPlt(double A, double B)
99+
{
100+
const volatile double AE = A + EPSILON;
101+
return AE < B;
102+
}
103+
104+
static inline bool
105+
FPle(double A, double B)
106+
{
107+
const volatile double BE = B + EPSILON;
108+
return A <= BE;
109+
}
110+
111+
static inline bool
112+
FPgt(double A, double B)
113+
{
114+
const volatile double BE = B + EPSILON;
115+
return A > BE;
116+
}
117+
118+
static inline bool
119+
FPge(double A, double B)
120+
{
121+
const volatile double AE = A + EPSILON;
122+
return AE >= B;
123+
}
124+
125+
#else
126+
52127
static inline bool
53128
FPeq(double A, double B)
54129
{
@@ -85,6 +160,8 @@ FPge(double A, double B)
85160
return A + EPSILON >= B;
86161
}
87162

163+
#endif // PGSPHERE_FLOAT_STORE
164+
88165
/*---------------------------------------------------------------------
89166
* Point - (x,y)
90167
*-------------------------------------------------------------------*/

Diff for: upgrade_scripts/pg_sphere--1.3.0--1.3.1.sql.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- Nothing to upgrade in the schema

0 commit comments

Comments
 (0)