[GRASS-dev] [bug #4998] (grass) r.mapcalc rand (a, b): b-1 is used instead of b

Maciej Sieczka tutey at o2.pl
Mon Aug 14 07:06:32 EDT 2006


Glynn Clements napisa?(a):

> Request Tracker wrote:

>> $ r.mapcalc 'map=rand(1,100)'
>> $ r.info -r map
>> min=1
>> max=99
>>     ^
>>     |
>>   should be 100!

> The above is correct, although the documentation should be more
> explicit. The result of rand() is a pseudo-random value x such that:

> 	a <= x < b

> This definition results in consistent behaviour for both the integer
> and floating-point cases, as well as being consistent with most
> standard PRNG functions (which usually treat the upper bound as
> exclusive).

Is this really necessary? Isn't it counter intuitive?

>> $ r.mapcalc 'map=rand(1,1)'
>>    0%
>>    ^
>>    |
>>   no progress whatever, 100% CPU used
> 
> This might a compiler error, although it should handle this
> explicitly.
> 
> The above case will result in division by zero, typically causing
> SIGFPE to be thrown. r.mapcalc installs a signal handler for SIGFPE
> which sets a flag then returns. It appears that SIGFPE gets thrown
> continuously in this case.
> 
> I've fixed this error, and updated the documentation to clarify the
> behaviour.

Thank you!

Maciek




More information about the grass-dev mailing list