[Rd] double in summary.c : isum
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Mar 23 13:01:13 CET 2013
On 20/03/2013 12:56, Matthew Dowle wrote:
>
> Hi,
>
> Please consider the following :
>
>> x = as.integer(2^30-1)
> [1] 1073741823
>> sum(c(rep(x, 10000000), rep(-x,9999999)))
> [1] 1073741824
>
> Tested on 2.15.2 and a recent R-devel (r62132).
>
> I'm wondering if s in isum could be LDOUBLE instead of double, like
> rsum, to fix this edge case?
No, because there is no guarantee that LDOUBLE differs from double (and
platform on which it does not).
Users really need to take responsibility for the numerical stability of
calcuations they attempt. Expecting to sum 20 million large numbers
exactly is unrealistic.
There are cases where 64-bit integer accumulators would be beneficial,
and this is one. Unfortunately C11 does not require them but some
optional moves in that direction are planned.
>
> https://svn.r-project.org/R/trunk/src/main/summary.c
>
> Thanks,
> Matthew
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
--
Brian D. Ripley, ripley at 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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel
mailing list