[GRASS-dev] [GRASS GIS] #1976: r.mapcalc: Allow rounding of floating numbers

GRASS GIS trac at osgeo.org
Wed May 22 12:58:30 PDT 2013

#1976: r.mapcalc: Allow rounding of floating numbers
 Reporter:  pvanbosgeo   |       Owner:  grass-dev@…              
     Type:  enhancement  |      Status:  new                      
 Priority:  normal       |   Milestone:  7.0.0                    
Component:  Raster       |     Version:  unspecified              
 Keywords:  r.mapcalc    |    Platform:  Unspecified              
      Cpu:  Unspecified  |  

Comment(by glynn):

 Replying to [comment:4 glynn]:

 > Unless someone has a better idea, I plan to change the round() function
 so that the second argument is the step value,

 Done in r56365. An optional third argument is the start value, so e.g.
 round(x,1.0,0.5) will round to the nearest something-point-five value.

 > and add an roundi() (round-inverse) function where the second argument
 is the reciprocal of the step value (to avoid the rounding error when
 using a step of 10^-N^).

 I haven't bothered with this. If the step value can't be represented
 exactly, then in the general case, neither can the rounded value. If it's
 desired, it would be better to clone xround.c and modify the i_round()
 function (swap the multiplication and division) than to try to get yet
 another case into that file.

 Rounding to a given number of decimal places (as opposed to rounding to a
 multiple of 10^-N^) is something which really needs to be done during
 conversion to a string. Attempting to round a floating-point value to a
 given number of decimal places will inevitably add rounding errors which
 may be visible if the value is subsequently converted to a string using
 sufficient precision.

Ticket URL: <http://trac.osgeo.org/grass/ticket/1976#comment:6>
GRASS GIS <http://grass.osgeo.org>

More information about the grass-dev mailing list