Thread overview
[Issue 12234] New: BigInt both >0 and ==0
Feb 23, 2014
Daniel Killebrew
Feb 24, 2014
Daniel Killebrew
Feb 24, 2014
safety0ff.bugz
February 23, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12234

           Summary: BigInt both >0 and ==0
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: killebrew.daniel@gmail.com


--- Comment #0 from Daniel Killebrew <killebrew.daniel@gmail.com> 2014-02-23 14:56:51 PST ---
There seems to be a bug in BigInt where a value==0, but value>0==true.

import std.stdio;
import std.bigint;

void main() {
  {
    //works
    BigInt evil = 107;
    int counter;
    while (evil != 0){
      evil /= 10;
    }
  }

  {
    //fails
    BigInt evil = 107;
    int counter;
    while (evil > 0){
      evil /= 10;

      ++counter;
      if(counter > 5) {
        assert(evil == 0);
        throw new Exception("evil==0, but we're still looping, so evil>0...
this doesn't make sense");
      }
    }
  }
}

The code will throw the exception. The evil==0 comparison works as expected. The evil>0 comparison gives a wrong answer.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 24, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12234


Daniel Killebrew <killebrew.daniel@gmail.com> changed:

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


--- Comment #1 from Daniel Killebrew <killebrew.daniel@gmail.com> 2014-02-23 16:17:27 PST ---
Actually, it looks like this has been fixed in Phobos master. https://github.com/D-Programming-Language/phobos/blob/master/std/internal/math/biguintcore.d#L220

However, I will submit a pull request with unittest for this case, to prevent regression.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 24, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12234


safety0ff.bugz <safety0ff.bugz@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |safety0ff.bugz@gmail.com
         Resolution|INVALID                     |DUPLICATE


--- Comment #2 from safety0ff.bugz <safety0ff.bugz@gmail.com> 2014-02-23 17:43:48 PST ---
See bug report #11583 for the commit & PR that fixed this. The unit test should already be there to prevent regression.

*** This issue has been marked as a duplicate of issue 11583 ***

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 14, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12234



--- Comment #3 from github-bugzilla@puremagic.com 2014-03-14 01:45:53 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/30999e7dc15945183a06c9cbf9bf8464704cadcb Add unittests: compare BigUint(0) to 0UL

to prevent regression of bug 12234.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------