[GRASS-dev] dealing with nan
Yann Chemin
yann.chemin at gmail.com
Mon May 19 03:37:21 EDT 2008
2008/5/19 Glynn Clements <glynn at gclements.plus.com>:
>
> Yann Chemin wrote:
>
> > I have some data that reads as "nan", while rare, it may happen when
> > compressing/uncompressing GRASS Locations to ship them across
> > Internet.
> >
> > I would like to know how to deal with them in GRASS raster
> > programming, so that they are:
> > 1 - detected
> > 2 - set to null
>
> if (x != x)
> G_set_d_null_value(&x, 1);
>
Sounds simple enough.
>
> There is also isnan(), which is in C99, and also specified by POSIX:
>
> http://www.opengroup.org/onlinepubs/009695399/functions/isnan.html
>
> However, I don't know if it exists on all platforms which we care
> about. MSDN says that MSVCRT has _isnan() (with a leading underscore),
> but it's defined in <float.h> rather than <math.h>.
>
hmm... ok
>
> The (x != x) test should be portable; OTOH, it's the kind of thing
> that compilers often get wrong, particularly when optimising (if you
> ignore NaN, x!=x is always false).
>
OK, this is a pickle... I'll give it a try and see what it does here.
>
> For 7.0, I intend to change G_is_[fd]_null_value() to treat all NaN
> values as null, not just the specific bit patterns which it currently
> uses.
>
This would be good indeed.
>
> --
> Glynn Clements <glynn at gclements.plus.com>
>
--
Yann Chemin
International Rice Research Institute
Office: http://www.irri.org/gis
Perso: http://www.freewebs.com/ychemin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-dev/attachments/20080519/76237156/attachment.html
More information about the grass-dev
mailing list