[GRASS5] r.in.gdal - precision problem in lib/gis/adj_cellhd.c

Brad Douglas rez at touchofmadness.com
Thu Apr 7 11:11:00 EDT 2005


On Thu, 2005-04-07 at 08:59 +0200, Radim Blazek wrote:
> Brad Douglas wrote:
> > On Wed, 2005-04-06 at 15:23 +0200, Markus Neteler wrote:
> > 
> >>How can I convince lib/gis/adj_cellhd.c to work as desired?
> >>The comparison is currently:
> >>
> >> if (cellhd->north > 90.0)
> >>     return (_("Illegal latitude for North"));
> > 
> > 
> > float north;
> > 
> > sscanf(cellhd->north, "%.1f", &north);
> > if (north > 90.0)
> >     return (_("Illegal latitude for North.\n"));
> > 
> 
> It can silently damage data. I am not in favour.

It should suffice for this specific purpose as a short-term fix.  

Although shunned upon, that usage of sscanf() is littered throughout
GRASS code.  I say we temporarily commit the above to get it "mostly"
working and work on a permanent solution to non-integer comparisons.

Maybe we could do one of these:

/* Compares two floats to 'precision' decimal places */
/* Returns 1 if equal, 0 otherwise                   */
int G_f_equal(float a, float b, int precision)
...

or:

/* Compares two floats; Precision "adjusted"   */
/* Returns 1 if equal, 0 otherwise             */
int G_relequal(float a, float b)
{
#define ABS(x)    ((x) < 0 ? -(x) : (x))
#define MAX(x, y) ((x) <= (y) ? (y) : (x))

    float c = ABS(a);
    float d = ABS(b);

    c = MAX(c, d);
    d = ABS(a - b) / c;

   return (d == 0. ? 1 : 0);
}

/* Compares two floats. "Precision adjusted"   */
/* Returns positive, 0, or negative value if a */
/* is greater, equal, or less than b           */
float G_relcompare(float a, float b)
...


Do any of these sound useful?


-- 
Brad Douglas <rez at touchofmadness.com>




More information about the grass-dev mailing list