precisiongmpmpfr

How to change `MPFR_MAX_PREC` either via `R` or a re-compile?


The default value (in bits, I believe), as shown via Rmpfr:

.mpfr_maxPrec()
[1] 9.223372e+18

I'd like to find a way to change that value to something larger. Here's a real-world example where it matters. Oneof the infamous "998" fractions, 1/998001 , produces the decimal sequence 002003004.... 100101102.... 996997998999001... . But the best I can get with Rmpfr is

mpfr(1/(mpfr(998001,1e7)),1e7)
1 'mpfr' number of precision  10000000   bits 

which terminates with "33133233333"

Increasing the precision to 1e8 or 1e9 doesn't change the output; if I try 1e10, I get

mpfr(1/(mpfr(998001,1e6)),1e10)
Error in .class1(object) : prec = -2147483648 < 1  is too small
In addition: Warning message:
In .class1(object) : NAs introduced by coercion to integer range  

Which may be a bug inside the Rmpfr or gmp packages (that's -2^32 there).


Solution

  • I received some info from the package maintainer.

    print.mpfr method uses
    # max.digits = getOption("Rmpfr.print.max.digits", 999L)
    hence, by default default (no such option set), "only" 999
    significant digits are printed

    So this can be 'fixed' with, e.g :

    print(foo9,digits = 4000, max.digits = getOption("Rmpfr.print.max.digits",4000))

    And the last error I mentioned is a bug; to be addressed in a future release of Rmpfr .