[R] [Rd] Floating point precision / guard digits? (PR#13771)

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Sun Jun 21 22:59:51 CEST 2009


Stavros Macrakis wrote

[...]

> programming languages (including R).  I don't know whether R's sum function
> uses this technique or some other (e.g. Kahan summation), but it does manage
> to give higher precision than summation with individual arithmetic
> operators:
>
>     sum(c(2^63,1,-2^63)) => 1
>   

not if the arguments are passed as separate elements in ...:

x = c(2^63, 1, -2^63)
sum(x)
# 1
do.call(sum, as.list(x))
# 0

y = 1:3
sum(y)
# 6
do.call(sum, as.list(y))
# 6

vQ




More information about the R-help mailing list