digitalmars.D.bugs - [Issue 293] New: Expression uint.max + 1 yields 0 (zero)
- d-bugmail puremagic.com (23/23) Aug 17 2006 http://d.puremagic.com/issues/show_bug.cgi?id=293
- Oskar Linde (5/33) Aug 17 2006 This is not a bug. Look under Integer Promotions on
- BCS (3/42) Aug 17 2006 Shouldn't the bug be the overflow in the constant folding? I would hope
- d-bugmail puremagic.com (10/10) Aug 17 2006 http://d.puremagic.com/issues/show_bug.cgi?id=293
- d-bugmail puremagic.com (6/9) Aug 17 2006 http://d.puremagic.com/issues/show_bug.cgi?id=293
- d-bugmail puremagic.com (7/7) Aug 17 2006 http://d.puremagic.com/issues/show_bug.cgi?id=293
- d-bugmail puremagic.com (4/4) Aug 17 2006 http://d.puremagic.com/issues/show_bug.cgi?id=293
http://d.puremagic.com/issues/show_bug.cgi?id=293
Summary: Expression uint.max + 1 yields 0 (zero)
Product: D
Version: 0.164
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla digitalmars.com
ReportedBy: m.faustino gmail.com
The expression uint.max + 1, yields 0 (zero). For example, the following code
will print "4294967296 == 0":
//----------------------------------------------------------
import std.stdio;
void main()
{
ulong u = uint.max;
writefln(u + 1, " == ", uint.max + 1);
}
//----------------------------------------------------------
--
Aug 17 2006
d-bugmail puremagic.com wrote:
http://d.puremagic.com/issues/show_bug.cgi?id=293
Summary: Expression uint.max + 1 yields 0 (zero)
Product: D
Version: 0.164
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla digitalmars.com
ReportedBy: m.faustino gmail.com
The expression uint.max + 1, yields 0 (zero). For example, the following code
will print "4294967296 == 0":
//----------------------------------------------------------
import std.stdio;
void main()
{
ulong u = uint.max;
writefln(u + 1, " == ", uint.max + 1);
}
//----------------------------------------------------------
This is not a bug. Look under Integer Promotions on
http://www.digitalmars.com/d/type.html
type type of (uint) + (int) is (uint), not (ulong)
/Oskar
Aug 17 2006
Oskar Linde wrote:d-bugmail puremagic.com wrote:Shouldn't the bug be the overflow in the constant folding? I would hope that the DMD would error on overflows in constant expressions.http://d.puremagic.com/issues/show_bug.cgi?id=293 Summary: Expression uint.max + 1 yields 0 (zero) Product: D Version: 0.164 Platform: PC OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: m.faustino gmail.com The expression uint.max + 1, yields 0 (zero). For example, the following code will print "4294967296 == 0": //---------------------------------------------------------- import std.stdio; void main() { ulong u = uint.max; writefln(u + 1, " == ", uint.max + 1); } //----------------------------------------------------------This is not a bug. Look under Integer Promotions on http://www.digitalmars.com/d/type.html type type of (uint) + (int) is (uint), not (ulong) /Oskar
Aug 17 2006
http://d.puremagic.com/issues/show_bug.cgi?id=293
bugzilla digitalmars.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
That's how fixed precision integer arithmetic works when it overflows. Not a
bug.
--
Aug 17 2006
http://d.puremagic.com/issues/show_bug.cgi?id=293That's how fixed precision integer arithmetic works when it overflows. Not a bug.So why (u + 1) doesn't overflow when (uint.max + 1) does? In the code I wrote, aren't those two expressions semantically equivalent? --
Aug 17 2006
http://d.puremagic.com/issues/show_bug.cgi?id=293 u+1 adds 1 to a ulong, which does not overflow because it's a 64 bit type which is large enough to represent 4294967296. uint.max+1 is a uint, which does overflow because it's a 32 bit type and not large enough to hold 4294967296. The expressions are not semantically equivalent. --
Aug 17 2006
http://d.puremagic.com/issues/show_bug.cgi?id=293 Ok, thanks. Sorry for the false bug report though. --
Aug 17 2006









BCS <BCS pathlink.com> 