Learn R Programming

Rmpfr (version 0.5-3)

mpfr.utils: MPFR Number Utilities

Description

mpfrVersion() returns the version of the MPFR library which Rmpfr is currently linked to.

c(x,y,...) can be used to combine MPFR numbers in the same way as regular numbers IFF the first argument x is of class mpfr.

mpfr.is.0(.) uses the MPFR library in the documented way to check if (a vector of) MPFR numbers are zero.

mpfr.is.integer(x) uses the MPFR library in the documented way to check if (a vector of) MPFR numbers is integer valued. This is equivalent to x == round(x), but not at all to is.integer(as(x, "numeric")). You should typically rather use is.whole(x) instead.

hypot(x,y) computes the hypothenuse length $z$ in a rectangular triangle with leg side lengths $x$ and $y$, i.e., $$z = hypot(x,y) = \sqrt{x^2 + y^2},$$ in a numerically stable way.

Usage

mpfrVersion()
mpfr.is.0(x)
mpfr.is.integer(x)
## S3 method for class 'mpfr':
c(\dots)
## S3 method for class 'mpfr':
diff(x, lag = 1L, differences = 1L, \dots)

hypot(x,y)

Arguments

x,y
an object of class mpfr.
...
For diff, further mpfr class objects or simple numbers (numeric vectors) which are coerced to mpfr with default precision of 128 bit
lag, differences
for diff(): exact same meaning as in diff()'s default method, diff.default.

Value

  • mpfr.is.0 returns a logical vector of length length(x) with values TRUE iff the corresponding x[i] is an MPFR representation of zero (0). Similarly, mpfr.is.integer returns a logical vector of length length(x).

    mpfrVersion returns an object of S3 class "numeric_version", so it can be used in comparisons.

    The other functions return MPFR number (vectors), i.e., extending class mpfr.

See Also

str.mpfr for the str method. erf for special mathematical functions on MPFR; The class description mpfr mentioning the generic arithmetic and mathematical functions for which "mpfr" methods are available.

Examples

Run this code
mpfrVersion()

(x <- c(Const("pi", 64), mpfr(-2:2, 64)))
mpfr.is.0(x)    # one of them is
x[mpfr.is.0(x)] # but it may not have been obvious..
str(x)

xy <- expand.grid(x = -2:2, y = -2:2) ; x <- xy[,"x"] ; y <- xy[,"y"]
a2. <- atan2(y,x)

stopifnot(all.equal(a2., atan2(as(y,"mpfr"), x)),
          mpfr.is.integer(mpfr(2, 500) ^ (1:200)),
          all.equal(diff(x), diff(as.numeric(x))),
          TRUE)

Run the code above in your browser using DataLab