summaryrefslogtreecommitdiff
path: root/src/include/utils
diff options
context:
space:
mode:
authorTomas Vondra2018-08-16 17:56:11 +0000
committerTomas Vondra2018-08-16 17:56:11 +0000
commitc4c34008854654279ec30067d72fc5d174d2f42f (patch)
treee598b56e55eb225263be08af6a0a7aad9e48f651 /src/include/utils
parenta082aed0723c737ec65222730ccede5db5251b4d (diff)
Use the built-in float datatypes to implement geometric types
This patch makes the geometric operators and functions use the exported function of the float4/float8 datatypes. The main reason of doing so is to check for underflow and overflow, and to handle NaNs consciously. The float datatypes consider NaNs values to be equal and greater than all non-NaN values. This change considers NaNs equal only for equality operators. The placement operators, contains, overlaps, left/right of etc. continue to return false when NaNs are involved. We don't need to worry about them being considered greater than any-NaN because there aren't any basic comparison operators like less/greater than for the geometric datatypes. The changes may be summarised as: * Check for underflow, overflow and division by zero * Consider NaN values to be equal * Return NULL when the distance is NaN for all closest point operators * Favour not-NaN over NaN where it makes sense The patch also replaces all occurrences of "double" as "float8". They are the same, but were used inconsistently in the same file. Author: Emre Hasegeli Reviewed-by: Kyotaro Horiguchi, Tomas Vondra Discussion: https://www.postgresql.org/message-id/CAE2gYzxF7-5djV6-cEvqQu-fNsnt%3DEqbOURx7ZDg%2BVv6ZMTWbg%40mail.gmail.com
Diffstat (limited to 'src/include/utils')
-rw-r--r--src/include/utils/geo_decls.h19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/include/utils/geo_decls.h b/src/include/utils/geo_decls.h
index 0e066894cd1..9f8505804e8 100644
--- a/src/include/utils/geo_decls.h
+++ b/src/include/utils/geo_decls.h
@@ -8,9 +8,6 @@
*
* src/include/utils/geo_decls.h
*
- * NOTE
- * These routines do *not* use the float types from adt/.
- *
* XXX These routines were not written by a numerical analyst.
*
* XXX I have made some attempt to flesh out the operators
@@ -21,14 +18,14 @@
#ifndef GEO_DECLS_H
#define GEO_DECLS_H
-#include <math.h>
-
#include "fmgr.h"
/*--------------------------------------------------------------------
* Useful floating point utilities and constants.
- *-------------------------------------------------------------------*/
-
+ *-------------------------------------------------------------------
+ *
+ * XXX: They are not NaN-aware.
+ */
#define EPSILON 1.0E-06
@@ -57,7 +54,7 @@
*-------------------------------------------------------------------*/
typedef struct
{
- double x,
+ float8 x,
y;
} Point;
@@ -89,7 +86,7 @@ typedef struct
*-------------------------------------------------------------------*/
typedef struct
{
- double A,
+ float8 A,
B,
C;
} LINE;
@@ -124,7 +121,7 @@ typedef struct
typedef struct
{
Point center;
- double radius;
+ float8 radius;
} CIRCLE;
/*
@@ -178,6 +175,6 @@ typedef struct
* in geo_ops.c
*/
-extern double pg_hypot(double x, double y);
+extern float8 pg_hypot(float8 x, float8 y);
#endif /* GEO_DECLS_H */