R语言:意外的精度从min.mpfr调用返回

发布于 2025-02-03 18:30:07 字数 572 浏览 4 评论 0原文

考虑:

> 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

我知道mpfr对象的“最小”方法以某种方式潜入bigzbigq bigq - 类对象的“ min”方法中无法弄清楚精度如何或为什么会碰到如此宽敞的值。谁能详细说明窗帘背后发生了什么?

附录:这似乎只有在我以很小的精度开始的MPFR对象开始时才会发生。如果我从foo&lt; -mpfr(1:5,prec = 60)开始,那么我在精度值中看不到任何跳跃。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦幻的心爱 2025-02-10 18:30:07

这些似乎是默认选项,按类型划分,如上所述,缺乏设置的固定限制:

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

可以请求更高的精度。

?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

从结果中提取的集合仍在刮擦...

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文