round(numeric(0)) (PR#235)
Prof Brian D Ripley
ripley@stats.ox.ac.uk
Thu, 29 Jul 1999 17:58:14 +0100 (BST)
On Thu, 29 Jul 1999, Kurt Hornik wrote:
> >>>>> ripley writes:
>
> > Try
> >> round(numeric(0))
> > [1] NA
> >> floor(numeric(0))
> > numeric(0)
> >> trunc(numeric(0))
> > numeric(0)
>
> > S has them all as numeric(0), and I think R is wrong.
> > This looks like a design error in the math2 group: it applies to
> > signif too, and also to the complex cases, e.g.
> >> signif(complex(0))
> > [1] NA
>
> In math2, we have
>
> if (na < 1 || nb < 1) {
> for (i = 0; i < n; i++)
> y[i] = NA_REAL;
> }
>
> with
>
> na = LENGTH(sa);
> nb = LENGTH(sb);
> n = (na < nb) ? nb : na;
>
> round(numeric(0)) really does round(numeric(0), 0) and hence we have na
> = 0, n = nb = 1. I think math2 is about right because you need that
> sort of symmetry for recycling, but do_round() could know better. Now
>
> R> round(pi, 1:4)
> [1] 3.1000 3.1400 3.1420 3.1416
>
> is supposed to work so is it really clear what we want? (if either arg
> has length 0, does the result have length 0? Should this be true for
> any math2 type function?)
Yes, I think that is what Svr4 says is the correct behaviour: the recycling
rules have been changed to be consistent (JMC says somewhere in the Green
book) and any zero-length vector immediately makes the result of zero
length.
--
Brian D. Ripley, ripley@stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._