]> granicus.if.org Git - postgis/commitdiff
Replace MAXFLOAT with more "standard" FLT_MAX
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 19 Sep 2014 16:27:20 +0000 (16:27 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 19 Sep 2014 16:27:20 +0000 (16:27 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@12988 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/g_box.c
liblwgeom/liblwgeom_internal.h
liblwgeom/lwgeodetic.c
liblwgeom/lwgeodetic_tree.c
liblwgeom/lwgeom_api.c
liblwgeom/measures.c
liblwgeom/measures3d.c
postgis/gserialized_gist_2d.c
postgis/lwgeom_backend_api.c
postgis/lwgeom_functions_basic.c

index 239fd8b0b1a09417d7bbd7299d738572431970cd..d095950c04969401ce20eb81ccbe76b63fa3df88 100644 (file)
@@ -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 )
        {
index 715ba682d19b02503e2aed7498d66b82a327080a..f029cbb07a96b2880e73408e842d5cfeab7f6c57 100644 (file)
@@ -28,6 +28,8 @@
 #include <ieeefp.h>
 #endif
 
+#include <float.h>
+
 #include "liblwgeom.h"
 
 
 #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
index 29a235c5ae1be3a47b0499c8d77d77e1c840a561..ce447a2ab3774f198d9057205e29afc636fee213 100644 (file)
@@ -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++ )
index c972fd636c33117ef0cd12b84395d44a1ca8608b..eab196ee91e12bcf86bb65fa1ee0d0fc326ede48 100644 (file)
@@ -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. */
index 6c171c40d092d4eaf95b27581209caa3d7e1bc83..3323e094924b8ebc0d53bcf51e80dfd4ede2d2c2 100644 (file)
@@ -14,7 +14,6 @@
 #include "liblwgeom_internal.h"
 #include "lwgeom_log.h"
 
-#include <float.h>
 #include <stdio.h>
 #include <errno.h>
 #include <assert.h>
index 0bcd6ce2d8be409e2805e891918afafb1b57346d..566d0b308a3325d7c229f74b56351cd86830d369 100644 (file)
@@ -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;
 }
 
 
index ced0806d644616da6e6a6490031148232ed40058..a62d502df3deabfbca4494c9301d18fc33c585df 100644 (file)
@@ -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;
 }
 
 
index 5c1ef85c275534de136d3d01abcad4f072550370..1d3f4ef0ec769bd5ae175a7598e89e3c25dd7458 100644 (file)
@@ -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 */
index 0910ad0e4033a32293375134852c07bcf6d137b3..649b109cf8a41c2ff694c5af4beface8157e46da 100644 (file)
@@ -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);
 }
index 94a0406f8a0cae7cbfc4215fa836f8ab21eb27f8..b56fd2676d150903a9a9ecf023c7d75be68ef961 100644 (file)
@@ -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<MAXFLOAT)
+       if (mindist<FLT_MAX)
                PG_RETURN_FLOAT8(mindist);
        
        PG_RETURN_NULL();
@@ -745,7 +745,7 @@ Datum LWGEOM_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(tolerance >= 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<MAXFLOAT)
+       if (mindist<FLT_MAX)
                PG_RETURN_FLOAT8(mindist);
 
        PG_RETURN_NULL();
@@ -989,7 +989,7 @@ Datum LWGEOM_dwithin3d(PG_FUNCTION_ARGS)
        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(tolerance >= mindist);
 }