Learn R Programming

Rmpfr (version 0.1-7)

mpfr: Create "mpfr" Numbers (Objects)

Description

Create multiple (i.e. typically high) precision numbers, to be used in arithmetic and mathematical computations with R.

Usage

mpfr(x, precBits, base = 10)
Const(name = c("pi", "gamma", "catalan"), prec = 120L)

Arguments

x
a numeric or character vector.
precBits, prec
a number, the maximal precision to be used, in bits; i.e. 53 corresponds to double precision. Must be at least 2.
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$.
name
a string specifying the mpfrlib - internal constant computation. "gamma" is Euler's gamma $(\gamma)$, and "catalan" Catalan's constant.

Value

  • an object of (S4) class mpfr which the user should just as a normal numeric vector.

See Also

The class documentation mpfr contains more details.

Examples

Run this code
mpfr(pi, 120) ## the double-precision pi "translated" to 120-bit precision

pi. <- Const("pi", prec = 260) # pi "computed" to correct 260-bit precision
pi. # nicely prints 80 digits [260 * log10(2) ~= 78.3 ~ 80]

Const("gamma",   128L) # 0.5772...
Const("catalan", 128L) # 0.9159...

x <- mpfr(0:7, 100)/7 # a more precise version of  k/7, k=0,..,7
x
1 / x

## character input :
mpfr("2.718281828459045235360287471352662497757") - exp(mpfr(1, 150))
## ~= -4 * 10^-40

## with some 'base' choices :
print(mpfr("111.1111", base=2)) * 2^4

mpfr("af21.01020300a0b0c", base=16)
##  68 bit prec.  44833.00393694653820642

Run the code above in your browser using DataLab