[GRASS-dev] How to: if undefined, set to NULL?

Vaclav Petras wenzeslaus at gmail.com
Sun Sep 4 14:39:43 PDT 2016


On Sun, Sep 4, 2016 at 9:45 AM, Nikos Alexandris <nik at nikosalexandris.net>
wrote:

> Updated in sandbox, see: https://trac.osgeo.org/grass/changeset/69365
>
> Is it though correct?
>

I was not looking at the logic but

if (hue == -1.0) {

is not safe. Although it will probably work most of the time if you set it
to the exactly same value (`hue = -1;`), but it is not portable because it
is exact comparison for floats/doubles. Generally, you need to do something
like

if (fabs(hue - (-1.0)) < GRASS_EPSILON) {

However, here it might be more appropriate to signal the good or bad state
of hue by some other variable:

hue_good = FALSE;

/* setting hue here together with hue_good = TRUE */

if (!hue_good) {

/* do the null set */

Also, it seems that the code is not consistent with FCELL versus DCELL. I
can see DCELL *rowbuffer and Rast_is_d_null_value but also
(FCELL)saturation as well as floats and doubles. Since the input claims to
be always DCELL, use DCELL/double everywhere.

Related to that, although I'm never sure about where is its appropriate to
use DCELL and where double (DCELL currently gets evaluated to double:
typedef double DCELL;). I would probably use DCELL everywhere in this
function; just to make it clear that we deal purely with cell values and
there is no need to switch to anything else.

And of course, congrats and kudos for your C efforts, Nikos!

Vaclav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20160904/d85e2a68/attachment.html>


More information about the grass-dev mailing list