Learn R Programming

Rmpfr (version 0.9-5)

asNumeric-methods: Methods for asNumeric(<mpfr>)

Description

Methods for function asNumeric (in package gmp).

Usage


# S4 method for mpfrArray
asNumeric(x)

Value

an R object of type (typeof) "numeric", a matrix

or array if x had non-NULL dimension dim().

Arguments

x

a “number-like” object, here, a mpfr or typically mpfrArrayone.

Methods

signature(x = "mpfrArray")

this method also dispatches for mpfrMatrix and returns a numeric array.

signature(x = "mpfr")

for non-array/matrix, asNumeric(x) is basically the same as as.numeric(x).

Author

Martin Maechler

See Also

our lower level (non-generic) toNum(). Further, asNumeric (package gmp), standard R's as.numeric().

Examples

Run this code
x <- (0:7)/8 # (exact)
X <- mpfr(x, 99)
stopifnot(identical(asNumeric(x), x),
	  identical(asNumeric(X), x))

m <- matrix(1:6, 3,2)
(M <- mpfr(m, 99) / 5) ##-> "mpfrMatrix"
asNumeric(M) # numeric matrix
stopifnot(all.equal(asNumeric(M), m/5),
          identical(asNumeric(m), m))# remains matrix

Run the code above in your browser using DataLab