round(numeric(0)) (PR#235)
Kurt Hornik
Kurt.Hornik@ci.tuwien.ac.at
Thu, 29 Jul 1999 18:49:47 +0200 (CEST)
>>>>> 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?)
-k
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._