[GRASS5] [bug #3967] (grass) Undocumented: max() returns integer values if at least one argument is an int

Request Tracker grass-bugs at intevation.de
Sun Jan 8 14:42:41 EST 2006


this bug's URL: http://intevation.de/rt/webrt?serial_num=3967
-------------------------------------------------------------------------

Subject: Undocumented: max() returns integer values if at least one argument is an int 

Platform: GNU/Linux/i386
grass obtained from: CVS
grass binary for platform: Compiled from Sources
GRASS Version: GRASS 6.1.cvs checked out 20050106

According to the r.mapcalc documentation page, max() returns a float if any of its arguments are floats. In fact, map() returns an integer result if any of its arguments are integers!

example:

r.mapcalc "temp1 = 0"  # CELL
r.mapcalc "temp2 = 0.1"  # FCELL
r.mapcalc "temp3 = max(temp1, temp2)"   # Returns 0!
r.mapcalc "temp4 = max(float(temp1), temp2)" # Returns 0.1!

This is confusing. I suppose this is a C library thing. In the scripting languages I use, the cast to float is implicit in these situations.

Minor fix: update the docs to make clear the behavior
Major fix: implicit promotion to float if either (any) raster is of type float or double

David

-------------------------------------------- Managed by Request Tracker




More information about the grass-dev mailing list