product#

Multiply every value in the list and return the numerical product.

Synopsis#

my $p = product @values;
my $p = product 1..10;           # 3628800

What you get back#

A single number. Integer overflow is promoted to floating point transparently, so the result is an integer as long as the exact product fits in an IV. An empty list yields 1 (the multiplicative identity).

Examples#

my $n = product 3, 9, 12;        # 324
my $n = product();               # 1
my $n = product map { $_->weight } @items;

Differences from upstream#

Fully compatible with upstream.

See also#

  • sum — additive counterpart.

  • sum0 — additive counterpart that mirrors product’s identity-element behaviour on empty input.

  • reduce — the generic reduction when product is not specific enough.