Commit 17b44a35 authored by Antoine Lucas's avatar Antoine Lucas
Browse files

Merge branch 'master' of forgemia.inra.fr:sylvain.jasson/gmp

parents 43b19bcf 3ff21406
2020-05-11 Martin Maechler <maechler@stat.math.ethz.ch>
* R/AllClasses-etc.R (.diff.big): diff.big[zq]() methods
2020-03-30 Martin Maechler <maechler@stat.math.ethz.ch>
* R/matrixz.R[.dimZQ, .ncolZQ]: use `%/%` to get integer dim() and ncol()
......
Package: gmp
Version: 0.5-14
Date: 2020-05-08
Date: 2020-05-11
Title: Multiple Precision Arithmetic
Author: Antoine Lucas, Immanuel Scholz, Rainer Boehme <rb-gmp@reflex-studio.de>,
Sylvain Jasson <Sylvain.Jasson@inrae.fr>,
......
......@@ -230,6 +230,9 @@ S3method(solve,bigz)
S3method(t,bigq)
S3method(t,bigz)
S3method(diff, bigz, .diff.big)
S3method(diff, bigq, .diff.big)
## S4 generic .. also imported in Rmpfr
export(asNumeric)
exportMethods(asNumeric)
......
......@@ -12,3 +12,28 @@
setOldClass("bigz")#, prototype=as.bigz(integer()))
setOldClass("bigq")#, prototype=as.bigq(integer()))
## cannot use as.bigz() yet which is only defined in ./bigz.R
## diff() method for these: this is just base::diff.default()
## ---- with 2 lines commented out: '##>>'
.diff.big <- function(x, lag = 1L, differences = 1L, ...)
{
ismat <- is.matrix(x)
xlen <- if(ismat) dim(x)[1L] else length(x)
if (length(lag) != 1L || length(differences) > 1L ||
lag < 1L || differences < 1L)
stop("'lag' and 'differences' must be integers >= 1")
if (lag * differences >= xlen)
return(x[0L]) # empty, but of proper mode
r <- x ##>> r <- unclass(x) # don't want class-specific subset methods
i1 <- -seq_len(lag)
if (ismat)
for (i in seq_len(differences))
r <- r[i1, , drop = FALSE] -
r[-nrow(r):-(nrow(r)-lag+1L), , drop = FALSE]
else
for (i in seq_len(differences))
r <- r[i1] - r[-length(r):-(length(r)-lag+1L)]
##>> class(r) <- oldClass(x)
r
}
##--> and entries in ../NAMESPACE
......@@ -203,3 +203,14 @@ if(FALSE) { ## FIXME: pmin() / pmax() are completely wrong for "bigq" !!
} else
message("{Rmpfr + gmp} checks __not__ done")
##--------------------------- order(), sort.list() --------------------------
x <- as.bigz("0x123456789abcdef") # my secret message
B <- x + as.bigz(2)^(110:100)
(dB <- diff(B)) # now works
stopifnot(dB < 0,
log2(-dB) == 109:100 # 2^{n+1} - 2^n == 2^n
)
rev(B) # is sorted
is.unsorted(rev(B))# TRUE but should be FALSE
if(FALSE) ## not yet
identical(sort(B), rev(B))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment