[GRASS5] Re: [GRASS_DE] r.mapcalc round()

Markus Neteler neteler at geog.uni-hannover.de
Tue May 15 09:52:14 EDT 2001


Hi Dieter,

(cc to grass5)

On Tue, May 15, 2001 at 03:01:36PM +0200, Dieter Lehmann wrote:
> Hi,
> 
> r.mapcalc test='float(x)/10'
> results in something like 0.0200000002.

what are the contents of "x"?

> I need to round. The function round() in mapcalc gives only the next integer.
> 
> My problem might be solved in mapcalc or in r.stats (I need to export the
> values through r.stats -1 test).

However, something is odd with r.mapcalc in my opinion:

r.mapcalc x1=1.4
EXECUTING x1 = ...  100%
CREATING SUPPORT FILES FOR x1
range: 1.3999999762 1.3999999762

r.stats x1
r.stats:  100%
1.4-1.4

but:
r.stats -1 x1
1.3999999762
1.3999999762
1.3999999762
1.3999999762
1.3999999762
[...]

 -> not what I expect.


r.univar x1
[...]
Minimum: 1.3999999762
Maximum: 1.3999999762
Range:  0
Arithmetic Mean:  1.4
Variance:  -2.49502e-12
awk: cmd. line:17: (FILENAME=- FNR=18894) warning: sqrt called with negative argument -2.49502e-12
Standarddeviation: nan

-> huh!

r.mapcalc x2=1.6
EXECUTING x2 = ...  100%
CREATING SUPPORT FILES FOR x2
range: 1.6000000238 1.6000000238

-> does not look very impressive.

r.mapcalc x0=1  
EXECUTING x0 = ...  100%
CREATING SUPPORT FILES FOR x0
range: 1 1

-> o.k.

Starting to round:
r.mapcalc x1round="round(x1)"
EXECUTING x1round = ...  100%
CREATING SUPPORT FILES FOR x1round
range: 1 1
 -> rounding is o.k.

r.mapcalc x2round="round(x2)"
EXECUTING x2round = ...  100%
CREATING SUPPORT FILES FOR x2round
range: 2 2
 -> rounding is o.k.

r.mapcalc x3="1.6 + 1."
EXECUTING x3 = ...  100%
CREATING SUPPORT FILES FOR x3
range: 2.5999999046 2.5999999046
 -> huh?

Perhaps someone could explain this behaviour. Or is it a precision bug?

Markus

---------------------------------------- 
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo at geog.uni-hannover.de with
subject 'unsubscribe grass5'



More information about the grass-dev mailing list