Details Ticket 3967


Comment | Reply | Take | Open


Serial Number 3967
Subject Undocumented: max() returns integer values if at least one argument is an int
Area grass6
Queue grass
Requestors david.p.finlayson@gmail.com
Owner none
Status resolved
Last User Contact Mon Jan 9 18:16:55 2006 (3 yr ago)
Current Priority 30
Final Priority 70
Due No date assigned
Last Action Tue Jan 10 09:42:14 2006 (3 yr ago)
Created Sun Jan 8 20:42:41 2006 (3 yr ago)

Transaction History Ticket 3967


Sun, Jan 8 2006 20:42:41    Request created by guest  
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
Mon, Jan 9 2006 11:27:53    Mail sent by glynn@gclements.plus.com  
Return-Path <glynn@gclements.plus.com>
Delivered-To grass-bugs@lists.intevation.de
From Glynn Clements <glynn@gclements.plus.com>
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
Message-ID <17346.15012.131024.27914@cerise.gclements.plus.com>
Date Mon, 9 Jan 2006 10:27:48 +0000
To Request Tracker <grass-bugs@intevation.de>
Cc grass5@grass.itc.it
Subject Re: [GRASS5] [bug #3967] (grass) Undocumented: max() returns integer values if at least one argument is an int
In-Reply-To <20060108194241.B1F7F1006B1@lists.intevation.de>
References <20060108194241.B1F7F1006B1@lists.intevation.de>
X-Mailer VM 7.07 under 21.4 (patch 15) "Security Through Obscurity" XEmacs Lucid
X-Spam-Status No, hits=-4.9 tagged_above=-999.0 required=3.0 tests=BAYES_00
X-Spam-Level
Request Tracker wrote:

> 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!

Actually, it return type is the same is its first argument.

> example:
> 
> r.mapcalc "temp1 = 0"  # CELL
> r.mapcalc "temp2 = 0.1"  # FCELL

Actually, this is DCELL; you would need to use "0.1f" or "float(0.1)"
to get FCELL.

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

r.mapcalc "temp5 = max(temp2, temp1)" # Returns 0.1!

> This is confusing. I suppose this is a C library thing.

No, it's a bug:

--- raster/r.mapcalc/check.c~	2004-11-09 13:45:12.000000000 +0000
+++ raster/r.mapcalc/check.c	2006-01-09 10:19:38.000000000 +0000
@@ -99,11 +99,11 @@
 	argt[0] = CELL_TYPE;
 
 	for (i = 1; i <= argc; i++)
-		if (argt[1] == FCELL_TYPE)
+		if (argt[i] == FCELL_TYPE)
 			argt[0] = FCELL_TYPE;
 
 	for (i = 1; i <= argc; i++)
-		if (argt[1] == DCELL_TYPE)
+		if (argt[i] == DCELL_TYPE)
 			argt[0] = DCELL_TYPE;
 
 	for (i = 1; i <= argc; i++)

FWIW, this applies to max, min, median and mode (all of the functions
which take a variable number of arguments where the result type should
be the most general of the argument types).

> 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

That's how it was /supposed/ to behave.

Fixed in CVS.

-- 
Glynn Clements <glynn@gclements.plus.com>


Mon, Jan 9 2006 11:38:37    Mail sent by neteler@itc.it  
Return-Path <neteler@itc.it>
Delivered-To grass-bugs@lists.intevation.de
Date Mon, 9 Jan 2006 11:38:31 +0100
From Markus Neteler <neteler@itc.it>
To Glynn Clements <glynn@gclements.plus.com>
Cc Request Tracker <grass-bugs@intevation.de>, grass5@grass.itc.it
Subject Re: [GRASS5] [bug #3967] (grass) Undocumented: max() returns integer values if at least one argument is an int
Message-ID <20060109103831.GC2968@bartok.itc.it>
Mail-Followup-To Glynn Clements <glynn@gclements.plus.com>, Request Tracker <grass-bugs@intevation.de>, grass5@grass.itc.it
References <20060108194241.B1F7F1006B1@lists.intevation.de> <17346.15012.131024.27914@cerise.gclements.plus.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
In-Reply-To <17346.15012.131024.27914@cerise.gclements.plus.com>
User-Agent Mutt/1.4.1i
X-PGP-Key http://www.gdf-hannover.de/neteler/markus_gpgkey.asc
X-Spam-Status No, hits=-4.9 tagged_above=-999.0 required=3.0 tests=BAYES_00
X-Spam-Level
On Mon, Jan 09, 2006 at 10:27:48AM +0000, Glynn Clements wrote:
> > 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 
...
> > Major fix: implicit promotion to float if either (any) raster is of
> > type float or double
> 
> That's how it was /supposed/ to behave.
> 
> Fixed in CVS.

Fixed also in 6.0.2-CVS.

Markus


Mon, Jan 9 2006 16:46:26    Status changed to resolved by msieczka  
Mon, Jan 9 2006 16:46:26    Mail sent by msieczka  
Closing it.

Maciek
Mon, Jan 9 2006 18:16:55    Mail sent by dfinlays@u.washington.edu  
Return-Path <david.p.finlayson@gmail.com>
Delivered-To grass-bugs@lists.intevation.de
DomainKey-Signature a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=eSyyroj3fPC4JHaOloIe+W5wd6nkDyOJKcEW12NjBzp9oKURMr6d4u+sGQ+6QxcgDUGuUeYFnIaetA9xJqNuQqnqro0cj6DMRfDaJRwlcgSGMyDSXEz6PGfENPnl8LsgJQrKqGtKA7MWEYa5pElix+n606U+US6ptmtgtxiXsls=
Message-ID <be6d1720601090916o2adc7621l15735551d5b9a6ad@mail.gmail.com>
Date Mon, 9 Jan 2006 09:16:48 -0800
From David Finlayson <dfinlays@u.washington.edu>
Reply-To dfinlays@u.washington.edu
Sender david.p.finlayson@gmail.com
To Glynn Clements via RT <grass-bugs@intevation.de>
Subject Re: [bug #3967] (grass) Undocumented: max() returns integer values if at least one argument is an int
In-Reply-To <20060109102754.0439D1006B1@lists.intevation.de>
MIME-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Content-Disposition inline
References <20060109102754.0439D1006B1@lists.intevation.de>
X-Spam-Status No, hits=-4.9 tagged_above=-999.0 required=3.0 tests=BAYES_00
X-Spam-Level
Thanks, I'll check it out.

David

On 1/9/06, Glynn Clements via RT <grass-bugs@intevation.de> wrote:
>
> Request Tracker wrote:
>
> > this bug's URL: http://intevation.de/rt/webrt?serial_num=3D3967
> > -----------------------------------------------------------------------=
--
> >
> > Subject: Undocumented: max() returns integer values if at least one arg=
ument 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!
>
> Actually, it return type is the same is its first argument.
>
> > example:
> >
> > r.mapcalc "temp1 =3D 0"  # CELL
> > r.mapcalc "temp2 =3D 0.1"  # FCELL
>
> Actually, this is DCELL; you would need to use "0.1f" or "float(0.1)"
> to get FCELL.
>
> > r.mapcalc "temp3 =3D max(temp1, temp2)"   # Returns 0!
> > r.mapcalc "temp4 =3D max(float(temp1), temp2)" # Returns 0.1!
>
> r.mapcalc "temp5 =3D max(temp2, temp1)" # Returns 0.1!
>
> > This is confusing. I suppose this is a C library thing.
>
> No, it's a bug:
>
> --- raster/r.mapcalc/check.c~   2004-11-09 13:45:12.000000000 +0000
> +++ raster/r.mapcalc/check.c    2006-01-09 10:19:38.000000000 +0000
> @@ -99,11 +99,11 @@
>         argt[0] =3D CELL_TYPE;
>
>         for (i =3D 1; i <=3D argc; i++)
> -               if (argt[1] =3D=3D FCELL_TYPE)
> +               if (argt[i] =3D=3D FCELL_TYPE)
>                         argt[0] =3D FCELL_TYPE;
>
>         for (i =3D 1; i <=3D argc; i++)
> -               if (argt[1] =3D=3D DCELL_TYPE)
> +               if (argt[i] =3D=3D DCELL_TYPE)
>                         argt[0] =3D DCELL_TYPE;
>
>         for (i =3D 1; i <=3D argc; i++)
>
> FWIW, this applies to max, min, median and mode (all of the functions
> which take a variable number of arguments where the result type should
> be the most general of the argument types).
>
> > In the scripting languages I use, the cast to float is implicit in thes=
e
> > 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
>
> That's how it was /supposed/ to behave.
>
> Fixed in CVS.
>
> --
> Glynn Clements <glynn@gclements.plus.com>
>
>
> --- Headers Follow ---
>
> >From glynn@gclements.plus.com  Mon Jan  9 11:27:53 2006
> Return-Path: <glynn@gclements.plus.com>
> Delivered-To: grass-bugs@lists.intevation.de
> Received: from mail.intevation.de (aktaia [212.95.126.10])
>         by lists.intevation.de (Postfix) with ESMTP id B55DC1006AE
>         for <grass-bugs@lists.intevation.de>; Mon,  9 Jan 2006 11:27:53 +=
0100 (CET)
> Received: from localhost (localhost [127.0.0.1])
>         by mail.intevation.de (Postfix) with ESMTP id 46FC836D89
>         for <grass-bugs@lists.intevation.de>; Mon,  9 Jan 2006 11:27:53 +=
0100 (CET)
> Received: from cerise.gclements.plus.com (82-71-30-52.dsl.in-addr.zen.co.=
uk [82.71.30.52])
>         by mail.intevation.de (Postfix) with ESMTP id 49FA336D7F
>         for <grass-bugs@intevation.de>; Mon,  9 Jan 2006 11:27:50 +0100 (=
CET)
> Received: from cerise.gclements.plus.com (localhost [127.0.0.1])
>         by cerise.gclements.plus.com (8.13.4/8.13.4) with ESMTP id k09ARm=
J8028479;
>         Mon, 9 Jan 2006 10:27:48 GMT
> Received: (from glynn@localhost)
>         by cerise.gclements.plus.com (8.13.4/8.13.4/Submit) id k09ARmhJ02=
8476;
>         Mon, 9 Jan 2006 10:27:48 GMT
> From: Glynn Clements <glynn@gclements.plus.com>
> MIME-Version: 1.0
> Content-Type: text/plain; charset=3Dus-ascii
> Content-Transfer-Encoding: 7bit
> Message-ID: <17346.15012.131024.27914@cerise.gclements.plus.com>
> Date: Mon, 9 Jan 2006 10:27:48 +0000
> To: Request Tracker <grass-bugs@intevation.de>
> Cc: grass5@grass.itc.it
> Subject: Re: [GRASS5] [bug #3967] (grass) Undocumented: max() returns int=
eger values if at least one argument is an int
> In-Reply-To: <20060108194241.B1F7F1006B1@lists.intevation.de>
> References: <20060108194241.B1F7F1006B1@lists.intevation.de>
> X-Mailer: VM 7.07 under 21.4 (patch 15) "Security Through Obscurity" XEma=
cs Lucid
> X-Spam-Status: No, hits=3D-4.9 tagged_above=3D-999.0 required=3D3.0 tests=
=3DBAYES_00
> X-Spam-Level:
>
> -------------------------------------------- Managed by Request Tracker
>


--
David Finlayson
Marine Geology & Geophysics
School of Oceanography
Box 357940
University of Washington
Seattle, WA  98195-7940
USA

Office: Marine Sciences Building, Room 112
Phone: (206) 616-9407
Web: http://students.washington.edu/dfinlays


Mon, Jan 9 2006 18:16:55    Status changed to open by _rt_system  
Tue, Jan 10 2006 09:42:14    Status changed to resolved by msieczka  
Comment | Reply | Take | Open

You are currently authenticated as guest.
[Show Configuration] [Login as another user]

Users Guide - Mail Commands - Homepage of RequestTracker 1.0.7 - list any request