Bug 4874 – std.numeric.dotProduct doesn't work with bigints

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-09-15T14:17:00Z
Last change time
2013-11-18T02:24:37Z
Assigned to
clugdbug
Creator
bearophile_hugs
Depends on
4301, 4872

Comments

Comment #0 by bearophile_hugs — 2010-09-15T14:17:17Z
With dmd 2.049beta this code compiles (but first see bug 4872 too): // program #1 import std.bigint; T dotProduct2(T)(/*in*/ T[] a1, /*in*/ T[] a2) { assert(a1.length == a2.length); T total = 0; foreach (i; 0 .. a1.length) total += a1[i] * a2[i]; return total; } void main() { BigInt[] a1 = [BigInt(1), BigInt(3), BigInt(-5)]; BigInt[] a2 = [BigInt(4), BigInt(-2), BigInt(-1)]; BigInt r = dotProduct2(a1, a2); } But the std.numeric.dotProduct() can't be used with bigints: // program #2 import std.numeric, std.bigint; void main() { BigInt[] a1 = [BigInt(1), BigInt(3), BigInt(-5)]; BigInt[] a2 = [BigInt(4), BigInt(-2), BigInt(-1)]; assert(dotProduct(a1, a2) == BigInt(3)); } If in program #1 arguments are "in" it doesn't compile.
Comment #1 by clugdbug — 2010-09-15T15:11:49Z
That's the same issue as 4301. BigInt isn't yet const-correct.
Comment #2 by andrei — 2013-03-10T19:20:19Z
Assigning to Don.
Comment #3 by simen.kjaras — 2013-11-07T00:09:21Z
Comment #4 by bearophile_hugs — 2013-11-18T02:24:37Z