www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1892] New: min and max work improperly for mixed-sign numbers

reply d-bugmail puremagic.com writes:
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?


-- 
Mar 04 2008
next sibling parent Bill Baxter <dnewsgroup billbaxter.com> writes:
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
Mar 04 2008
prev sibling parent d-bugmail puremagic.com writes:
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.


-- 
Mar 06 2008