[Rd] sum overflow (PR#1091)
David Smith
dsmith@insightful.com
Thu, 13 Sep 2001 11:07:36 -0700
> If you use integers you need to be aware of the consequences. It's a
> feature not a bug.
Perhaps, but maybe a more useful feature would be to signal to the user when
such an overflow occurs? Sv4 does this by returning NA for overflow integer
results:
> a <- (1:1000)
> b <- (1:1000)
> sum(a * a) * sum(b * b)
[1] NA
When this was introduced in S-PLUS 5, we discovered some overflow errors we
were previously unaware of in S-PLUS (by noticing NAs in the results).
# David Smith
--
David M Smith <dsmith@insightful.com>
S-PLUS Product Marketing Manager, Insightful Corp, Seattle WA
Tel: +1 (206) 283 8802 x360
Fax: +1 (206) 283 0347
Learn how Merck, Proctor & Gamble, Merrill Lynch and others are using
S-PLUS, deploying Web-based analytics and more at the 2001 S-PLUS User
Conference being held in Philadelphia, October 18-19 -
www.insightful.com/events/2001uc.
> -----Original Message-----
> From: owner-r-devel@stat.math.ethz.ch
> [mailto:owner-r-devel@stat.math.ethz.ch]On Behalf Of Prof Brian Ripley
> Sent: Thursday, September 13, 2001 01:54
> To: wsi@gcal.ac.uk
> Cc: r-devel@stat.math.ethz.ch; R-bugs@biostat.ku.dk
> Subject: Re: [Rd] sum overflow (PR#1091)
>
>
> It's not a problem with sum:
>
> > sum(a*a)
> [1] 333833500
> > sum(b*b)
> [1] 333833500
>
> are accurate.
>
> The overflow is in the integer arithmetic for *. That's a question for
> your C run-time system. On a 64-bit machine you might get different
> results (although most use 32-bit ints, including mine).
>
> If you use integers you need to be aware of the consequences. It's a
> feature not a bug.
>
>
> On Thu, 13 Sep 2001 wsi@gcal.ac.uk wrote:
>
> > 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
> >
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._._._._._._
> >
>
> --
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._