diff options
author | Tom Lane | 2016-09-27 15:38:33 +0000 |
---|---|---|
committer | Tom Lane | 2016-09-27 15:38:33 +0000 |
commit | f31a931fade868d788ef4480c59753a2d5059246 (patch) | |
tree | 614246ea47696b568ad5b7ea06f7c75d932802cf /contrib/cube/cubedata.h | |
parent | 51c3e9fade76c12e4aa37bffdf800bbf74fb3fb1 (diff) |
Improve contrib/cube's handling of zero-D cubes, infinities, and NaNs.
It's always been possible to create a zero-dimensional cube by converting
from a zero-length float8 array, but cube_in failed to accept the '()'
representation that cube_out produced for that case, resulting in a
dump/reload hazard. Make it accept the case. Also fix a couple of
other places that didn't behave sanely for zero-dimensional cubes:
cube_size would produce 1.0 when surely the answer should be 0.0,
and g_cube_distance risked a divide-by-zero failure.
Likewise, it's always been possible to create cubes containing float8
infinity or NaN coordinate values, but cube_in couldn't parse such input,
and cube_out produced platform-dependent spellings of the values. Convert
them to use float8in_internal and float8out_internal so that the behavior
will be the same as for float8, as we recently did for the core geometric
types (cf commit 50861cd68). As in that commit, I don't pretend that this
patch fixes all insane corner-case behaviors that may exist for NaNs, but
it's a step forward.
(This change allows removal of the separate cube_1.out and cube_3.out
expected-files, as the platform dependency that previously required them
is now gone: an underflowing coordinate value will now produce an error
not plus or minus zero.)
Make errors from cube_in follow project conventions as to spelling
("invalid input syntax for cube" not "bad cube representation")
and errcode (INVALID_TEXT_REPRESENTATION not SYNTAX_ERROR).
Also a few marginal code cleanups and comment improvements.
Tom Lane, reviewed by Amul Sul
Discussion: <15085.1472494782@sss.pgh.pa.us>
Diffstat (limited to 'contrib/cube/cubedata.h')
-rw-r--r-- | contrib/cube/cubedata.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/contrib/cube/cubedata.h b/contrib/cube/cubedata.h index 7eaac396403..af02464178c 100644 --- a/contrib/cube/cubedata.h +++ b/contrib/cube/cubedata.h @@ -1,5 +1,9 @@ /* contrib/cube/cubedata.h */ +/* + * This limit is pretty arbitrary, but don't make it so large that you + * risk overflow in sizing calculations. + */ #define CUBE_MAX_DIM (100) typedef struct NDBOX @@ -29,6 +33,7 @@ typedef struct NDBOX double x[FLEXIBLE_ARRAY_MEMBER]; } NDBOX; +/* NDBOX access macros */ #define POINT_BIT 0x80000000 #define DIM_MASK 0x7fffffff @@ -43,10 +48,12 @@ typedef struct NDBOX #define POINT_SIZE(_dim) (offsetof(NDBOX, x) + sizeof(double)*(_dim)) #define CUBE_SIZE(_dim) (offsetof(NDBOX, x) + sizeof(double)*(_dim)*2) +/* fmgr interface macros */ #define DatumGetNDBOX(x) ((NDBOX *) PG_DETOAST_DATUM(x)) #define PG_GETARG_NDBOX(x) DatumGetNDBOX(PG_GETARG_DATUM(x)) #define PG_RETURN_NDBOX(x) PG_RETURN_POINTER(x) +/* GiST operator strategy numbers */ #define CubeKNNDistanceCoord 15 /* ~> */ #define CubeKNNDistanceTaxicab 16 /* <#> */ #define CubeKNNDistanceEuclid 17 /* <-> */ |