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.