[GRASS-dev] Overflow warning in r.mapcalc calculation
Markus Metz
markus.metz.giswork at gmail.com
Fri May 17 13:57:07 PDT 2013
On Fri, May 17, 2013 at 5:13 PM, Paulo van Breugel
<p.vanbreugel at gmail.com> wrote:
> Hi Glynn and Rainer
>
> 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
Markus M
>
>
>
>
> On Fri, May 17, 2013 at 4:38 PM, Glynn Clements <glynn at gclements.plus.com>
> wrote:
>>
>>
>> Rainer M. Krug wrote:
>>
>> > > One option is to modify round() to take a second argument (defaulting
>> > > to 1), and have it return the first argument rounded to the nearest
>> > > multiple of the second. The return type would be that of the second
>> > > argument, i.e. round(x,1) rounds to the nearest integer and returns an
>> > > integer, round(x,1.0) rounds to the nearest integer and returns a
>> > > float, round(x,1e-3) would round to 3 decimal places (i.e. the nearest
>> > > multiple of 0.001), etc.
>> >
>> > Sounds like a sensible approach without adding to many new
>> > functions. But I would actually split the two, i.e. have two more
>> > arguments, where one specifies the type,
>> > and the other one the number of decimals to round to, i.e.
>> >
>> > round(x, 0, "I") would be the default, rounding to whole number and
>> > return an integer
>>
>> That interface isn't possible. r.mapcalc doesn't have a string type,
>> and there's no way that a function's return type can depend upon the
>> value of a parameter.
>>
>> --
>> Glynn Clements <glynn at gclements.plus.com>
>> _______________________________________________
>> grass-dev mailing list
>> grass-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/grass-dev
>
>
>
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-dev
More information about the grass-dev
mailing list