Learn R Programming

Rmpfr (version 0.5-3)

mpfr-utils: Rmpfr -- Utilities for Precision Setting, Printing, etc

Description

This page documents utilities from package Rmpfr which are typically not called by the user. In some case the may come handy.

Usage

getPrec(x, base = 10, doNumeric = TRUE, is.mpfr = NA)
getD(x)
mpfr_default_prec(prec)
## S3 method for class 'mpfrArray':
print(x, digits = NULL, drop0trailing = FALSE,
      right = TRUE, \dots)
## S3 method for class 'mpfr':
print(x, digits = NULL, drop0trailing = TRUE,
      right = TRUE, \dots)
toNum(from)
mpfr2array(x, dim, dimnames = NULL, check = FALSE)

Arguments

x, from
an Robject of class "mpfr", or "mpfrArray", respectively.
base
(only when x is character) the base with respect to which x[i] represent numbers; base $b$ must fulfill $2 \le b \le 36$.
doNumeric
logical indicating integer or double typed x should be accepted and a default precision be returned. Should typically be kept at default
is.mpfr
logical indicating if class(x) is already known to be "mpfr"; typically should be kept at default, NA.
prec
a positive integer, or missing.
drop0trailing
logical indicating if trailing "0"s should be omitted.
right
logical indicating print()ing should right justify the strings; see print.default() to which it is passed.
digits, ...
further arguments to print methods.
dim, dimnames
for "mpfrArray" construction.
check
logical indicating if the mpfrArray construction should happen with internal safety check. Previously, the implicit default used to be true.

Value

  • getPrec(x) returns a integer vector of the same length as x. If you need to change the precision of x, i.e., need something like setPrec, use roundMpfr().

    getD(x) is intended to be a fast version of x@.Data, and should not be used outside of lower level functions.

    mpfr_default_prec() returns the current MPFR default precision, an integer. This is currently not made use of, in all of package Rmpfr, where functions have their own default precision where needed. mpfr_default_prec(prec) sets the current MPFR default precision and returns the previous one; see above.

    toNum(m) returns a numeric array or matrix, when m is of class "mpfrArray" or "mpfrMatrix", respectively. It should be equivalent to as(m, "array") or ... "matrix". Note that the slightly more general asNumeric() is preferred now.

    mpfr2array() a slightly more flexible alternative to dim(.) <- dd.

Details

The print method is currently built on the format method for class mpfr. This, currently does not format columns jointly which leads to suboptimally looking output. There are plans to change this.

See Also

Start using mpfr(..), and compute with these numbers.

mpfrArray(x) is for numeric (non-mpfr) x, whereas mpfr2array(x) is for "mpfr" classed x, only.

Examples

Run this code
getPrec(as(c(1,pi), "mpfr")) # 128 for both

(opr <- mpfr_default_prec()) ## typically  53, the MPFR system default
stopifnot(opr == (oprec <- mpfr_default_prec(70)),
          70  == mpfr_default_prec())
## and reset it:
mpfr_default_prec(opr)

## Printing of "MPFR" matrices is less nice than R's usual matrix printing:
m <- outer(c(1, 3.14, -1024.5678), c(1, 1e-3, 10,100))
m[3,3] <- round(m[3,3])
m
mpfr(m, 50)

mpfr2array(Bernoulli(1:6, 60), c(2,3),
           dimnames = list(LETTERS[1:2], letters[1:3]))

Run the code above in your browser using DataLab