D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4470 - Problems with std.bigint mod and divide
Summary: Problems with std.bigint mod and divide
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-16 04:35 UTC by yebblies
Modified: 2010-09-20 08:50 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description yebblies 2010-07-16 04:35:08 UTC
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);
}
Comment 1 yebblies 2010-07-16 04:49:08 UTC
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);
}
Comment 2 yebblies 2010-07-16 04:53:41 UTC
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);
}
Comment 3 yebblies 2010-07-16 05:02:11 UTC
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 {}
		}
	}
}
Comment 4 Don 2010-07-16 23:28:43 UTC
Fixed svn 1764. The 'power of 2' bug was already fixed in svn 1673.