2

Complex Number in R is defined as:

function (length.out = 0L, real = numeric(), imaginary = numeric(), modulus = 1, argument = 0)

I've a program which aims to process multiple precision values in the real case and complex case. R does not support multiple precision directly. After installing the Rmpfr package I could define multiple precision values and use regular functions using the new mpfr objects.

TestFunc <- function(a, b){
    seq(a, b, length.out = 3)
}

>TestFunc(mpfr(1, 120), mpfr(2, 120))
[1]                                       1
[2] 1.1666666666666666666666666666666666662
[3] 1.3333333333333333333333333333333333338
[4]                                     1.5
[5] 1.6666666666666666666666666666666666677
[6] 1.8333333333333333333333333333333333338
[7]                                       2

I have functions which also process complex numbers.

PROBLEM: I cannot call

complex(real=mpfr(1, 120), imaginary=mpfr(1,120))

because, the complex function definition requires these to be of double precision only.

Is there a way in which I can do complex number arithmetic in R, using multiple precision?

complextea
  • 393
  • 1
  • 5
  • 16
  • There seems to be a possibility using the `mpc` package, which you can retrieve [here](https://cran.r-project.org/src/contrib/Archive/mpc/mpc_0.1.tar.gz). You can install this package with `install.packages("//mpc_0.1.tar.gz", repos = NULL, type = "source")`. Note that there are several system requirements; specifically you will need the [MPC library](http://www.multiprecision.org/). The README file provides more details. Good luck! – RHertel Feb 25 '16 at 09:23
  • `MPC` is a `C` library. Will `R` install a `C` library? Tried it: Warning: invalid package 'Path/mpc_0.3.tar.gz' Error: ERROR: no packages specified Warning messages: 1: running command `'"PATH/R/R-32~1.3/bin/i386/R" CMD INSTALL -l "PATH\R\win-library\3.2" "Path/mpc_0.3.tar.gz"'` had status 1 2: In install.packages("Path\\mpc_0.3.tar.gz", : installation of package ‘Path/mpc_0.3.tar.gz’ had non-zero exit status – complextea Feb 25 '16 at 10:39
  • What I meant with `` was the entire path of wherever you have stored the file, maybe something like `C:/Users/Hobbit/Desktop/mpc_0.3.tar.gz`. R will not install the MPC library, it will only check if it is available. See the "Packages" and the "Download" section on the linked page to `MPC` for the installation procedure. I did not try it myself, so I don't know what other problems you may encounter. There may be a reason why the package was removed from CRAN. If I had a solution, I would have posted it as an answer, and not as a comment. I hope you will succeed. – RHertel Feb 25 '16 at 10:52
  • Moreover, since I'm primarily a Linux user, I never know whether you need forward slashes, backward slashes or double backward slashes in the PATH specification. Sorry. Try and search which is the correct way to specify the path in R using Windows; this has been discussed on many posts before on SO. – RHertel Feb 25 '16 at 10:58
  • I thank-you for the help. Yes, I obviously replaced the by the actual locations. And I tried to see if MPC was a package available in the packages normally available to R, which is from where I installed `Rmpfr` in the first place. Secondly, sadly, there's no installation procedure, just download links. So, I tried to install it the way you suggested, and also by the R's automatic option to install a package from local zip files in the R's GUI. It failed both the times. Thanks once again. – complextea Feb 25 '16 at 11:00
  • @RHertel It's normally, `double backward-slashes` in Windows. I use `\\\` to source files into R. – complextea Feb 25 '16 at 11:01

0 Answers0