set.seed(47)
x <- c(0, 2^(-3:3), (-1:1)/0,
sort(rlnorm(2^12, 10, 20) * sample(c(-1,1), 512, replace=TRUE)))
head(xM <- mpfr(x, 128), 11)
str(rFM <- frexpMpfr(xM))
d.fr <- with(rFM, data.frame(x=x, r=asNumeric(r), e=e))
head(d.fr , 16)
tail(d.fr)
ar <- abs(rFM$r)
stopifnot(0.5 <= ar[is.finite(x) & x != 0], ar[is.finite(x)] < 1,
is.integer(rFM$e))
ldx <- with(rFM, ldexpMpfr(r, e))
(iN <- which(is.na(x))) # 10
stopifnot(exprs = {
all.equal(xM, ldx, tol = 2^-124) # allow 4 bits loss, but apart from the NA, even:
identical(xM[-iN], ldx[-iN])
is.na(xM [iN])
is.na(ldx[iN])
})
Run the code above in your browser using DataLab