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 )
{
#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
{
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 */
/* 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;
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 )
POINT2D p;
LWPOLY *lwpoly;
LWPOINT *lwpt;
- double distance = MAXFLOAT;
+ double distance = FLT_MAX;
int i;
if ( type1 == POINTTYPE )
POINT2D p;
LWPOLY *lwpoly;
LWLINE *lwline;
- double distance = MAXFLOAT;
+ double distance = FLT_MAX;
int i;
if ( type1 == LINETYPE )
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 */
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++ )
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++ )
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;
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 */
}
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. */
#include "liblwgeom_internal.h"
#include "lwgeom_log.h"
-#include <float.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>
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;
}
/**
{
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;
{
double x,y;
DISTPTS thedl;
- double initdistance = MAXFLOAT;
+ double initdistance = FLT_MAX;
LWGEOM *result;
thedl.mode = mode;
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))
{
}
/*should never get here. all cases ought to be error handled earlier*/
lwerror("Some unspecified error.");
- return MAXFLOAT;
+ return FLT_MAX;
}
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;
{
double x,y,z;
DISTPTS3D thedl;
- double initdistance = MAXFLOAT;
+ double initdistance = FLT_MAX;
LWGEOM *result;
thedl.mode = mode;
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))
{
}
/*should never get here. all cases ought to be error handled earlier*/
lwerror("Some unspecified error.");
- return MAXFLOAT;
+ return FLT_MAX;
}
#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
return b->ymin - a->ymax;
}
- return MAXFLOAT;
+ return FLT_MAX;
}
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);
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);
* 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 */
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);
}
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();
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);
}
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();
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);
}