Skip to content
Prev 28471 / 63468 Next

prod(0, 1:1000) ; 0 * Inf etc

I definitely do agree with you.
Basically, I see two different ways to proceed:

   1. one could first check if there are any 0 in the vector and then
      return 0 without computing the product
   2. or convert prod(x1, x2, x3) in prod(c(x1, x2, x3))

Both approaches are similar except for the pathological case where one 
vector x1 is really huge. An example:

prod(0, 1:1e25)

   1. will give 0
   2. will give an error stating that the vector c(0, 1:1e255) will be
      too large - in length I mean

Consequently, my opinion will be that approach 1 will be better - and 
maybe faster because it'll avoide useless computations.

Best,
Mathieu

Martin Maechler a ?crit :