Hi, I am working with large numbers and identified that R looses precision for such high numbers. The precision is lost exactly when the number is equal or larger than 53 bits. See the following output which shows that the numbers below 53 bit have proper precision:> 2^53[1] 9007199254740992> 2^53-1[1] 9007199254740991> 2^53-2[1] 9007199254740990 Now, see the numbers above 53 bit:> 2^53[1] 9007199254740992> 2^53+1[1] 9007199254740992> 2^53+2[1] 9007199254740994> 2^53+3[1] 9007199254740996> 2^53+4[1] 9007199254740996 Is there a solution to the problem? Thanks a lot Stephan
Hi, I am working with large numbers and identified that R looses precision for such high numbers. The precision is lost exactly when the number is equal or larger than 53 bits. See the following output which shows that the numbers below 53 bit have proper precision:> 2^53[1] 9007199254740992> 2^53-1[1] 9007199254740991> 2^53-2[1] 9007199254740990 Now, see the numbers above 53 bit:> 2^53[1] 9007199254740992> 2^53+1[1] 9007199254740992> 2^53+2[1] 9007199254740994> 2^53+3[1] 9007199254740996> 2^53+4[1] 9007199254740996 Is there a solution to the problem? Thanks a lot Stephan
Perhaps here?: https://r-forge.r-project.org/projects/rmpfr/ M On Thu, Jan 10, 2013 at 10:58 AM, Stephan Mueller <stephan.mueller at atsec.com> wrote:> > > I am working with large numbers and identified that R looses precision > for such high numbers. > > The precision is lost exactly when the number is equal or larger than 53 > bits. See the following output which shows that the numbers below 53 bit > have proper precision:
> I am working with large numbers and identified that R looses > precision for such high numbers.Yes. R uses standard 32-bit double precision. See ?double in your R help system. And welcome to finite precision arithmetic, which is a very widely known issue in digital comuting ever since it was invented.> Is there a solution to the problem?"Yes, lots," said Bilbo, before he remembered not to give his friends away. "No, none at all, not one," he said immediately afterwards. [1] R cannot easily be recompiled to use higher precision, so in that sense, 'none at all'. However, you could use something like the Rmpfr package for arbitrary precision arithmetic. On linux/unix you can use bc (see http://r.789695.n4.nabble.com/Arbitrary-Precision-Numbers-td855931.html) Or you could do basic things that address the issue: for example, scale, mean-centre or transform the numbers or change your parameterisation so that you do not need high numerical precision on large numbers. Steve Ellison [1] JRR Tolkien, ' The Hobbit', Chapter 3 (1937)> > Thanks a lot > Stephan > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}
On 13-01-10 6:01 AM, Stephan Mueller wrote:> Hi, > > I am working with large numbers and identified that R looses precision > for such high numbers. > > The precision is lost exactly when the number is equal or larger than 53 > bits. See the following output which shows that the numbers below 53 bit > have proper precision: > >> 2^53 > [1] 9007199254740992 >> 2^53-1 > [1] 9007199254740991 >> 2^53-2 > [1] 9007199254740990 > > Now, see the numbers above 53 bit: > >> 2^53 > [1] 9007199254740992 >> 2^53+1 > [1] 9007199254740992 >> 2^53+2 > [1] 9007199254740994 >> 2^53+3 > [1] 9007199254740996 >> 2^53+4 > [1] 9007199254740996 > > > Is there a solution to the problem?R has no native numeric type with more than 53 bit precision, but other packages have added it. For example, the gmp package provides an interface to the gmp library which supports arbitrarily large integers and arbitary precision rationals. Duncan Murdoch
> On 10 Jan 2013, at 15:56 , S Ellison <S.Ellison at lgcgroup.com> wrote: > > > >> I am working with large numbers and identified that R looses >> precision for such high numbers. > Yes. R uses standard 32-bit double precision.Well, for large values of 32... such as 64. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com