[Issue 7973] New: BigInt %= long/ulong gives wrong value
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Apr 23 04:22:34 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7973
Summary: BigInt %= long/ulong gives wrong value
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: smjg at iname.com
--- Comment #0 from Stewart Gordon <smjg at iname.com> 2012-04-23 04:23:34 PDT ---
import std.stdio, std.bigint;
void main() {
const mod = 10_000_000_000_000_000;
pragma(msg, typeof(mod));
BigInt value = 2551700137;
writefln("%d", value);
writefln("%d", mod);
value %= mod;
writefln("%d", value);
}
----------
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd bigint_mod.d
const(long)
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>bigint_mod
2551700137
10000000000000000
676780713
----------
Interestingly, if I %= a long or ulong literal or non-const variable instead, I
get
----------
d:\dmd2\windows\bin\..\..\src\phobos\std\bigint.d(163): Error: static assert
(true && false) is false
bigint_mod.d(10): instantiated from here: opOpAssign!("%",ulong)
----------
and looking at bigint.d I see
static assert(!is(T==long) && !is(T==ulong));
so it appears that doing %= on a long/ulong has been deliberately disabled
pending getting it working properly, but const/immutable long/ulong has been
overlooked in doing so.
Since BigInt %= BigInt seems to work correctly, how about making it construct a
BigInt from the long/ulong and using that? It can later be replaced with an
implementation optimised to long/ulong once that has been written and tested.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list