From: Paul Ramsey Date: Fri, 19 Sep 2014 16:27:20 +0000 (+0000) Subject: Replace MAXFLOAT with more "standard" FLT_MAX X-Git-Tag: 2.2.0rc1~839 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e4b650737c7da760d492b65bdc5962128b6a6b8;p=postgis Replace MAXFLOAT with more "standard" FLT_MAX git-svn-id: http://svn.osgeo.org/postgis/trunk@12988 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/g_box.c b/liblwgeom/g_box.c index 239fd8b0b..d095950c0 100644 --- a/liblwgeom/g_box.c +++ b/liblwgeom/g_box.c @@ -528,8 +528,8 @@ static int lwcircstring_calculate_gbox_cartesian(LWCIRCSTRING *curve, GBOX *gbox tmp.flags = flags; /* Initialize */ - gbox->xmin = gbox->ymin = gbox->zmin = gbox->mmin = MAXFLOAT; - gbox->xmax = gbox->ymax = gbox->zmax = gbox->mmax = -1 * MAXFLOAT; + gbox->xmin = gbox->ymin = gbox->zmin = gbox->mmin = FLT_MAX; + gbox->xmax = gbox->ymax = gbox->zmax = gbox->mmax = -1 * FLT_MAX; for ( i = 2; i < curve->points->npoints; i += 2 ) { diff --git a/liblwgeom/liblwgeom_internal.h b/liblwgeom/liblwgeom_internal.h index 715ba682d..f029cbb07 100644 --- a/liblwgeom/liblwgeom_internal.h +++ b/liblwgeom/liblwgeom_internal.h @@ -28,6 +28,8 @@ #include #endif +#include + #include "liblwgeom.h" @@ -57,12 +59,6 @@ #define FP_CONTAINS_EXCL(A, X, B) (FP_LT(A, X) && FP_LT(X, B)) #define FP_CONTAINS(A, X, B) FP_CONTAINS_EXCL(A, X, B) -/** -* Largest float value. Should this be from math.h instead? -*/ -#ifndef MAXFLOAT -#define MAXFLOAT 3.402823466e+38F -#endif /* * this will change to NaN when I figure out how to diff --git a/liblwgeom/lwgeodetic.c b/liblwgeom/lwgeodetic.c index 29a235c5a..ce447a2ab 100644 --- a/liblwgeom/lwgeodetic.c +++ b/liblwgeom/lwgeodetic.c @@ -166,8 +166,8 @@ gbox_angular_height(const GBOX* gbox) { double d[6]; int i; - double zmin = MAXFLOAT; - double zmax = -1 * MAXFLOAT; + double zmin = FLT_MAX; + double zmax = -1 * FLT_MAX; POINT3D pt; /* Take a copy of the box corners so we can treat them as a list */ @@ -212,7 +212,7 @@ gbox_angular_width(const GBOX* gbox) /* Find the vector furthest from our seed vector */ for ( j = 0; j < 2; j++ ) { - maxangle = -1 * MAXFLOAT; + maxangle = -1 * FLT_MAX; for ( i = 0; i < 4; i++ ) { double angle, dotprod; @@ -1741,7 +1741,7 @@ static double ptarray_distance_spheroid(const POINTARRAY *pa1, const POINTARRAY int use_sphere = (s->a == s->b ? 1 : 0); /* Make result really big, so that everything will be smaller than it */ - distance = MAXFLOAT; + distance = FLT_MAX; /* Empty point arrays? Return negative */ if ( pa1->npoints == 0 || pa2->npoints == 0 ) @@ -2144,7 +2144,7 @@ double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, co POINT2D p; LWPOLY *lwpoly; LWPOINT *lwpt; - double distance = MAXFLOAT; + double distance = FLT_MAX; int i; if ( type1 == POINTTYPE ) @@ -2184,7 +2184,7 @@ double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, co POINT2D p; LWPOLY *lwpoly; LWLINE *lwline; - double distance = MAXFLOAT; + double distance = FLT_MAX; int i; if ( type1 == LINETYPE ) @@ -2229,7 +2229,7 @@ double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, co POINT2D p; LWPOLY *lwpoly1 = (LWPOLY*)lwgeom1; LWPOLY *lwpoly2 = (LWPOLY*)lwgeom2; - double distance = MAXFLOAT; + double distance = FLT_MAX; int i, j; /* Point of 2 in polygon 1 implies zero distance */ @@ -2261,7 +2261,7 @@ double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, co if ( lwtype_is_collection(type1) ) { int i; - double distance = MAXFLOAT; + double distance = FLT_MAX; LWCOLLECTION *col = (LWCOLLECTION*)lwgeom1; for ( i = 0; i < col->ngeoms; i++ ) @@ -2279,7 +2279,7 @@ double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, co if ( lwtype_is_collection(type2) ) { int i; - double distance = MAXFLOAT; + double distance = FLT_MAX; LWCOLLECTION *col = (LWCOLLECTION*)lwgeom2; for ( i = 0; i < col->ngeoms; i++ ) diff --git a/liblwgeom/lwgeodetic_tree.c b/liblwgeom/lwgeodetic_tree.c index c972fd636..eab196ee9 100644 --- a/liblwgeom/lwgeodetic_tree.c +++ b/liblwgeom/lwgeodetic_tree.c @@ -552,8 +552,8 @@ circ_node_max_distance(const CIRC_NODE *n1, const CIRC_NODE *n2) double circ_tree_distance_tree(const CIRC_NODE* n1, const CIRC_NODE* n2, const SPHEROID* spheroid, double threshold) { - double min_dist = MAXFLOAT; - double max_dist = MAXFLOAT; + double min_dist = FLT_MAX; + double max_dist = FLT_MAX; GEOGRAPHIC_POINT closest1, closest2; double threshold_radians = threshold / spheroid->radius; @@ -589,7 +589,7 @@ circ_tree_distance_tree_internal(const CIRC_NODE* n1, const CIRC_NODE* n2, doubl if( circ_node_min_distance(n1, n2) > *max_dist ) { LWDEBUGF(4, "pruning pair %p, %p", n1, n2); - return MAXFLOAT; + return FLT_MAX; } /* If your maximum is a new low, we'll use that as our new global tolerance */ @@ -707,7 +707,7 @@ circ_tree_distance_tree_internal(const CIRC_NODE* n1, const CIRC_NODE* n2, doubl } else { - d_min = MAXFLOAT; + d_min = FLT_MAX; /* Drive the recursion into the COLLECTION types first so we end up with */ /* pairings of primitive geometries that can be forced into the point-in-polygon */ /* tests above. */ diff --git a/liblwgeom/lwgeom_api.c b/liblwgeom/lwgeom_api.c index 6c171c40d..3323e0949 100644 --- a/liblwgeom/lwgeom_api.c +++ b/liblwgeom/lwgeom_api.c @@ -14,7 +14,6 @@ #include "liblwgeom_internal.h" #include "lwgeom_log.h" -#include #include #include #include diff --git a/liblwgeom/measures.c b/liblwgeom/measures.c index 0bcd6ce2d..566d0b308 100644 --- a/liblwgeom/measures.c +++ b/liblwgeom/measures.c @@ -57,9 +57,9 @@ lw_dist2d_distpts_init(DISTPTS *dl, int mode) dl->mode = mode; dl->tolerance = 0.0; if ( mode == DIST_MIN ) - dl->distance = MAXFLOAT; + dl->distance = FLT_MAX; else - dl->distance = -1 * MAXFLOAT; + dl->distance = -1 * FLT_MAX; } /** @@ -70,7 +70,7 @@ lw_dist2d_distanceline(LWGEOM *lw1, LWGEOM *lw2, int srid, int mode) { double x1,x2,y1,y2; - double initdistance = ( mode == DIST_MIN ? MAXFLOAT : -1.0); + double initdistance = ( mode == DIST_MIN ? FLT_MAX : -1.0); DISTPTS thedl; LWPOINT *lwpoints[2]; LWGEOM *result; @@ -117,7 +117,7 @@ lw_dist2d_distancepoint(LWGEOM *lw1, LWGEOM *lw2,int srid,int mode) { double x,y; DISTPTS thedl; - double initdistance = MAXFLOAT; + double initdistance = FLT_MAX; LWGEOM *result; thedl.mode = mode; @@ -200,7 +200,7 @@ lwgeom_mindistance2d_tolerance(LWGEOM *lw1, LWGEOM *lw2, double tolerance) DISTPTS thedl; LWDEBUG(2, "lwgeom_mindistance2d_tolerance is called"); thedl.mode = DIST_MIN; - thedl.distance= MAXFLOAT; + thedl.distance= FLT_MAX; thedl.tolerance = tolerance; if (lw_dist2d_comp( lw1,lw2,&thedl)) { @@ -208,7 +208,7 @@ lwgeom_mindistance2d_tolerance(LWGEOM *lw1, LWGEOM *lw2, double tolerance) } /*should never get here. all cases ought to be error handled earlier*/ lwerror("Some unspecified error."); - return MAXFLOAT; + return FLT_MAX; } diff --git a/liblwgeom/measures3d.c b/liblwgeom/measures3d.c index ced0806d6..a62d502df 100644 --- a/liblwgeom/measures3d.c +++ b/liblwgeom/measures3d.c @@ -45,7 +45,7 @@ LWGEOM * lw_dist3d_distanceline(LWGEOM *lw1, LWGEOM *lw2, int srid, int mode) { double x1,x2,y1,y2, z1, z2; - double initdistance = ( mode == DIST_MIN ? MAXFLOAT : -1.0); + double initdistance = ( mode == DIST_MIN ? FLT_MAX : -1.0); DISTPTS3D thedl; LWPOINT *lwpoints[2]; LWGEOM *result; @@ -95,7 +95,7 @@ lw_dist3d_distancepoint(LWGEOM *lw1, LWGEOM *lw2, int srid, int mode) { double x,y,z; DISTPTS3D thedl; - double initdistance = MAXFLOAT; + double initdistance = FLT_MAX; LWGEOM *result; thedl.mode = mode; @@ -181,7 +181,7 @@ lwgeom_mindistance3d_tolerance(LWGEOM *lw1, LWGEOM *lw2, double tolerance) DISTPTS3D thedl; LWDEBUG(2, "lwgeom_mindistance3d_tolerance is called"); thedl.mode = DIST_MIN; - thedl.distance= MAXFLOAT; + thedl.distance= FLT_MAX; thedl.tolerance = tolerance; if (lw_dist3d_recursive(lw1, lw2, &thedl)) { @@ -189,7 +189,7 @@ lwgeom_mindistance3d_tolerance(LWGEOM *lw1, LWGEOM *lw2, double tolerance) } /*should never get here. all cases ought to be error handled earlier*/ lwerror("Some unspecified error."); - return MAXFLOAT; + return FLT_MAX; } diff --git a/postgis/gserialized_gist_2d.c b/postgis/gserialized_gist_2d.c index 5c1ef85c2..1d3f4ef0e 100644 --- a/postgis/gserialized_gist_2d.c +++ b/postgis/gserialized_gist_2d.c @@ -34,7 +34,7 @@ #include "liblwgeom.h" /* For standard geometry types. */ #include "lwgeom_pg.h" /* For debugging macros. */ #include "gserialized_gist.h" /* For utility functions. */ -#include "liblwgeom_internal.h" /* For MAXFLOAT */ +#include "liblwgeom_internal.h" /* For FLT_MAX */ /* Fall back to older finite() if necessary */ #ifndef HAVE_ISFINITE @@ -517,7 +517,7 @@ static double box2df_distance(const BOX2DF *a, const BOX2DF *b) return b->ymin - a->ymax; } - return MAXFLOAT; + return FLT_MAX; } @@ -631,7 +631,7 @@ Datum gserialized_distance_centroid_2d(PG_FUNCTION_ARGS) POSTGIS_DEBUGF(3, "got boxes %s and %s", box2df_to_string(&b1), box2df_to_string(&b2)); PG_RETURN_FLOAT8(distance); } - PG_RETURN_FLOAT8(MAXFLOAT); + PG_RETURN_FLOAT8(FLT_MAX); } PG_FUNCTION_INFO_V1(gserialized_distance_box_2d); @@ -651,7 +651,7 @@ Datum gserialized_distance_box_2d(PG_FUNCTION_ARGS) POSTGIS_DEBUGF(3, "got boxes %s and %s", box2df_to_string(&b1), box2df_to_string(&b2)); PG_RETURN_FLOAT8(distance); } - PG_RETURN_FLOAT8(MAXFLOAT); + PG_RETURN_FLOAT8(FLT_MAX); } PG_FUNCTION_INFO_V1(gserialized_same_2d); @@ -1077,14 +1077,14 @@ Datum gserialized_gist_distance_2d(PG_FUNCTION_ARGS) * and '14' as the gist distance-between-boxes strategy number */ if ( strategy != 13 && strategy != 14 ) { elog(ERROR, "unrecognized strategy number: %d", strategy); - PG_RETURN_FLOAT8(MAXFLOAT); + PG_RETURN_FLOAT8(FLT_MAX); } /* Null box should never make this far. */ if ( gserialized_datum_get_box2df_p(PG_GETARG_DATUM(1), &query_box) == LW_FAILURE ) { POSTGIS_DEBUG(4, "[GIST] null query_gbox_index!"); - PG_RETURN_FLOAT8(MAXFLOAT); + PG_RETURN_FLOAT8(FLT_MAX); } /* Get the entry box */ diff --git a/postgis/lwgeom_backend_api.c b/postgis/lwgeom_backend_api.c index 0910ad0e4..649b109cf 100644 --- a/postgis/lwgeom_backend_api.c +++ b/postgis/lwgeom_backend_api.c @@ -172,6 +172,6 @@ Datum intersects3d_dwithin(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom1, 0); PG_FREE_IF_COPY(geom2, 1); /*empty geometries cases should be right handled since return from underlying - functions should be MAXFLOAT which causes false as answer*/ + functions should be FLT_MAX which causes false as answer*/ PG_RETURN_BOOL(0.0 == mindist); } diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index 94a0406f8..b56fd2676 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -707,7 +707,7 @@ Datum LWGEOM_mindistance2d(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom2, 1); /*if called with empty geometries the ingoing mindistance is untouched, and makes us return NULL*/ - if (mindist= mindist); } @@ -950,7 +950,7 @@ Datum LWGEOM_mindistance3d(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(geom2, 1); /*if called with empty geometries the ingoing mindistance is untouched, and makes us return NULL*/ - if (mindist= mindist); }