Bug 12562 – std.algorithm.mul

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-04-11T21:32:00Z
Last change time
2016-12-24T15:27:12Z
Keywords
trivial
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-04-11T21:32:56Z
I suggest to add a function "mul" similar to std.algorithm.sum to std.algorithm that computes the product of the given range: void main() { import std.stdio, std.range, std.algorithm, std.bigint; reduce!((a, b) => a * b)(1, iota(1, 10)).writeln; // 362_880 iota(1, 10).mul.writeln; // The same result. iota(1, 10).mul(1.0).writeln; // The same result, but of type double. BigInt[] a; a.mul.writeln; // Should print 1 }
Comment #1 by saurabh.das — 2015-11-12T06:46:20Z
std.algorithm.sum differs from reduce!((a, b) => a + b) in that it uses a different algorithm for floating-point types to reduce the round-off error. As far as I understand, multiplication of floating-point types does not suffer from the same problem. (Or does it?) Do you have any special case algorithms you would like to implement for std.algorithm.mul in mind? If it is simply a forward to reduce!((a, b) => a * b), then is it a big enough convenience to be included into phobos? I have been trying to make some time to contribute back to Dlang and this seems like the perfect, nice and easy issue, to dip my toe into the phobos-contributor waters! :)
Comment #2 by bearophile_hugs — 2015-11-12T09:45:49Z
(In reply to Saurabh Das from comment #1) > Do you have any special case algorithms you would like to implement for > std.algorithm.mul in mind? I don't have anything special in mind.
Comment #3 by greeenify — 2016-12-23T17:16:23Z
If someone starts with this, he should read the comment at the cumulativeSum discussion: https://github.com/dlang/phobos/pull/4881#issuecomment-259489117
Comment #4 by andrei — 2016-12-24T15:27:12Z
Doesn't seem this warrants a special function.