[R-pkg-devel] How to get arbitrary precise inputs from R for an Rcpp package?
Leo Mada
|eo@m@d@ @end|ng |rom @yon|c@eu
Sun Jul 21 00:06:24 CEST 2024
Dear Khue,
As mentioned before, you can use Rmpfr to read in strings or compute higher precision values, like
x = mpfr(1, 192) /10;
# 0.1 with 192 bits precision
# or x = mpfr("0.1", 192);
mpfr(1, 192) /10 - mpfr("0.1", 192)
# 1 'mpfr' number of precision 192 bits
# [1] 0
However, I do not know how easy it is to convert from the mpfr format to the other format. Maybe the BH-team can add an mpfr constructor to the library.
On a somewhat related topic, I did implement a very basic solver in native R (and based on Rmpfr). You can have a look on GitHub; it is not a package, but the script should be self-contained:
https://github.com/discoleo/R/blob/master/Math/Polynomials.Helper.Matrix.mpfr.R
It is very basic - more like a proof of concept. It does not include any advanced tricks and there is quit some drop of precision in some examples, see:
https://github.com/discoleo/R/blob/master/Math/Polynomials.Helper.mpfr.Tests.R
I was primarily interested in solving systems of polynomial equations (including complex roots); but did not have time to finish the remaining work. Extending the algorithm to solve for eigenvalues may be feasible (although I was less interested in eigenvalues). A native implementation in C++ would be faster; but I try to avoid any more complicated programming if it is not absolutely essential!
Sincerely,
Leonard
[[alternative HTML version deleted]]
More information about the R-package-devel
mailing list