[GRASS-dev] Overflow warning in r.mapcalc calculation

Glynn Clements glynn at gclements.plus.com
Mon May 20 04:46:54 PDT 2013


Markus Metz wrote:

> > Happy to see this exchange of ideas. It would be great if this could be
> > implemented. Do you think it is useful I make a feature request on the bug
> > tracker (with link to this email thread) so the idea doesn't get lost?
> 
> Instead of
> 
> r.mapcalc "A = if(B==0,
> (round(C/0.0001)-1175699902)/(3007966667-1175699902) *100.0, 1)"
> --overwrite
> 
> try
> 
> r.mapcalc "A = if(B==0,
> (round(C/0.0001)-1175699902.0)/(3007966667.0-1175699902.0) *100.0, 1)"
> --overwrite
> 
> or better with whitespaces
> 
> r.mapcalc "A = if(B == 0, (round(C / 0.0001) - 1175699902.0) /
> (3007966667.0 - 1175699902.0) * 100.0, 1)" --overwrite
> 
> adding .0 to numbers forces all calculations to be done with  floating
> point double precision

That won't help; the problem is that round() returns an integer.

It wouldn't be particularly hard to change it so that the return type
is the same as the argument type, but that might break existing
scripts.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list