[Issue 12234] New: BigInt both >0 and ==0

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Feb 23 14:56:55 PST 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 at puremagic.com
        ReportedBy: killebrew.daniel at gmail.com


--- Comment #0 from Daniel Killebrew <killebrew.daniel at 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: -------


More information about the Digitalmars-d-bugs mailing list