an R object of class bigz, bigq or mpfr
respectively.
precB
precision in bits for the result. The default,
NULL, means to use the minimal precision necessary for
correct representation.
rnd.mode
a 1-letter string specifying how rounding
should happen at C-level conversion to MPFR, see details of
mpfr.
mod
a possible modulus, see as.bigz in
package gmp.
Details
Note that we also provide the natural (S4) coercions,
as(x, "mpfr") for x inheriting from class "bigz"
or "bigq".
Value
a numeric vector of the same length as x, of the desired class.
See Also
mpfr(), as.bigz and
as.bigq in package gmp.
Examples
S <- gmp::Stirling2(50,10)
show(S)
SS <- S * as.bigz(1:3)^128
stopifnot(all.equal(log2(SS[2]) - log2(S), 128, tolerance=1e-15),
identical(SS, .mpfr2bigz(.bigz2mpfr(SS))))
.bigz2mpfr(S) # 148 bit precision
.bigz2mpfr(S, precB=256) # 256 bit
## rational --> mpfr:
sq <- SS / as.bigz(2)^100
MP <- as(sq, "mpfr")
stopifnot(identical(MP, .bigq2mpfr(sq)),
SS == MP * as(2, "mpfr")^100)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Rmpfr)
Loading required package: gmp
Attaching package: 'gmp'
The following objects are masked from 'package:base':
%*%, apply, crossprod, matrix, tcrossprod
C code of R package 'Rmpfr': GMP using 64 bits per limb
Attaching package: 'Rmpfr'
The following objects are masked from 'package:stats':
dbinom, dnorm, dpois, pnorm
The following objects are masked from 'package:base':
cbind, pmax, pmin, rbind
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Rmpfr/gmp-conversions.Rd_%03d_medium.png", width=480, height=480)
> ### Name: gmp-conversions
> ### Title: Conversion Utilities gmp <-> Rmpfr
> ### Aliases: .bigq2mpfr .bigz2mpfr .mpfr2bigz coerce,bigq,mpfr-method
> ### coerce,bigz,mpfr-method
> ### Keywords: arith
>
> ### ** Examples
>
> S <- gmp::Stirling2(50,10)
> show(S)
Big Integer ('bigz') :
[1] 26154716515862881292012777396577993781727011
> SS <- S * as.bigz(1:3)^128
> stopifnot(all.equal(log2(SS[2]) - log2(S), 128, tolerance=1e-15),
+ identical(SS, .mpfr2bigz(.bigz2mpfr(SS))))
>
> .bigz2mpfr(S) # 148 bit precision
1 'mpfr' number of precision 148 bits
[1] 26154716515862881292012777396577993781727011
> .bigz2mpfr(S, precB=256) # 256 bit
1 'mpfr' number of precision 256 bits
[1] 26154716515862881292012777396577993781727011
>
> ## rational --> mpfr:
> sq <- SS / as.bigz(2)^100
> MP <- as(sq, "mpfr")
> stopifnot(identical(MP, .bigq2mpfr(sq)),
+ SS == MP * as(2, "mpfr")^100)
>
>
>
>
>
> dev.off()
null device
1
>