Use the built-in float datatypes to implement geometric types

Enterprise / PostgreSQL - Tomas Vondra [] - 16 August 2018 17:56 EDT

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

c4c3400885 Use the built-in float datatypes to implement geometric types
src/backend/access/gist/gistproc.c | 100 ++++----
src/backend/utils/adt/geo_ops.c | 501 ++++++++++++++++++++-----------------
src/backend/utils/adt/geo_spgist.c | 28 +--
src/include/utils/geo_decls.h | 19 +-
4 files changed, 343 insertions(+), 305 deletions(-)


  • Share