Re: [Rd] prod(0, 1:1000) ; 0 * Inf etc

From: Berwin A Turlach <berwin_at_maths.uwa.edu.au>
Date: Tue, 22 Apr 2008 11:10:02 +0800

G'day Martin,

On Mon, 21 Apr 2008 18:40:43 +0200
Martin Maechler <maechler_at_stat.math.ethz.ch> wrote:

> I think most of us would expect prod(0:1000) to return 0, and ...
> ... it does.
>
> However, many of us also expect
> prod(x1, x2) to be equivalent to
> prod(c(x1,x2))
> the same as we can expect that for min(), max(), sum() and such
> members of the "Summary" group.

Many may also expect that prod(x) and prod(rev(x)) are equivalent. Unfortunately, this does not hold in finite precision arithmetic:

> prod(0:1000)
[1] 0
> prod(1000:0)

[1] NA
> prod(rev(0:1000))

[1] NA

It might be better to educate useRs on finite precision arithmetic than trying to catch such situations. Note, I am saying "better", not "easier". :-)

Cheers,         

        Berwin



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 22 Apr 2008 - 03:12:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Apr 2008 - 08:31:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive