[GRASS-user] r.stats: negative cell counts and percentages
Glynn Clements
glynn at gclements.plus.com
Fri Oct 2 21:37:17 EDT 2009
Hamish wrote:
> Hamish wrote:
> > > I notice r.info uses unsigned long long + printf %llu
> > > Shall we standardize on that?
>
> Glynn wrote:
> > The main downside is that you can end up needing a lot of
> > conditional code.
>
> I'm not seeing any alternative though.
>
> For any module which does math with it (eg casting prior to
> variable multiplication/division), perhaps to save some noise in
> the code the LONGTYPE could be set up as a macro at the top
> of the file and then the casts should look like
> (LONGTYPE)chellhd.rows * cellhb*cols
I suggest adding the following (or something similar) to config.h:
#ifdef HAVE_LONG_LONG_INT
#define longest long long
#define PRILONGEST_PREFIX "ll"
#else
#define longest long
#define PRILONGEST_PREFIX "l"
#endif
#define PRIdLONGEST PRILONGEST_PREFIX "d"
#define PRIiLONGEST PRILONGEST_PREFIX "i"
#define PRIoLONGEST PRILONGEST_PREFIX "o"
#define PRIuLONGEST PRILONGEST_PREFIX "u"
#define PRIxLONGEST PRILONGEST_PREFIX "x"
#define PRIXLONGEST PRILONGEST_PREFIX "X"
I'm unsure whether it's better to use a macro or a typedef for the
type. Using a macro allows the use of "unsigned longest" rather than
requiring a separate typedef (e.g. "u_longest").
I have no particular preference as to the name of the macro/type, or
whether to use upper or lower case for a macro (a typedef should use
lower case).
The PRI* syntax is intended to mirror the C99 macros from
<inttypes.h>. The definition doesn't include the leading "%", so that
you can include flags, a field width and/or a precision.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list