R Under development (unstable) (2024-11-15 r87338 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 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. > require("Rmpfr") Loading required package: 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 object is masked from 'package:gmp': outer The following objects are masked from 'package:stats': dbinom, dgamma, dnbinom, dnorm, dpois, dt, pnorm The following objects are masked from 'package:base': cbind, pmax, pmin, rbind > > ### Simple basic examples of creation of "mpfr" objects > > pi. <- Const("pi", prec = 260) > pi. # nicely prints 80 digits [260 * log10(2) ~= 78.3 ~ 80] 1 'mpfr' number of precision 260 bits [1] 3.1415926535897932384626433832795028841971693993751058209749445923078164062862088 > > ## These both failed (in mpfr2str(.)) with a seg.fault: > c(mpfr(1, prec=3), pi.) 2 'mpfr' numbers of precision 3 .. 260 bits [1] 1 [2] 3.1415926535897932384626433832795028841971693993751058209749445923078164062862088 > m0 <- mpfr(numeric(), prec=64) > ## print()ing / str() of 0-length mpfr > stopifnot( + grepl("0 'mpfr' numbers", capture.output( m0)), + grepl("0 'mpfr' numbers", capture.output(str(m0)))) > > c(m0,m0) # failed in Rmpfr <= 0.6-0 0 'mpfr' numbers > stopifnot(identical(c(m0,m0), m0), + identical(c(m0,pi.), pi.), + identical(c(pi.,m0), pi.)) > > ## This is TRUE for 0 and -0 : > Zero <- mpfr(c(0,1/-Inf), 20) > stopifnot(mpfrIs0(Zero), is.whole(Zero)) > stopifnot(mpfr.is.0(Zero))# deprecated but must work Warning message: In mpfr.is.0(Zero) : 'mpfr.is.0' is deprecated. Use 'mpfrIs0' instead. See help("Deprecated") > stopifnot(mpfr.is.integer(Zero))# deprecated but must work Warning message: In mpfr.is.integer(Zero) : 'mpfr.is.integer' is deprecated. Use '.mpfr.is.whole' instead. See help("Deprecated") > Zero # the "-0" should print correctly 2 'mpfr' numbers of precision 20 bits [1] 0 -0 > stopifnot(.getSign(Zero) == c(1,-1), + sign(Zero) == 0, + identical(format(Zero, digits=1), c("0.", "-0."))) > > ## testing 'recycling' > b <- c(20,120,80, 60) > (x <- mpfr(2^-(5:7), precBits = b)) 4 'mpfr' numbers of precision 20 .. 120 bits [1] 0.03125 0.015625 0.0078125 0.03125 > > d.spec <- c(0,NA,NaN,Inf,-Inf) > (spec <- mpfr(d.spec, 3)) 5 'mpfr' numbers of precision 3 bits [1] 0 NaN NaN Inf -Inf > stopifnot(length(x) == 4, x[1] == x[4], getPrec(x) == b, + identical(is.na(spec), is.na(d.spec)), + identical(is.finite(spec), is.finite(d.spec)), + identical(is.infinite(spec), is.infinite(d.spec)), + ## mpfr(, .) : + identical(x, mpfr(x, getPrec(x))), + identical(spec, mpfr(spec, getPrec(spec))), + asNumeric(1/mpfr(x, 16)) == 2^c(5:7,5), + identical(format(spec), c("0.", "NaN", "NaN", "Inf", "-Inf")), + mpfr(0.2, prec = 5:15, rnd.mode = "D") < 0.2) > > B.set <- setNames(2:62, paste0("B=",2:62)) > str(lapply(B.set, function(B) format(spec, base= B)))# "0.0" and "0.00" -- FIXME List of 61 $ B=2 : chr [1:5] "0.0" "NaN" "NaN" "Inf" ... $ B=3 : chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=4 : chr [1:5] "0.0" "NaN" "NaN" "Inf" ... $ B=5 : chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=6 : chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=7 : chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=8 : chr [1:5] "0.0" "NaN" "NaN" "Inf" ... $ B=9 : chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=10: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=11: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=12: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=13: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=14: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=15: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=16: chr [1:5] "0.0" "NaN" "NaN" "Inf" ... $ B=17: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=18: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=19: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=20: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=21: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=22: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=23: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=24: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=25: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=26: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=27: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=28: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=29: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=30: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=31: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=32: chr [1:5] "0.0" "NaN" "NaN" "Inf" ... $ B=33: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=34: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=35: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=36: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=37: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=38: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=39: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=40: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=41: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=42: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=43: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=44: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=45: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=46: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=47: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=48: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=49: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=50: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=51: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=52: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=53: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=54: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=55: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=56: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=57: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=58: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=59: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=60: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=61: chr [1:5] "0." "NaN" "NaN" "Inf" ... $ B=62: chr [1:5] "0." "NaN" "NaN" "Inf" ... > > t2 <- mpfr(2^10,3) > ## digits = 1 used to crash: MPFR assertion failed: m >= 2 || ((((b) & ((b) - 1)) == 0) == 0 && m >= 1) > ## ---------- (+ seg.fault) for 'base = 2' (and others, not for default base = 10), > ## digits = NULL should choose "enough" ... but does not > str(r <- lapply(B.set, function(B) .mpfr2str(t2, digits=1, base = B))) base = 2, digits = 1 is increased to digits = 2 base = 4, digits = 1 is increased to digits = 2 base = 8, digits = 1 is increased to digits = 2 base = 16, digits = 1 is increased to digits = 2 base = 32, digits = 1 is increased to digits = 2 List of 61 $ B=2 :List of 4 ..$ str : chr "10" ..$ exp : int 11 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=3 :List of 4 ..$ str : chr "1" ..$ exp : int 7 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=4 :List of 4 ..$ str : chr "10" ..$ exp : int 6 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=5 :List of 4 ..$ str : chr "2" ..$ exp : int 5 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=6 :List of 4 ..$ str : chr "5" ..$ exp : int 4 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=7 :List of 4 ..$ str : chr "3" ..$ exp : int 4 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=8 :List of 4 ..$ str : chr "20" ..$ exp : int 4 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=9 :List of 4 ..$ str : chr "1" ..$ exp : int 4 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=10:List of 4 ..$ str : chr "1" ..$ exp : int 4 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=11:List of 4 ..$ str : chr "8" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=12:List of 4 ..$ str : chr "7" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=13:List of 4 ..$ str : chr "6" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=14:List of 4 ..$ str : chr "5" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=15:List of 4 ..$ str : chr "5" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=16:List of 4 ..$ str : chr "40" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=17:List of 4 ..$ str : chr "4" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=18:List of 4 ..$ str : chr "3" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=19:List of 4 ..$ str : chr "3" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=20:List of 4 ..$ str : chr "3" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=21:List of 4 ..$ str : chr "2" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=22:List of 4 ..$ str : chr "2" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=23:List of 4 ..$ str : chr "2" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=24:List of 4 ..$ str : chr "2" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=25:List of 4 ..$ str : chr "2" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=26:List of 4 ..$ str : chr "2" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=27:List of 4 ..$ str : chr "1" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=28:List of 4 ..$ str : chr "1" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=29:List of 4 ..$ str : chr "1" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=30:List of 4 ..$ str : chr "1" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=31:List of 4 ..$ str : chr "1" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=32:List of 4 ..$ str : chr "10" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=33:List of 4 ..$ str : chr "v" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=34:List of 4 ..$ str : chr "u" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=35:List of 4 ..$ str : chr "t" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=36:List of 4 ..$ str : chr "s" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=37:List of 4 ..$ str : chr "S" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=38:List of 4 ..$ str : chr "R" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=39:List of 4 ..$ str : chr "Q" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=40:List of 4 ..$ str : chr "Q" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=41:List of 4 ..$ str : chr "P" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=42:List of 4 ..$ str : chr "O" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=43:List of 4 ..$ str : chr "O" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=44:List of 4 ..$ str : chr "N" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=45:List of 4 ..$ str : chr "N" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=46:List of 4 ..$ str : chr "M" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=47:List of 4 ..$ str : chr "M" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=48:List of 4 ..$ str : chr "L" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=49:List of 4 ..$ str : chr "L" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=50:List of 4 ..$ str : chr "K" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=51:List of 4 ..$ str : chr "K" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=52:List of 4 ..$ str : chr "K" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=53:List of 4 ..$ str : chr "J" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=54:List of 4 ..$ str : chr "J" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=55:List of 4 ..$ str : chr "J" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=56:List of 4 ..$ str : chr "I" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=57:List of 4 ..$ str : chr "I" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=58:List of 4 ..$ str : chr "I" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=59:List of 4 ..$ str : chr "H" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=60:List of 4 ..$ str : chr "H" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=61:List of 4 ..$ str : chr "H" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=62:List of 4 ..$ str : chr "H" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE > str(r. <- lapply(B.set, function(B) .mpfr2str(t2, base = B))) List of 61 $ B=2 :List of 4 ..$ str : chr "100" ..$ exp : int 11 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=3 :List of 4 ..$ str : chr "111" ..$ exp : int 7 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=4 :List of 4 ..$ str : chr "10" ..$ exp : int 6 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=5 :List of 4 ..$ str : chr "131" ..$ exp : int 5 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=6 :List of 4 ..$ str : chr "443" ..$ exp : int 4 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=7 :List of 4 ..$ str : chr "266" ..$ exp : int 4 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=8 :List of 4 ..$ str : chr "20" ..$ exp : int 4 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=9 :List of 4 ..$ str : chr "14" ..$ exp : int 4 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=10:List of 4 ..$ str : chr "10" ..$ exp : int 4 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=11:List of 4 ..$ str : chr "85" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=12:List of 4 ..$ str : chr "71" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=13:List of 4 ..$ str : chr "61" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=14:List of 4 ..$ str : chr "53" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=15:List of 4 ..$ str : chr "48" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=16:List of 4 ..$ str : chr "40" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=17:List of 4 ..$ str : chr "39" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=18:List of 4 ..$ str : chr "33" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=19:List of 4 ..$ str : chr "2g" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=20:List of 4 ..$ str : chr "2b" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=21:List of 4 ..$ str : chr "27" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=22:List of 4 ..$ str : chr "23" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=23:List of 4 ..$ str : chr "1m" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=24:List of 4 ..$ str : chr "1j" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=25:List of 4 ..$ str : chr "1g" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=26:List of 4 ..$ str : chr "1d" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=27:List of 4 ..$ str : chr "1b" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=28:List of 4 ..$ str : chr "19" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=29:List of 4 ..$ str : chr "16" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=30:List of 4 ..$ str : chr "14" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=31:List of 4 ..$ str : chr "12" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=32:List of 4 ..$ str : chr "10" ..$ exp : int 3 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=33:List of 4 ..$ str : chr "v1" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=34:List of 4 ..$ str : chr "u4" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=35:List of 4 ..$ str : chr "t9" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=36:List of 4 ..$ str : chr "sg" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=37:List of 4 ..$ str : chr "RP" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=38:List of 4 ..$ str : chr "Qa" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=39:List of 4 ..$ str : chr "QA" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=40:List of 4 ..$ str : chr "PO" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=41:List of 4 ..$ str : chr "Oe" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=42:List of 4 ..$ str : chr "OG" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=43:List of 4 ..$ str : chr "NZ" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=44:List of 4 ..$ str : chr "NC" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=45:List of 4 ..$ str : chr "MY" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=46:List of 4 ..$ str : chr "MC" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=47:List of 4 ..$ str : chr "Lb" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=48:List of 4 ..$ str : chr "LG" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=49:List of 4 ..$ str : chr "Ki" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=50:List of 4 ..$ str : chr "KO" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=51:List of 4 ..$ str : chr "K4" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=52:List of 4 ..$ str : chr "Ja" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=53:List of 4 ..$ str : chr "JH" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=54:List of 4 ..$ str : chr "Iq" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=55:List of 4 ..$ str : chr "IY" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=56:List of 4 ..$ str : chr "IG" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=57:List of 4 ..$ str : chr "Ht" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=58:List of 4 ..$ str : chr "Hc" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=59:List of 4 ..$ str : chr "HL" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=60:List of 4 ..$ str : chr "H4" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=61:List of 4 ..$ str : chr "Gm" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE $ B=62:List of 4 ..$ str : chr "GW" ..$ exp : int 2 ..$ finite: logi TRUE ..$ is.0 : logi FALSE > ## FIXME: still too short > > x <- c(-12, 1:3 * pi) > sss <- mpfr(x, 100) > validObject(sss) [1] TRUE > sss 4 'mpfr' numbers of precision 100 bits [1] -12 3.1415926535897931159979634685442 [3] 6.2831853071795862319959269370884 9.4247779607693793479938904056326 > sss2 <- sss * sss > stopifnot(identical(sss2, sss * x), + identical(sss2, x * sss), + sss ^ 2 == sss2) > ## and go back {not sure if identical() is guaranteed here, but it seems...}: > stopifnot(identical(x, as(sss, "numeric"))) > > (cs <- as(sss, "character")) [1] "-12" "3.1415926535897931159979634685442" [3] "6.2831853071795862319959269370884" "9.4247779607693793479938904056326" > > y <- c(0, 100,-10, 1.25, -2.5, + x * c(1,100,1e5,1e20), + x / 100^(1:4)) > (Y <- mpfr(y, 100)) 13 'mpfr' numbers of precision 100 bits [1] 0 100 [3] -10 1.25 [5] -2.5 -12 [7] 314.15926535897932581065106205642 628318.53071795857977122068405151 [9] 942477796076937936896 -0.11999999999999999555910790149937 [11] 0.00031415926535897930899771113288921 6.2831853071795866542926731201923e-6 [13] 9.4247779607693799284994504768947e-8 > cbind(y, as.data.frame(.mpfr2str(Y, 20))[,c("exp","str")]) y exp str 1 0.000000e+00 0 00000000000000000000 2 1.000000e+02 3 10000000000000000000 3 -1.000000e+01 2 -10000000000000000000 4 1.250000e+00 1 12500000000000000000 5 -2.500000e+00 1 -25000000000000000000 6 -1.200000e+01 2 -12000000000000000000 7 3.141593e+02 3 31415926535897932581 8 6.283185e+05 6 62831853071795857977 9 9.424778e+20 21 94247779607693793690 10 -1.200000e-01 0 -11999999999999999556 11 3.141593e-04 -3 31415926535897930900 12 6.283185e-06 -5 62831853071795866543 13 9.424778e-08 -7 94247779607693799285 > > s <- mpfr(43208, 14)# low precision > eps8 <- 8 * .Machine$double.eps > ## checking mpfr -> character -> mpfr: > i1..5f <- c("4.e+4", "4.3e+4", "4.32e+4", "43210.", "43208.") > stopifnot(exprs = { + all.equal(y, as.numeric(format(Y, digits=20)), tol= eps8) + all.equal(Y, as(format(Y), "mpfr"), tol= eps8) + identical(sapply(1:5, formatMpfr, x=s), i1..5f) + identical(sapply(1:5, formatMpfr, x=s, exponent.plus=FALSE), + sub("e[+]", "e", i1..5f)) + }) > > > ## More character -> mpfr checking : > ## from echo 'scale=200; 4*a(1)' | bc -l : > cpi <- "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196" > pi. <- Const("pi", prec=667) > stopifnot(cpi == format(mpfr(cpi, prec=667), digits=201), + all.equal(pi., as(cpi, "mpfr")), + all.equal(pi., as(cpi, "mpfr"), tol = 1e-200)) > > set.seed(17) > ## Check double -> mpfr -> character -> double : > ## Unfortunately, format(, .) -> .mpfr2str() triggers a memory bug > ## that I think is an MPFR library "mis-feature" > ## 2011-02-09 -- bug *no longer* triggered ! > rSign <- function(n) sample(c(-1,1), size = n, replace=TRUE) > N <- function(x) as.numeric(x) > ntry <- if(Sys.getenv("USER") == "maechler") 150 else 5 > for(n in 1:ntry) { + cat(if(n %% 10)"." else n) + x. <- rSign(100) * rlnorm(100) + prec <- rpois(1, 110); digs <- floor(0.95*(prec / log2(10))) + X. <- mpfr(x., precBits = prec) + stopifnot(all.equal(x., N(format(X., digits=digs)), tol = eps8) + , all.equal(x., N(log(exp(X.))), tol = 32*eps8) + ) + }; cat("\n") ..... > > stopifnot(identical(mpfr.is.0(X.),# deprecated but must work + mpfrIs0 (X.))) Warning message: In mpfr.is.0(X.) : 'mpfr.is.0' is deprecated. Use 'mpfrIs0' instead. See help("Deprecated") > X. <- X.[!mpfrIs0(X.)] > stopifnot(all( X./X. == 1)) # TRUE > > u <- mpfr(as.raw(0:100)) > z <- mpfr(1:12, 200) > z[z > 100] <- 100 # nothing done (but used to fail) > z[] <- 0 > stopifnot(0:100 == u, is(z,"mpfr"), mpfrIs0(z), + all.equal(u, mpfr(0:100, prec = 8), tol = 0), + 0:1 == mpfr(1:2 %% 2 == 0)) > z[3] <- Const("pi",200) > ## z has length 12 -- now extend it: > z[15:17] <- 1/mpfr(10:12, 100) > stopifnot(all.equal(z[1:4], c(0,0,pi,0), tol = 1e-15), validObject(z), + all.equal(z[13:17], c(NaN,NaN, 1/(10:12)), tol = 1e-15)) > > ## These seg.faulted (each via different R -> C interface) in the past: > assertError <- tools::assertError > assertError( pp <- Const("pi", prec = 1e11) ) > assertError( mpfr("123.456", precBits= 1e11) ) > assertError( mpfr(as.bigz(3), precBits= 1e11) ) > > stopifnot(identical(mpfr(NULL), mpfr(logical()))) > > ## mpfr --> bigInteger "bigz" > Pi <- Const("pi", prec = 300) > twoP <- mpfr(2, 100)^(-2:80) > m <- Pi * twoP > L <- mpfr(2, 256)^1000 > stopifnot(exprs = { + .mpfr2bigz(Pi) == 3 + .mpfr2bigz(twoP) == as.bigz(c(0,0, 2^(0:80))) + .mpfr2bigz(m) == floor(m) + .mpfr2bigz(m / L) == 0 + .mpfr2bigz(m * L) == floor(m * L) ## used to fail + .mpfr2bigz(m * L^8) == floor(m * L^8) ## (ditto) + }) > > proc.time() user system elapsed 1.35 0.12 1.46