Bug 12234 – BigInt both >0 and ==0

Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-02-23T14:56:00Z
Last change time
2014-03-14T01:45:53Z
Assigned to
nobody
Creator
killebrew.daniel

Comments

Comment #0 by killebrew.daniel — 2014-02-23T14:56:51Z
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.
Comment #1 by killebrew.daniel — 2014-02-23T16:17:27Z
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.
Comment #2 by safety0ff.bugz — 2014-02-23T17:43:48Z
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 ***
Comment #3 by github-bugzilla — 2014-03-14T01:45:53Z
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.