[GRASS-dev] dealing with nan
Glynn Clements
glynn at gclements.plus.com
Mon May 19 03:26:53 EDT 2008
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);
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>.
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).
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.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list