[Rd] prod(numeric(0)) surprise

Ben Bolker bolker at zoo.ufl.edu
Mon Jan 9 03:24:51 CET 2006


   It surprised me that prod(numeric(0)) is 1.
I guess if you say (operation(nothing) == identity
element) this makes sense, but ??

    Looking in the code, this makes sense:
basically (s=1; for i=0 to length(x),
multiply s by x[i]) -- which comes out to 1.

   What *should* prod(numeric(0)) produce?
I couldn't find the answer documented anywhere.

   (And how about sum(numeric(0))==0,
which for some reason makes more intuitive sense
to me, but is really exactly the same thing --
consider exp(sum(log(numeric(0)))) ... ?)

   cheers
     Ben Bolker

-- 
620B Bartram Hall                            bolker at zoo.ufl.edu
Zoology Department, University of Florida    http://www.zoo.ufl.edu/bolker
Box 118525                                   (ph)  352-392-5697
Gainesville, FL 32611-8525                   (fax) 352-392-3704



More information about the R-devel mailing list