Thread overview
[Issue 4470] New: Problems with std.bigint mod and divide
Jul 16, 2010
yebblies
Jul 16, 2010
yebblies
Jul 16, 2010
yebblies
Jul 16, 2010
yebblies
Jul 17, 2010
Don
Sep 20, 2010
Don
July 16, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4470

           Summary: Problems with std.bigint mod and divide
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: yebblies@gmail.com


--- Comment #0 from yebblies <yebblies@gmail.com> 2010-07-16 04:35:08 PDT ---
With the version of std.bigint packaged with dmd2.047 (on winxp / x86)

1. You get 'object.Error: Win32 Exception'
   when attempting any BigInt % BigInt(1) or BigInt % 1.

Test case:

import std.bigint;
void main()
{
  auto r1 = BigInt(6) % 1;
  auto r2 = BigInt(6) % BigInt(1);
}

2. BigInt % BigInt(0) seems to go into an infinite loop

import std.bigint;
void main()
{
  auto r = BigInt(6) % BigInt(0);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 16, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4470



--- Comment #1 from yebblies <yebblies@gmail.com> 2010-07-16 04:49:08 PDT ---
The following tests should succeed when this issue has been fixed:

unittest
{
    try
    {
        scope(success) assert(0);
        auto r1 = BigInt(6) % BigInt(0);
    } catch {}
    try
    {
        scope(success) assert(0);
        auto r1 = BigInt(6) % 0;
    } catch {}
    assert(BigInt(6) % BigInt(1) == 1);
    assert(BigInt(6) % 1 == 1);
    assert(BigInt(-6) % BigInt(-1) == -1);
    assert(BigInt(-6) % -1 == -1);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 16, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4470



--- Comment #2 from yebblies <yebblies@gmail.com> 2010-07-16 04:53:41 PDT ---
My bad!  That should be:

unittest
{
    try
    {
        scope(success) assert(0);
        auto r1 = BigInt(6) % BigInt(0);
    } catch {}
    try
    {
        scope(success) assert(0);
        auto r1 = BigInt(6) % 0;
    } catch {}
    assert(BigInt(6) % BigInt(1) == 0);
    assert(BigInt(6) % 1 == 0);
    assert(BigInt(-6) % BigInt(-1) == 0);
    assert(BigInt(-6) % -1 == 0);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 16, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4470



--- Comment #3 from yebblies <yebblies@gmail.com> 2010-07-16 05:02:11 PDT ---
This seems to crash with every power of two, int or BigInt.

import std.bigint;
void main()
{
    foreach(a; 0..1000)
    {
        foreach(b; 0..1000)
        {
            try
            {
                scope(failure) writeln(a, " % ", b, " failed");
                auto x = BigInt(a) % b;
            } catch {}
            try
            {
                scope(failure) writeln(a, " % BigInt(", b, ") failed");
                auto x = BigInt(a) % BigInt(b);
            } catch {}
        }
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 17, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4470


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #4 from Don <clugdbug@yahoo.com.au> 2010-07-16 23:28:43 PDT ---
Fixed svn 1764. The 'power of 2' bug was already fixed in svn 1673.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 20, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4470


Don <clugdbug@yahoo.com.au> changed:

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


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