[Rd] sum overflow (PR#1091)

wsi@gcal.ac.uk wsi@gcal.ac.uk
Thu, 13 Sep 2001 10:43:08 +0200 (MET DST)


Full_Name: Bill Simpson
Version: 1.2.3
OS: linux
Submission from: (NULL) (193.62.250.209)


I think I have found an accuracy problem with sum()

> a<-1:1000
> b<-1:1000
>
> crossprod(a,a)*crossprod(b,b)
             [,1]
[1,] 1.114448e+17
> drop(.Last.value)
[1] 1.114448e+17
>
#this should give same answer as above
> sum(a*a)*sum(b*b)
[1] -652010736
#seems to be due to sum using integer representation which overflows instead of
using
#double representation

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._