Skip to content

Precision of values > 53 bits

3 messages · Stephan Mueller, R. Michael Weylandt, S Ellison

#
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:
[1] 9007199254740992
[1] 9007199254740991
[1] 9007199254740990

Now, see the numbers above 53 bit:
[1] 9007199254740992
[1] 9007199254740992
[1] 9007199254740994
[1] 9007199254740996
[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:
#
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.
"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)
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}