Carl Witthoft
Carl Witthoft

Reputation: 21502

R language: unexpected precision returned from min.mpfr call

Consider:

> foob <- as.bigz(5:7)
> min(foob)
Big Integer ('bigz') :
[1] 5
> .bigz2mpfr(prev)
1 'mpfr' number of precision  4   bits 
[1] 5
> min(.bigz2mpfr(foob))
1 'mpfr' number of precision  53   bits 
[1] 5
> min(mpfr(5:7,5))
1 'mpfr' number of precision  53   bits 
[1] 5

I know that the 'min' method for mpfr objects somehow dives into the 'min' method for bigz or bigq - class objects but can't figure out how or why the precision gets bumped up to such a larg value. Can anyone detail what's happening behind the curtain?

Addendum: this only seems to happen if I start out with mpfr objects with very small precision. If I start with, say foo <- mpfr(1:5, prec = 60) then I don't see any jump in the precision value.

Upvotes: 1

Views: 58

Answers (1)

Chris
Chris

Reputation: 2286

These seem to be the default options, by type, absent setting precBit as you do above:

debug at /home/chris/r_TMPDIR/RtmpK4UkSw/R.INSTALL422c7408a8298/Rmpfr/R/mpfr.R#656: if (is.logical(x)) 2L else if (is.raw(x)) {
    if (is.object(x)) {
        if (inherits(x, "bigz")) 
            frexpZ(x)$exp
        else if (inherits(x, "bigq")) {
            if (missing(bigq.)) {
                warning("default precision for 'bigq' arbitrarily chosen as ", 
                  bigq.)
                bigq.
            }
            else as.integer(bigq.)
        }
        else 8L
    }
    else 8L
} else {
    if (!doNumeric) 
        stop("must specify 'precBits' for numeric 'x' when 'doNumeric' is false")
    if (is.integer(x)) 
        32L
    else if (is.double(x)) 
        53L
    else if (length(x) == 0) 
        mpfr_default_prec()
    else stop(sprintf("cannot determine 'precBits' for x of type '%s'", 
        typeof(x)))
}
Browse[4]> ls()
[1] "base"      "bigq."     "doNumeric" "is.mpfr"   "x"        
Browse[4]> s

Greater or less precision can be requested.

?getPrec # get you into otherwise unexported utilities for poking around
f5 <- getPrec(6:10, base = 10, doNumeric = TRUE, is.mpfr = NA, bigq. = 128L)
> f5
[1] 32
> f6 <- getPrec(6.5:10, base = 10, doNumeric = TRUE, is.mpfr = NA, bigq. = 128L)
> f6
[1] 53

Still head scratching on extracting from result for sets...

Upvotes: 2

Related Questions