Last data update: 2014.03.03

R: Methods for 'asNumeric(<mpfr>)'
asNumeric-methodsR Documentation

Methods for asNumeric(<mpfr>)

Description

Methods for function asNumeric (in package gmp).

Usage


## S4 method for signature 'mpfrArray'
asNumeric(x)

Arguments

x

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

Value

an R object of type (typeof) "numeric", a matrix or array if x had non-NULL dimension dim().

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(s)

Martin Maechler

See Also

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

Examples

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

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/asNumeric-methods.Rd_%03d_medium.png", width=480, height=480)
> ### Name: asNumeric-methods
> ### Title: Methods for 'asNumeric(<mpfr>)'
> ### Aliases: asNumeric-methods asNumeric,mpfr-method
> ###   asNumeric,mpfrArray-method
> ### Keywords: methods
> 
> ### ** Examples
> 
> 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"
'mpfrMatrix' of dim(.) =  (3, 2) of precision  99   bits 
     [,1]                              [,2]                             
[1,] 0.1999999999999999999999999999998 0.7999999999999999999999999999994
[2,] 0.3999999999999999999999999999997  1.000000000000000000000000000000
[3,] 0.6000000000000000000000000000003  1.200000000000000000000000000001
> asNumeric(M) # numeric matrix
     [,1] [,2]
[1,]  0.2  0.8
[2,]  0.4  1.0
[3,]  0.6  1.2
> stopifnot(all.equal(asNumeric(M), m/5),
+           identical(asNumeric(m), m))# remains matrix
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>