Thread overview
[Issue 1892] New: min and max work improperly for mixed-sign numbers
Mar 04, 2008
d-bugmail
Mar 04, 2008
Bill Baxter
Mar 07, 2008
d-bugmail
March 04, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1892

           Summary: min and max work improperly for mixed-sign numbers
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: andrei@metalanguage.com
        ReportedBy: andrei@metalanguage.com


(From a post by bearophile.)

void main() {
    int a = -10;
    uint b = 10;
    writefln( min(a, b) );
}

prints 10 as per the infamous "uint rot" that transforms everything touched by uint an uint as well.

Not sure what the right solution is - either (a) fix CommonType to yield no
common type for int and uint, (b) fix CommonType to yield long for those two,
(c) leverage the semantics of min to yield int whenever the min of an int an
uint is taken, (d) something else?


-- 

March 04, 2008
d-bugmail@puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=1892
> 
>            Summary: min and max work improperly for mixed-sign numbers
>            Product: D
>            Version: unspecified
>           Platform: PC
>         OS/Version: Linux
>             Status: NEW
>           Severity: normal
>           Priority: P2
>          Component: DMD
>         AssignedTo: andrei@metalanguage.com
>         ReportedBy: andrei@metalanguage.com
> 
> 
> (From a post by bearophile.)
> 
> void main() {
>     int a = -10;
>     uint b = 10;
>     writefln( min(a, b) );
> }
> 
> prints 10 as per the infamous "uint rot" that transforms everything touched by
> uint an uint as well.
> 
> Not sure what the right solution is - either (a) fix CommonType to yield no
> common type for int and uint, (b) fix CommonType to yield long for those two,
> (c) leverage the semantics of min to yield int whenever the min of an int an
> uint is taken, (d) something else?
> 
> 


So you *do* still read the newsgroups.  ;-)

--bb
March 07, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1892


andrei@metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #1 from andrei@metalanguage.com  2008-03-07 00:27 -------
Fixed in 2.012.


--