D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4810 - dotProduct problem with ints
Summary: dotProduct problem with ints
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2010-09-04 06:18 UTC by bearophile_hugs
Modified: 2010-09-04 08:06 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 bearophile_hugs 2010-09-04 06:18:42 UTC
With DMD 2.048 this dotProduct doesn't work:

import std.numeric;
void main() {
    assert(dotProduct([1, 3, -5], [4, -2, -1]) == 3);
}



This is the first part of dotProduct:

Unqual!(CommonType!(F1, F2))
dotProduct(F1, F2)(in F1[] avector, in F2[] bvector)
{
    immutable n = avector.length;
    assert(n == bvector.length);
    auto avec = avector.ptr, bvec = bvector.ptr;
    typeof(return) sum0 = 0.0, sum1 = 0.0;


To fix it replace this:
typeof(return) sum0 = 0.0, sum1 = 0.0;

With:
typeof(return) sum0 = 0, sum1 = 0;
Comment 1 David Simcha 2010-09-04 08:06:57 UTC
http://dsource.org/projects/phobos/changeset/1953