[postgis-devel] Min, Max and Abs functions
Mark Cave-Ayland
m.cave-ayland at webbased.co.uk
Thu Nov 4 01:53:14 PST 2004
Hi everyone,
Reading through the PostgreSQL lists a couple of days ago, I noticed a
comment about how PostgreSQL supplies it's own min(), max(), and abs()
functions. Surely enough, if you download a PostgreSQL source and look in
src/include/c.h (which is included by postgres.h) you can see the
corresponding definitions:
/*
* Max
* Return the maximum of two numbers.
*/
#define Max(x, y) ((x) > (y) ? (x) : (y))
/*
* Min
* Return the minimum of two numbers.
*/
#define Min(x, y) ((x) < (y) ? (x) : (y))
/*
* Abs
* Return the absolute value of the argument.
*/
#define Abs(x) ((x) >= 0 ? (x) : -(x))
Is there any reason why we shouldn't use these in PostGIS? From memory,
there are several definitions of min(), max() and abs() particularly in the
0.9 branch which must be defined if using certain compilers like MingW and
Cygwin. It strikes me that the code could be tidied up and made consistent
across all platforms by making use of the PostgreSQL operators instead.
For reference, the current CVS contains the following in liblwgeom.h:
//#if ! defined(__MINGW32__)
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) <= (b) ? (a) : (b))
//#endif
#define abs(a) ((a) < (0) ? (-a) : (a))
While the definitions are slightly different in the cases where equal
numbers are involved, since the macros are #defined it should just be the
result which is altered since none of the parameters are passed by
reference.
Thoughts?
Mark.
------------------------
WebBased Ltd
South West Technology Centre
Tamar Science Park
Plymouth
PL6 8BT
T: +44 (0)1752 791021
F: +44 (0)1752 791023
W: http://www.webbased.co.uk
More information about the postgis-devel
mailing list