gmp/0000755000176200001440000000000014662153602011042 5ustar liggesusersgmp/tests/0000755000176200001440000000000014662051113012176 5ustar liggesusersgmp/tests/arith-ex.R0000644000176200001440000002367214444267422014066 0ustar liggesuserslibrary(gmp) ## for reference (==> *not* using *.Rout.save here!) sessionInfo() packageDescription("gmp") ##' an (x == y) which gives TRUE also when both are NA: isEQ <- function(x,y) (x == y) | (is.na(x) & is.na(y)) ## want to test all these (ops <- sapply(getGroupMembers("Ops"), getGroupMembers)) N. <- as.bigz(NA) Nq <- as.bigq(NA) stopifnot(identical(Nq, as.bigq(N.)), identical(N., as.bigz(Nq)))# used to fail xx <- c(NaN, NA, -Inf, -123:-121, -1:2, 7:8, Inf) (xxI <- as.bigz(xx))# Inf's and NaN's do not exist ==> very large integers for +/- Inf (x <- c(NA, xx[is.finite(xx)])) xI <- as.bigz(x) xQ <- as.bigq(xI) stopifnot(identical(xI, as.bigz(xQ)), identical(numerator(xQ), xI)) # numerator( ) stopifnot(isEQ(x, as.integer(x)), isEQ(x, xI), isEQ(x, xQ), identical(xQ, as.bigq(x)), identical(is.na(x), is.na(xI)), identical(is.na(x), is.na(xQ)), identical(is.finite(x), is.finite(xI)), identical(is.finite(x), is.finite(xQ)), identical(is.infinite(x), is.infinite(xI)), identical(is.infinite(x), is.infinite(xQ)), ## The next 4 all failed till 2012-05-05: isEQ(x, as.integer(xI)), isEQ(x, as.integer(xQ)), isEQ(x, as.numeric(xI)), isEQ(x, as.numeric(xQ)), TRUE) ## Finally (2020-06-06): mixed arithmetic works : stopifnot(exprs = { isEQ(xI - xQ, c(NA, rep(0, 9))) isEQ(xI + xQ, 2*xI) isEQ(xI * xQ, x^2) all.equal(xQ^xI, x^x) ## as do mixed comparisons (xI == xQ)[-1] !(xI < xQ)[-1] !(xI > xQ)[-1] (xI >= xQ)[-1] }) ## double precision factorial() is exact up to n=22 stopifnot(factorialZ(0:22) == factorial(0:22)) ## factorialZ() etc must also work when passed a bigz instead of an integer; ## till Jan.2014, they silently produced nonsense. N <- as.bigz(n <- 3:8) stopifnot(identical(factorialZ(N), factorialZ(n)), factorialZ (n) == factorial(n), identical(chooseZ(12, N), chooseZ(12, n)), chooseZ(12,n) == choose(12,n), identical(fibnum (N), fibnum (n)), identical(fibnum2(N), fibnum2(n)), identical(lucnum (N), lucnum (n)), identical(lucnum2(N), lucnum2(n))) ## This one does *NOT* distinguish NA and NaN -- that's wanted here EQ1 <- function(x,y) { (abs(x-y) <= 1e-13*(abs(x)+abs(y)) & !(nx <- is.na(x)) & !(ny <- is.na(y))) | (nx & ny) } stopifnot(EQ1(x, xI)) EQ <- function(x,y) mapply(EQ1, x, y, USE.NAMES=FALSE) ## a version of outer() that should work also with these objects mOuter <- function(X, Y=X, FUN, ...) { lapply(seq_along(X), function(i) FUN(X[i], Y, ...)) } matOuter <- function(X, Y=X, FUN, ...) { t(array(unlist(mOuter(X, Y, FUN, ...)), dim = c(length(Y), length(X)))) } ##' @title ##' @param OP an arithmetic OPerator such +, *,.. as R function ##' @param u numeric vector ##' @param uI a bigz/biginteger vector, "the same" as 'u'. ##' @return a logical n x n matrix, say R, R[i,j] := TRUE iff ##' u[i] OP v[j] are all the same when u,v vary in {u, uI}. ##' @author Martin Maechler opEQ <- function(OP, u, uI=as.bigz(u), eq=TRUE) { stopifnot(length(u) == length(uI)) if(eq) stopifnot(isEQ(u, uI)) # should be the case when result should be all TRUE ## ## choose only some on the RHS: iR <- if(no0.R <- (identical(OP, `/`) || identical(OP, `%/%`) || identical(OP, `%%`))) { ## no zero on the RHS i.e., 2nd operand is.na(u) | u != 0 } else TRUE ## choose only some on the LHS: iL <- if(no0.L <- (identical(OP, `^`))) { ## no zero on the LHS i.e., 1st operand is.na(u) | u != 0 } else TRUE ## EQ(mOuter(u [iL],u [iR], OP) -> R, mOuter(uI[iL],uI[iR], OP)) & EQ(mOuter(u [iL],uI[iR], OP) -> S, mOuter(uI[iL], u[iR], OP)) & EQ(R, S) } ## "Compare" - works "out of the box eqC <- lapply(sapply(ops$Compare, get), function(op) opEQ(op, x, xI)) stopifnot(do.call(all, eqC)) opsA <- ops$Arith eqA <- lapply(sapply(opsA, get), function(op) opEQ(op, x, xI)) op6 <- c("+","-", "*", "/", "%/%", "^")## << are fine - now including "^" _and_ %/% ! stopifnot(sapply(eqA, all)[op6]) ## The others: now (2014-07): only %% is left: has several "wrong": lapply(eqA[is.na(match(names(eqA), op6))], symnum) ## For example: symnum(opEQ(`%%`, x, xI))# not all TRUE, since, e.g., x [3] %% x x [3] %% xI ## (negative turned into >= 0; warning 'division by zero') x %% x [3] xI %% x [3] ## (no negatives ..) ##-- "^" ------------ z1i <- 0:1 z1n <- as.double(z1i) c(NA^0, NA^0L, z1i^NA, z1n^NA)# <- in R (<= 2011), the first and last are 1 stopifnot(isEQ(c(N.^0, N.^0L, z1i^N.), c(1,1,NA,1)), isEQ(c(Nq^0, Nq^0L, z1i^Nq), c(1,1,NA,1))) ## need non-negative values: x.po0 <- x >= 0 stopifnot(M.pow <- opEQ(`^`, x[x.po0], xI[x.po0])) if(FALSE)# FIXME stopifnot(M.powQ <- opEQ(`^`, x[x.po0], xQ[x.po0])) if(FALSE)# FIXME {z - q} M.poIQ <- opEQ(`^`,xI[x.po0], xQ[x.po0]) ## Modulo arithmetic i <- as.bigz(-5:10, 16); i <- i[i != 0]; i stopifnot(identical(as.integer(i), c(11:15, 1:10))) (Ii <- 1/i )## BUG: in all versions of gmp up to 0.5-5 -- now 7 warnings pow(x, -|n|) I2 <- i^(-1)## BUG: not considering (mod) // segmentation fault in gmp 0.5-1 {now: 7 warn..} stopifnot(identical(Ii, I2), is.na(Ii[c(2, 4, 7, 9, 11, 13, 15)]), identical(Ii[c(1,3)], as.bigz(c(3,5), 16))) (Iz <- 1/(z <- as.bigz(1:12, 13))) stopifnot(identical(Iz, z^-1), Iz == c(1, 7, 9, 10, 8, 11, 2, 5, 3, 4, 6, 12), identical(modulus(Iz), as.bigz(13))) ## The first two of course give fractions: (r1 <- as.bigz(3) / 1:12) r2 <- as.bigz(3) / as.bigz(1:12) stopifnot(identical(r1, r2)) ## Now, the new scheme : (iLR <- as.bigz(3, 13) / as.bigz(1:12, 13)) ## [1] (3 %% 13) (8 %% 13) (1 %% 13) (4 %% 13) (11 %% 13) (7 %% 13) ## [7] (6 %% 13) (2 %% 13) (9 %% 13) (12 %% 13) (5 %% 13) (10 %% 13) iL <- as.bigz(3, 13) / as.bigz(1:12) iLi <- as.bigz(3, 13) / 1:12 iR <- as.bigz(3) / as.bigz(1:12, 13) iiR <- 3 / as.bigz(1:12, 13) stopifnot(identical(iL, iLi) , identical(iR, iiR) , identical(iR, iLR) , identical(iL, iR)) ## failed until recently... ## whereas these two always use divq.bigz : (q <- as.bigz(3, 13) %/% as.bigz(1:12)) ## [1] (3 %% 13) (1 %% 13) (1 %% 13) (0 %% 13) (0 %% 13) (0 %% 13) ## [7] (0 %% 13) (0 %% 13) (0 %% 13) (0 %% 13) (0 %% 13) (0 %% 13) stopifnot(identical(q, divq.bigz(as.bigz(3, 13), 1:12)), ## --------- identical(q, 3 %/% as.bigz(1:12, 13)), q == c(3, 1, 1, rep(0,9))) s <- as.bigz(3, 13) / as.bigz(1:12, 17) ## used to give ## Big Integer ('bigz') object of length 12: ## [1] 3 1 1 0 0 0 0 0 0 0 0 0 ## but now, really just `` drops the contradicting "mod" '' ==> uses rational: stopifnot(identical(s, r1)) ##----- Z^e (modulo m) --------------- z12 <- as.bigz(1:12,12) stopifnot(identical(z12^1, z12), z12^0 == 1, identical(z12^2, as.bigz(rep(c(1,4,9,4,1,0), 2), 12)), identical(z12^3, as.bigz(c(1,8,3:5,0,7:9,4,11,0), 12)), identical(z12^4, z12^2), identical(z12^5, z12^3), identical(z12^6, z12^2), identical(z12^6, (1:12) ^ as.bigz(6, 12)) ) for(E in 6:20) { ir <- as.integer(r <- z12 ^ E) stopifnot(identical(modulus(r), as.bigz(12)), 0 <= ir, ir <= 11) } z17 <- as.bigz(1:16, 17) stopifnot(z17^0 == 1, identical(z17^1, z17), identical(z17^-1, iz <- 1/z17), identical(z17^-2, iz^2), (iz^2) * (sq <- z17^2) == 1, modulus(sq) == 17, unique(sq) == (1:8)^2 %% 17) ##--- Log()s ------------------------- (ex <- c(outer(c(2,5,10), 10^(1:3))))# 20 .. 10'000 stopifnot(dim(L <- outer(as.bigz(2:4), ex, `^`)) == c(3, length(ex))) l2 <- array(log2(L), dim = dim(L)) lnL <- log(L) a.EQ <- function(x,y, tol=1e-15, ...) all.equal(x,y, tol=tol, ...) stopifnot(a.EQ(l2[1,], ex), a.EQ(l2[3,], 2*ex), a.EQ(log(L, 8), lnL/log(8)), a.EQ(c(l2), lnL/log(2))) ###------------------ bigq -------------------------------- xQ1 <- as.bigq(x, 1) eqC <- lapply(sapply(ops$Compare, get), function(op) opEQ(op, x, xQ1)) stopifnot(Reduce(`&`, eqC))## ## xQ <- as.bigq(x, 17) # == x/17 .. *are* not equal, i.e., not expecting all TRUE: eqQ <- lapply(sapply(ops$Compare, get), function(op) opEQ(op, x, xQ, eq=FALSE)) lapply(eqQ, symnum)## <- symnum, for nice output Fn <- gmp:::pow.bigq; q <- 2.3 stopifnot(inherits(e1 <- tryCatch(Fn(q,q), error=identity), "error"), inherits(e2 <- tryCatch(q ^ as.bigq(1,3), error=identity), "error"), grepl("Rmpfr", e1$message), identical(e1$message, e2$message)) ## FIXME(2): %% and %/% do not work at all for bigq (opsA4 <- opsA[opsA != "^" & !grepl("^%", opsA)]) eqA1 <- lapply(sapply(opsA4, get), function(op) opEQ(op, x, xQ1)) sapply(eqA1, table) ## .TRUE -.TRUE *.TRUE /.TRUE ## 100 100 100 90 ## ^^^^ (90: was 81) [not dividing by 0] ## xQ *is* different from x (apart from x[6] (and, NA x[1])) eqA <- lapply(sapply(opsA4, get), function(op) opEQ(op, x, xQ, eq=FALSE)) lapply(eqA, symnum) ## round(x, digits) -- should work *and* be vectorized in both (x, digits) x1 <- as.bigq((-19:19), 10) stopifnot(round(x1, 1) == x1) half <- as.bigq(1, 2) i1 <- (-19:29) x <- half + i1 cbind(x, round(x)) rx1 <- round(x/10, 1) stopifnot(exprs = { as.bigz(round(x)) %% 2 == 0 identical(round(x) > x, i1 %% 2 == 1) (rx1 - x/10) * 20 == c(1,-1) # {recycling up/down}: perfect rounding to even (round(x/100, 2) - x/100) * 200 == c(1,-1) # (ditto) }) (drx1 <- asNumeric(rx1))# shows perfect round to *even* ## but double precision rounding cannot be perfect (as numbers are not exact!): dx <- asNumeric(x/10) dx1 <- round(dx, 1) dmat <- cbind(x=dx, r.x = dx1, rQx = drx1) ## shows "the picture" a bit {see Martin's vignette in CRAN package 'round'}: noquote(cbind(apply(dmat, 2, formatC), ER = ifelse(abs(dx1 - drx1) > 1e-10, "*", ""))) ## standard R: rd <- round(pi*10^(-2:5), digits=7:0) formatC(rd, digits=12, width=1) ## bigq -- show we vectorize in both x, digits (rQ <- round(as.bigq(pi*10^(-2:5)), digits=7:0)) stopifnot(exprs = { as.integer(numerator (rQ)) == 314159L as.integer(denominator(rQ)) == 10^(7:0) all.equal(asNumeric(rQ), rd, tol = 1e-15) }) gmp/tests/gmp-test.Rout.save0000644000176200001440000040030114662051113015544 0ustar liggesusers R version 4.3.2 Patched (2024-01-28 r85841) -- "Eye Holes" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) 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. > library(gmp) Attaching package: 'gmp' The following objects are masked from 'package:base': %*%, apply, crossprod, matrix, tcrossprod > > ## > ##' @title Test a unary (if unary=TRUE) or *binary* function > ##' @param FUN a function, such as add.bigq() ... > ##' @param x a list of "numbers" > ##' @param out string determining output class; if "str", use characters, otherwise double > ##' @return > ##' @author Antoine Lucas (& Martin Maechler) > ##' @examples test(as.bigq, 0) > test <- function(FUN, x, xlabs, out = "str", unary = FALSE) + { + if(missing(xlabs)) + xlabs <- if(is.character(names(x))) names(x) else sapply(x, formatN) + stopifnot(is.function(FUN), is.list(x), + (n <- length(x)) >= 1, length(xlabs) == n) + if(out == "str") { + sortie <- as.character + res <- "" + error <- "error" + } else { + sortie <- as.double + res <- 0 + error <- NA + } + nr <- if(unary) 1 else n + xlabs <- gsub(" ", "", xlabs) + res <- matrix(res, nr, n, + dimnames = list(if(!unary) abbreviate(xlabs, 11, named=FALSE), xlabs)) + for(i in 1:nr){ + classNameI = class(x[[i]]) + for(j in 1:n) { + classNameJ = class(x[[j]]) + + e <- if(unary) tryCatch(FUN(x[[j]]), error=identity) else + tryCatch(FUN(x[[i]],x[[j]]), error=identity) + if(inherits(e, "error")) + e <- error + else if(length(e) == 0) + e <- numeric() + ## we don't test standard R floating operations. + if( (classNameI[1] == "numeric" || classNameI[1] == "integer") && ( classNameJ[1] == "numeric" || classNameJ[1] == "integer") && class(e)[1] == "numeric") e <- "-" + + ## ## now, for some functions also compute the corresponding numeric values + if(length(e) > 0 && is.double(e[1]) && is.finite(e[1])) + e <- format(signif(e[1], digits=14), digits=7) # signif(), not round() + + res[i,j] <- sortie(e)[1] + } + } + res ## for printing, the user may prefer as.data.frame(.) + }## end{test} > > > allfunctionid <- c("as.bigz","+","-","*", + "divq.bigz","/","%%","^", + "inv.bigz", "gcd.bigz", "gcdex", "lcm.bigz", + "as.bigq", + "chooseZ", + "max","min","|","&","xor","c","cbind","rbind") > unaryfunctionid <- c("log","log2","log10","c", + "isprime","nextprime", "factorialZ", + "sizeinbase","fibnum","fibnum2","lucnum","lucnum2", + "factorize","abs","!") > numericFunName <- function(gmpName) { + if(gmpName != (r <- sub("[ZQ]$","", gmpName)) && + r!="as" && existsFunction(r)) # e.g. chooseZ + return(r) + if(gmpName != (r <- sub("\\.big[zq]$","", gmpName)) && + r!="as" && r!="sub" && existsFunction(r)) + return(r) + ttt <- c("add" = "+", + "sub" = "-", + "mul" = "*", + "pow" = "^", + "div" = "/", + "divq" = "%/%", + "mod" = "%%") + if(!is.na(t.r <- ttt[r])) + t.r[[1L]] + else ## return argument + gmpName + } > > > options(width = 140, nwarnings = 10000) > > sapply(allfunctionid, numericFunName) as.bigz + - * divq.bigz / %% ^ inv.bigz gcd.bigz gcdex lcm.bigz "as.bigz" "+" "-" "*" "%/%" "/" "%%" "^" "inv.bigz" "gcd" "gcdex" "lcm" as.bigq chooseZ max min | & xor c cbind rbind "as.bigq" "choose" "max" "min" "|" "&" "xor" "c" "cbind" "rbind" > sapply(unaryfunctionid, numericFunName) log log2 log10 c isprime nextprime factorialZ sizeinbase fibnum fibnum2 "log" "log2" "log10" "c" "isprime" "nextprime" "factorial" "sizeinbase" "fibnum" "fibnum2" lucnum lucnum2 factorize abs ! "lucnum" "lucnum2" "factorize" "abs" "!" > > > ex <- expression(23,as.bigz(23),as.bigq(23),c(3,23),as.bigz(c(3,23)),as.bigq(c(3,23)), "25", 2.3, -4, 4L, 0, as.bigz(34), + as.bigq(32,7), as.bigz(31,45), NULL,NA, -3L)## TODO: as.bigz(3)^700 > x <- lapply(ex, eval) > > ## Those "numbers" in x for which arithmetic should also work in double precision: > ## not modulo-arithmetic, not larger than double.prec > useN <- sapply(x, function(u) is.null(u[1]) || is.na(u[1]) || + (is.finite(as.numeric(u[1])) && (!inherits(u[1], "bigz") || is.null(modulus(u[1]))))) > names(x) <- vapply(ex, format, "") > if(FALSE)## shorter & easier {but *not* the original calls from 'ex'} + names(x) <- sapply(x, formatN) > str(x) List of 17 $ 23 : num 23 $ as.bigz(23) : 'bigz' raw 23 $ as.bigq(23) : 'bigq' raw 23 ..- attr(*, "denominator")= raw [1:16] 01 00 00 00 ... $ c(3, 23) : num [1:2] 3 23 $ as.bigz(c(3, 23)): 'bigz' raw [1:2] 3 23 $ as.bigq(c(3, 23)): 'bigq' raw [1:2] 3 23 ..- attr(*, "denominator")= raw [1:28] 02 00 00 00 ... $ 25 : chr "25" $ 2.3 : num 2.3 $ -4 : num -4 $ 4 : int 4 $ 0 : num 0 $ as.bigz(34) : 'bigz' raw 34 $ as.bigq(32, 7) : 'bigq' raw 32/7 ..- attr(*, "denominator")= raw [1:16] 01 00 00 00 ... $ as.bigz(31, 45) : 'bigz' raw (31 %% 45) ..- attr(*, "mod")= 'bigz' raw 45 $ NULL : NULL $ NA : logi NA $ -3L : int -3 > x. <- x[useN] > nx <- lapply(x., as.numeric) > gmp.NS <- asNamespace("gmp")# also get namespace *hidden* functions, i.e. methods: > for(fid in allfunctionid) + { + cat ("------------------------------------------\n", fid," ", sep="") + FUN <- get(fid, envir = gmp.NS, mode="function") + rc <- test(FUN, x ) + res <- test(FUN, x. , out = "numeric") + if((nfid <- numericFunName(fid)) != fid || existsFunction(nfid, where=baseenv())) { + FUN <- get(nfid, envir = gmp.NS, mode="function") + if(nfid != fid) cat("-> num.fn.:", nfid) + nres <- test(FUN, nx, out = "numeric") + cat("\n-> all.equal(target = res, current = F()): ", + all.equal(res, nres), "\n") + } else cat("\n\n") + print(as.data.frame(rc)); cat("\n") + ## ^^^^^^^^^^^^^ (for now, to diminuish difference to last version ) + } ------------------------------------------ as.bigz -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 60 in current 46 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 23 (0 %% 23) (0 %% 23) (0 %% 23) (2 %% 3) (2 %% 3) (2 %% 3) (23 %% 25) (1 %% 2) (3 %% -4) (3 %% 4) error as.bigz(23) (0 %% 23) (0 %% 23) (0 %% 23) (2 %% 3) (2 %% 3) (2 %% 3) (23 %% 25) (1 %% 2) (3 %% -4) (3 %% 4) error as.bigq(23) (0 %% 23) (0 %% 23) (0 %% 23) (2 %% 3) (2 %% 3) (2 %% 3) (23 %% 25) (1 %% 2) (3 %% -4) (3 %% 4) error c(3,23) (3 %% 23) (3 %% 23) (3 %% 23) (0 %% 3) (0 %% 3) (0 %% 3) (3 %% 25) (1 %% 2) (3 %% -4) (3 %% 4) error as.bgz((3,23)) (3 %% 23) (3 %% 23) (3 %% 23) (0 %% 3) (0 %% 3) (0 %% 3) (3 %% 25) (1 %% 2) (3 %% -4) (3 %% 4) error as.bgq((3,23)) (3 %% 23) (3 %% 23) (3 %% 23) (0 %% 3) (0 %% 3) (0 %% 3) (3 %% 25) (1 %% 2) (3 %% -4) (3 %% 4) error 25 (2 %% 23) (2 %% 23) (2 %% 23) (1 %% 3) (1 %% 3) (1 %% 3) (0 %% 25) (1 %% 2) (1 %% -4) (1 %% 4) error 2.3 (2 %% 23) (2 %% 23) (2 %% 23) (2 %% 3) (2 %% 3) (2 %% 3) (2 %% 25) (0 %% 2) (2 %% -4) (2 %% 4) error -4 (19 %% 23) (19 %% 23) (19 %% 23) (2 %% 3) (2 %% 3) (2 %% 3) (21 %% 25) (0 %% 2) (0 %% -4) (0 %% 4) error 4 (4 %% 23) (4 %% 23) (4 %% 23) (1 %% 3) (1 %% 3) (1 %% 3) (4 %% 25) (0 %% 2) (0 %% -4) (0 %% 4) error 0 (0 %% 23) (0 %% 23) (0 %% 23) (0 %% 3) (0 %% 3) (0 %% 3) (0 %% 25) (0 %% 2) (0 %% -4) (0 %% 4) error as.bigz(34) (11 %% 23) (11 %% 23) (11 %% 23) (1 %% 3) (1 %% 3) (1 %% 3) (9 %% 25) (0 %% 2) (2 %% -4) (2 %% 4) error as.bg(32,7) (4 %% 23) (4 %% 23) (4 %% 23) (1 %% 3) (1 %% 3) (1 %% 3) (4 %% 25) (0 %% 2) (0 %% -4) (0 %% 4) error as.b(31,45) (8 %% 23) (8 %% 23) (8 %% 23) (1 %% 3) (1 %% 3) (1 %% 3) (6 %% 25) (1 %% 2) (3 %% -4) (3 %% 4) error NULL NA NA NA NA NA NA NA NA NA NA NA error -3L (20 %% 23) (20 %% 23) (20 %% 23) (0 %% 3) (0 %% 3) (0 %% 3) (22 %% 25) (1 %% 2) (1 %% -4) (1 %% 4) error as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 (23 %% 34) (23 %% 32) (23 %% 31) 23 23 (2 %% -3) as.bigz(23) (23 %% 34) (23 %% 32) (23 %% 31) 23 23 (2 %% -3) as.bigq(23) (23 %% 34) (23 %% 32) (23 %% 31) 23 23 (2 %% -3) c(3,23) (3 %% 34) (3 %% 32) (3 %% 31) 3 3 (0 %% -3) as.bgz((3,23)) (3 %% 34) (3 %% 32) (3 %% 31) 3 3 (0 %% -3) as.bgq((3,23)) (3 %% 34) (3 %% 32) (3 %% 31) 3 3 (0 %% -3) 25 (25 %% 34) (25 %% 32) (25 %% 31) 25 25 (1 %% -3) 2.3 (2 %% 34) (2 %% 32) (2 %% 31) 2 2 (2 %% -3) -4 (30 %% 34) (28 %% 32) (27 %% 31) -4 -4 (2 %% -3) 4 (4 %% 34) (4 %% 32) (4 %% 31) 4 4 (1 %% -3) 0 (0 %% 34) (0 %% 32) (0 %% 31) 0 0 (0 %% -3) as.bigz(34) (0 %% 34) (2 %% 32) (3 %% 31) 34 34 (1 %% -3) as.bg(32,7) (4 %% 34) (4 %% 32) (4 %% 31) 4 4 (1 %% -3) as.b(31,45) (31 %% 34) (31 %% 32) (0 %% 31) 31 31 (1 %% -3) NULL NA NA NA NA NA NA NA -3L (31 %% 34) (29 %% 32) (28 %% 31) -3 -3 (0 %% -3) ------------------------------------------ + -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 256 in current 120 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 23 - 46 46 - 26 26 as.bigz(23) 46 46 46 26 26 26 as.bigq(23) 46 46 46 26 26 26 c(3,23) - 26 26 - 6 6 as.bgz((3,23)) 26 26 26 6 6 6 as.bgq((3,23)) 26 26 26 6 6 6 25 error 48 48 error 28 28 2.3 - 25 28485267643118387/1125899906842624 - 5 5967269506265907/1125899906842624 -4 - 19 19 - -1 -1 4 - 27 27 - 7 7 0 - 23 23 - 3 3 as.bigz(34) 57 57 57 37 37 37 as.bg(32,7) 193/7 193/7 193/7 53/7 53/7 53/7 as.b(31,45) (9 %% 45) (9 %% 45) 54 (34 %% 45) (34 %% 45) 34 NULL NA NA NA NA NA -3L - 20 20 - 0 0 25 2.3 -4 4 0 as.bigz(34) 23 error - - - - 57 as.bigz(23) 48 25 19 27 23 57 as.bigq(23) 48 28485267643118387/1125899906842624 19 27 23 57 c(3,23) error - - - - 37 as.bgz((3,23)) 28 5 -1 7 3 37 as.bgq((3,23)) 28 5967269506265907/1125899906842624 -1 7 3 37 25 error error error error error 59 2.3 error - - - - 36 -4 error - - - - 30 4 error - - 8 - 38 0 error - - - - 34 as.bigz(34) 59 36 30 38 34 68 as.bg(32,7) 207/7 54155785519130213/7881299347898368 4/7 60/7 32/7 270/7 as.b(31,45) (11 %% 45) (33 %% 45) (27 %% 45) (35 %% 45) (31 %% 45) (20 %% 45) NULL error NA error NA -3L error - - 1 - 31 as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 193/7 (9 %% 45) - as.bigz(23) 193/7 (9 %% 45) NA 20 as.bigq(23) 193/7 54 NA 20 c(3,23) 53/7 (34 %% 45) - as.bgz((3,23)) 53/7 (34 %% 45) NA 0 as.bgq((3,23)) 53/7 34 NA 0 25 207/7 (11 %% 45) error error error 2.3 54155785519130213/7881299347898368 (33 %% 45) - -4 4/7 (27 %% 45) - 4 60/7 (35 %% 45) 1 0 32/7 (31 %% 45) - as.bigz(34) 270/7 (20 %% 45) NA 31 as.bg(32,7) 64/7 249/7 NA 11/7 as.b(31,45) 249/7 (17 %% 45) NA (28 %% 45) NULL NA NA NA -3L 11/7 (28 %% 45) -6 ------------------------------------------ - -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 256 in current 114 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 23 - 0 0 - 20 20 as.bigz(23) 0 0 0 20 20 20 as.bigq(23) 0 0 0 20 20 20 c(3,23) - -20 -20 - 0 0 as.bgz((3,23)) -20 -20 -20 0 0 0 as.bgq((3,23)) -20 -20 -20 0 0 0 25 error 2 2 error 22 22 2.3 - -21 -23306128071642317/1125899906842624 - -1 -788129934789837/1125899906842624 -4 - -27 -27 - -7 -7 4 - -19 -19 - 1 1 0 - -23 -23 - -3 -3 as.bigz(34) 11 11 11 31 31 31 as.bg(32,7) -129/7 -129/7 -129/7 11/7 11/7 11/7 as.b(31,45) (8 %% 45) (8 %% 45) 8 (28 %% 45) (28 %% 45) 28 NULL NA NA NA NA NA -3L - -26 -26 - -6 -6 25 2.3 -4 4 0 as.bigz(34) 23 error - - - - -11 as.bigz(23) -2 21 27 19 23 -11 as.bigq(23) -2 23306128071642317/1125899906842624 27 19 23 -11 c(3,23) error - - - - -31 as.bgz((3,23)) -22 1 7 -1 3 -31 as.bgq((3,23)) -22 788129934789837/1125899906842624 7 -1 3 -31 25 error error error error error -9 2.3 error - - - - -32 -4 error - - - - -38 4 error - - 0 - -30 0 error - - - - -34 as.bigz(34) 9 32 38 30 34 0 as.bg(32,7) -143/7 17901808518797723/7881299347898368 60/7 4/7 32/7 -206/7 as.b(31,45) (6 %% 45) (29 %% 45) (35 %% 45) (27 %% 45) (31 %% 45) (42 %% 45) NULL error NA error NA -3L error - - -7 - -37 as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 129/7 (37 %% 45) - as.bigz(23) 129/7 (37 %% 45) -23 NA 26 as.bigq(23) 129/7 -8 -23 NA 26 c(3,23) -11/7 (17 %% 45) - as.bgz((3,23)) -11/7 (17 %% 45) -3 NA 6 as.bgq((3,23)) -11/7 -28 -3 NA 6 25 143/7 (39 %% 45) error error error 2.3 -17901808518797723/7881299347898368 (16 %% 45) - -4 -60/7 (10 %% 45) - 4 -4/7 (18 %% 45) 7 0 -32/7 (14 %% 45) - as.bigz(34) 206/7 (3 %% 45) -34 NA 37 as.bg(32,7) 0 -185/7 -32/7 NA 53/7 as.b(31,45) 185/7 (0 %% 45) (14 %% 45) NA (34 %% 45) NULL NA NA NA -3L -53/7 (11 %% 45) 0 ------------------------------------------ * -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 256 in current 120 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 23 - 529 529 - 69 69 as.bigz(23) 529 529 529 69 69 69 as.bigq(23) 529 529 529 69 69 69 c(3,23) - 69 69 - 9 9 as.bgz((3,23)) 69 69 69 9 9 9 as.bgq((3,23)) 69 69 69 9 9 9 25 error 575 575 error 75 75 2.3 - 46 59560105071974805/1125899906842624 - 6 7768709357214105/1125899906842624 -4 - -92 -92 - -12 -12 4 - 92 92 - 12 12 0 - 0 0 - 0 0 as.bigz(34) 782 782 782 102 102 102 as.bg(32,7) 736/7 736/7 736/7 96/7 96/7 96/7 as.b(31,45) (38 %% 45) (38 %% 45) 713 (3 %% 45) (3 %% 45) 93 NULL NA NA NA NA NA -3L - -69 -69 - -9 -9 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) 23 error - - - - 782 736/7 as.bigz(23) 575 46 -92 92 0 782 736/7 as.bigq(23) 575 59560105071974805/1125899906842624 -92 92 0 782 736/7 c(3,23) error - - - - 102 96/7 as.bgz((3,23)) 75 6 -12 12 0 102 96/7 as.bgq((3,23)) 75 7768709357214105/1125899906842624 -12 12 0 102 96/7 25 error error error error error 850 800/7 2.3 error - - - - 68 2589569785738035/246290604621824 -4 error - - - - -136 -128/7 4 error - - 16 - 136 128/7 0 error - - - - 0 0 as.bigz(34) 850 68 -136 136 0 1156 1088/7 as.bg(32,7) 800/7 2589569785738035/246290604621824 -128/7 128/7 0 1088/7 1024/49 as.b(31,45) (10 %% 45) (17 %% 45) (11 %% 45) (34 %% 45) (0 %% 45) (19 %% 45) 992/7 NULL error NA error NA NA -3L error - - -12 - -102 -96/7 as.bigz(31,45) NULL NA -3L 23 (38 %% 45) - as.bigz(23) (38 %% 45) NA -69 as.bigq(23) 713 NA -69 c(3,23) (3 %% 45) - as.bgz((3,23)) (3 %% 45) NA -9 as.bgq((3,23)) 93 NA -9 25 (10 %% 45) error error error 2.3 (17 %% 45) - -4 (11 %% 45) - 4 (34 %% 45) -12 0 (0 %% 45) - as.bigz(34) (19 %% 45) NA -102 as.bg(32,7) 992/7 NA -96/7 as.b(31,45) (16 %% 45) NA (42 %% 45) NULL NA NA -3L (42 %% 45) 9 ------------------------------------------ divq.bigz -> num.fn.: %/% -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 256 in current 102 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 23 1 1 error 7 7 error 0 11 -6 5 as.bigz(23) 1 1 error 7 7 error 0 11 -6 5 as.bigq(23) 1 1 error 7 7 error 0 11 -6 5 c(3,23) 0 0 error 1 1 error 0 1 -1 0 as.bgz((3,23)) 0 0 error 1 1 error 0 1 -1 0 as.bgq((3,23)) 0 0 error 1 1 error 0 1 -1 0 25 1 1 error 8 8 error 1 12 -7 6 2.3 0 0 error 0 0 error 0 1 -1 0 -4 -1 -1 error -2 -2 error -1 -2 1 -1 4 0 0 error 1 1 error 0 2 -1 1 0 0 0 error 0 0 error 0 0 0 0 as.bigz(34) 1 1 error 11 11 error 1 17 -9 8 as.bg(32,7) 1 1 error 10 10 error 1 16 -8 8 as.b(31,45) (1 %% 45) (1 %% 45) error (10 %% 45) (10 %% 45) error (1 %% 45) (15 %% 45) (37 %% 45) (7 %% 45) NULL error error NA NA NA error NA NA error NA NA NA NA -3L -1 -1 error -1 -1 error -1 -2 0 -1 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 NA 0 5 (0 %% 45) NA -8 as.bigz(23) NA 0 5 (0 %% 45) NA -8 as.bigq(23) NA 0 5 (0 %% 45) NA -8 c(3,23) NA 0 0 (0 %% 45) NA -1 as.bgz((3,23)) NA 0 0 (0 %% 45) NA -1 as.bgq((3,23)) NA 0 0 (0 %% 45) NA -1 25 NA 0 6 (0 %% 45) NA -9 2.3 NA 0 0 (0 %% 45) NA -1 -4 NA -1 -1 (44 %% 45) NA 1 4 NA 0 1 (0 %% 45) NA -2 0 NA 0 0 (0 %% 45) NA 0 as.bigz(34) NA 1 8 (1 %% 45) NA -12 as.bg(32,7) NA 0 8 (1 %% 45) NA -11 as.b(31,45) NA (0 %% 45) (7 %% 45) (1 %% 45) NA (34 %% 45) NULL NA NA NA NA NA NA NA -3L NA -1 -1 (44 %% 45) NA 1 ------------------------------------------ / -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 256 in current 130 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) 23 - 1 1 - 23/3 as.bigz(23) 1 1 1 23/3 23/3 as.bigq(23) 1 1 1 23/3 23/3 c(3,23) - 3/23 3/23 - 1 as.bgz((3,23)) 3/23 3/23 3/23 1 1 as.bgq((3,23)) 3/23 3/23 3/23 1 1 25 error 25/23 25/23 error 25/3 2.3 - 2589569785738035/25895697857380352 2589569785738035/25895697857380352 - 863189928579345/1125899906842624 -4 - -4/23 -4/23 - -4/3 4 - 4/23 4/23 - 4/3 0 - 0 0 - 0 as.bigz(34) 34/23 34/23 34/23 34/3 34/3 as.bg(32,7) 32/161 32/161 32/161 32/21 32/21 as.b(31,45) (17 %% 45) (17 %% 45) 31/23 NA NA NULL NA NA NA NA -3L - -3/23 -3/23 - -1 as.bigq(c(3,23)) 25 2.3 -4 4 0 23 23/3 error - - - - as.bigz(23) 23/3 23/25 25895697857380352/2589569785738035 -23/4 23/4 error as.bigq(23) 23/3 23/25 25895697857380352/2589569785738035 -23/4 23/4 error c(3,23) 1 error - - - - as.bgz((3,23)) 1 3/25 1125899906842624/863189928579345 -3/4 3/4 error as.bgq((3,23)) 1 3/25 1125899906842624/863189928579345 -3/4 3/4 error 25 25/3 error error error error error 2.3 863189928579345/1125899906842624 error - - - - -4 -4/3 error - - - - 4 4/3 error - - - - 0 0 error - - - - as.bigz(34) 34/3 34/25 38280596832649216/2589569785738035 -17/2 17/2 error as.bg(32,7) 32/21 32/175 36028797018963968/18126988500166245 -8/7 8/7 error as.b(31,45) 31/3 NA (38 %% 45) (26 %% 45) (19 %% 45) NA NULL error NA NA error -3L -1 error - - - - as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 23/34 161/32 (8 %% 45) - as.bigz(23) 23/34 161/32 (8 %% 45) NA -23/3 as.bigq(23) 23/34 161/32 23/31 NA -23/3 c(3,23) 3/34 21/32 (3 %% 45) - as.bgz((3,23)) 3/34 21/32 (3 %% 45) NA -1 as.bgq((3,23)) 3/34 21/32 3/31 NA -1 25 25/34 175/32 (40 %% 45) error error error 2.3 2589569785738035/38280596832649216 18126988500166245/36028797018963968 (32 %% 45) - -4 -2/17 -7/8 (26 %% 45) - 4 2/17 7/8 (19 %% 45) - 0 0 0 (0 %% 45) - as.bigz(34) 1 119/16 (4 %% 45) NA -34/3 as.bg(32,7) 16/119 1 32/217 NA -32/21 as.b(31,45) (34 %% 45) 217/32 (1 %% 45) NA NA NULL NA NA NA NA -3L -3/34 -21/32 (42 %% 45) - ------------------------------------------ %% -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 256 in current 186 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 23 - 0 error - 2 error error - - - - as.bigz(23) 0 0 error 2 2 error 23 1 3 3 NA as.bigq(23) error 0 error error 2 error error error error error error c(3,23) - 3 error - 0 error error - - - - as.bgz((3,23)) 3 3 error 0 0 error 3 1 3 3 NA as.bgq((3,23)) error 3 error error 0 error error error error error error 25 error 2 error error 1 error error error error error error 2.3 - 2 error - 2 error error - - - - -4 - 19 error - 2 error error - - - - 4 - 4 error - 1 error error - - 0 - 0 - 0 error - 0 error error - - - - as.bigz(34) 11 11 error 1 1 error 9 0 2 2 NA as.bg(32,7) error 9 error error 2 error error error error error error as.b(31,45) (8 %% 23) (8 %% 23) error (1 %% 3) (1 %% 3) error (6 %% 25) (1 %% 2) (3 %% -4) (3 %% 4) NA NULL error error error NA NA error NA error error NaN -3L - 20 error - 0 error error - - 1 - as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 23 error (23 %% 31) - as.bigz(23) 23 3 (23 %% 31) NA 2 as.bigq(23) 23 error (23 %% 31) error error error c(3,23) 3 error (3 %% 31) - as.bgz((3,23)) 3 3 (3 %% 31) NA 0 as.bgq((3,23)) 3 error (3 %% 31) error error error 25 25 error (25 %% 31) error error error 2.3 2 error (2 %% 31) - -4 30 error (27 %% 31) - 4 4 error (4 %% 31) -2 0 0 error (0 %% 31) - as.bigz(34) 0 2 (3 %% 31) NA 1 as.bg(32,7) 32 error (1 %% 31) error error error as.b(31,45) (31 %% 34) (3 %% 4) (0 %% 31) NA (1 %% -3) NULL error NA NA error NA -3L 31 error (28 %% 31) 0 ------------------------------------------ ^ -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 256 in current 143 in target 23 as.bigz(23) 23 - 20880467999847912034355032910567 as.bigz(23) 20880467999847912034355032910567 20880467999847912034355032910567 as.bigq(23) 20880467999847912034355032910567 20880467999847912034355032910567 c(3,23) - 94143178827 as.bgz((3,23)) 94143178827 94143178827 as.bgq((3,23)) 94143178827 94143178827 25 error 142108547152020037174224853515625 2.3 - 8388608 -4 - -70368744177664 4 - 70368744177664 0 - 0 as.bigz(34) 167500108222301408246337399112597504 167500108222301408246337399112597504 as.bg(32,7) 41538374868278621028243970633760768/27368747340080916343 41538374868278621028243970633760768/27368747340080916343 as.b(31,45) (16 %% 45) (16 %% 45) NULL NA NA -3L - -94143178827 as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 23 20880467999847912034355032910567 - 12167 12167 as.bigz(23) 20880467999847912034355032910567 12167 12167 12167 as.bigq(23) 20880467999847912034355032910567 12167 12167 12167 c(3,23) 94143178827 - 27 27 as.bgz((3,23)) 94143178827 27 27 27 as.bgq((3,23)) 94143178827 27 27 27 25 142108547152020037174224853515625 error 15625 15625 2.3 8388608 - 8 8 -4 -70368744177664 - -64 -64 4 70368744177664 - 64 64 0 0 - 0 0 as.bigz(34) 167500108222301408246337399112597504 39304 39304 39304 as.bg(32,7) 41538374868278621028243970633760768/27368747340080916343 32768/343 32768/343 32768/343 as.b(31,45) (16 %% 45) (1 %% 45) (1 %% 45) (1 %% 45) NULL NA NA NA NA -3L -94143178827 - -27 -27 25 2.3 -4 4 0 23 error - - - - as.bigz(23) 11045767571919545466173812409689943 error 1/279841 279841 1 as.bigq(23) 11045767571919545466173812409689943 error 1/279841 279841 1 c(3,23) error - - - - as.bgz((3,23)) 847288609443 error 1/81 81 1 as.bgq((3,23)) 847288609443 error 1/81 81 1 25 error error error error error 2.3 error - - - - -4 error - - - - 4 error - - - - 0 error - - - - as.bigz(34) 193630125104980427932766033374162714624 error 1/1336336 1336336 1 as.bg(32,7) 42535295865117307932921825928971026432/1341068619663964900807 error 2401/1048576 1048576/2401 1 as.b(31,45) (31 %% 45) error (16 %% 45) (31 %% 45) (1 %% 45) NULL error NA error 1 -3L error - - - - as.bigz(34) as.bigq(32,7) 23 19895113660064588580108197261066338165074766609 error as.bigz(23) 19895113660064588580108197261066338165074766609 error as.bigq(23) 19895113660064588580108197261066338165074766609 error c(3,23) 16677181699666569 error as.bgz((3,23)) 16677181699666569 error as.bgq((3,23)) 16677181699666569 error 25 338813178901720135627329000271856784820556640625 error 2.3 17179869184 error -4 295147905179352825856 error 4 295147905179352825856 error 0 0 error as.bigz(34) 11756638905368616011414050501310355554617941909569536 error as.bg(32,7) 1496577676626844588240573268701473812127674924007424/54116956037952111668959660849 error as.b(31,45) (31 %% 45) error NULL error NA NA error -3L 16677181699666569 error as.bigz(31,45) NULL NA -3L 23 (32 %% 45) - as.bigz(23) (32 %% 45) NA 1/12167 as.bigq(23) 1635170022196481349560959748587682926364327 NA 1/12167 c(3,23) (27 %% 45) - as.bgz((3,23)) (27 %% 45) NA 1/27 as.bgq((3,23)) 617673396283947 NA 1/27 25 (25 %% 45) error error error 2.3 (38 %% 45) - -4 (41 %% 45) - 4 (4 %% 45) - 0 (0 %% 45) - as.bigz(34) (34 %% 45) NA 1/39304 as.bg(32,7) 45671926166590716193865151022383844364247891968/157775382034845806615042743 NA 343/32768 as.b(31,45) (31 %% 45) NA (1 %% 45) NULL NA NA -3L (18 %% 45) - ------------------------------------------ inv.bigz -> all.equal(target = res, current = F()): Mean relative difference: 0.6402439 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 23 NA NA NA 2 2 2 12 1 3 3 NA as.bigz(23) NA NA NA 2 2 2 12 1 3 3 NA as.bigq(23) NA NA NA 2 2 2 12 1 3 3 NA c(3,23) 8 8 8 NA NA NA 17 1 3 3 NA as.bgz((3,23)) 8 8 8 NA NA NA 17 1 3 3 NA as.bgq((3,23)) 8 8 8 NA NA NA 17 1 3 3 NA 25 12 12 12 1 1 1 NA 1 1 1 NA 2.3 12 12 12 2 2 2 13 NA NA NA NA -4 17 17 17 2 2 2 6 NA NA NA NA 4 6 6 6 1 1 1 19 NA NA NA NA 0 NA NA NA NA NA NA NA NA NA NA NA as.bigz(34) 21 21 21 1 1 1 14 NA NA NA NA as.bg(32,7) 18 18 18 2 2 2 18 NA NA NA NA as.b(31,45) (3 %% 45) (3 %% 45) (3 %% 45) (1 %% 45) (1 %% 45) (1 %% 45) (21 %% 45) (1 %% 45) (3 %% 45) (3 %% 45) NA NULL NA NA NA NA NA NA NA NA NA NA NA NA -3L 15 15 15 NA NA NA 8 1 1 1 NA as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 3 7 (27 %% 45) NA 2 as.bigz(23) 3 7 (27 %% 45) NA 2 as.bigq(23) 3 7 (27 %% 45) NA 2 c(3,23) 23 11 (21 %% 45) NA NA as.bgz((3,23)) 23 11 (21 %% 45) NA NA as.bgq((3,23)) 23 11 (21 %% 45) NA NA 25 15 9 (5 %% 45) NA 1 2.3 NA NA (16 %% 45) NA 2 -4 NA NA (23 %% 45) NA 2 4 NA NA (8 %% 45) NA 1 0 NA NA NA NA NA as.bigz(34) NA NA (21 %% 45) NA 1 as.bg(32,7) NA NA (1 %% 45) NA 2 as.b(31,45) (11 %% 45) (31 %% 45) NA NA (1 %% 45) NULL NA NA NA NA NA NA -3L 11 21 (10 %% 45) NA NA ------------------------------------------ gcd.bigz -> num.fn.: gcd -> all.equal(target = res, current = F()): Mean relative difference: 0.875 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 23 23 23 23 1 1 1 1 1 1 1 as.bigz(23) 23 23 23 1 1 1 1 1 1 1 as.bigq(23) 23 23 23 1 1 1 1 1 1 1 c(3,23) 1 1 1 3 3 3 1 1 1 1 as.bgz((3,23)) 1 1 1 3 3 3 1 1 1 1 as.bgq((3,23)) 1 1 1 3 3 3 1 1 1 1 25 1 1 1 1 1 1 25 1 1 1 2.3 1 1 1 1 1 1 1 2 2 2 -4 1 1 1 1 1 1 1 2 4 4 4 1 1 1 1 1 1 1 2 4 4 0 23 23 23 3 3 3 25 2 4 4 as.bigz(34) 1 1 1 1 1 1 1 2 2 2 as.bg(32,7) 1 1 1 1 1 1 1 2 4 4 as.b(31,45) (1 %% 45) (1 %% 45) (1 %% 45) (1 %% 45) (1 %% 45) (1 %% 45) (1 %% 45) (1 %% 45) (1 %% 45) (1 %% 45) NULL NA NA NA NA NA NA NA NA NA NA NA -3L 1 1 1 3 3 3 1 1 1 1 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 23 1 1 (1 %% 45) NA 1 as.bigz(23) 23 1 1 (1 %% 45) NA 1 as.bigq(23) 23 1 1 (1 %% 45) NA 1 c(3,23) 3 1 1 (1 %% 45) NA 3 as.bgz((3,23)) 3 1 1 (1 %% 45) NA 3 as.bgq((3,23)) 3 1 1 (1 %% 45) NA 3 25 25 1 1 (1 %% 45) NA 1 2.3 2 2 2 (1 %% 45) NA 1 -4 4 2 4 (1 %% 45) NA 1 4 4 2 4 (1 %% 45) NA 1 0 0 34 32 (31 %% 45) NA 3 as.bigz(34) 34 34 2 (1 %% 45) NA 1 as.bg(32,7) 32 2 32 (1 %% 45) NA 1 as.b(31,45) (31 %% 45) (1 %% 45) (1 %% 45) (31 %% 45) NA (1 %% 45) NULL NA NA NA NA NA NA NA -3L 3 1 1 (1 %% 45) NA 3 ------------------------------------------ gcdex -> all.equal(target = res, current = F()): Mean relative difference: 0.875 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) 23 23 23 23 - 1 1 1 1 23 1 1 as.bigz(23) 23 23 23 1 1 1 1 23 1 1 as.bigq(23) 23 23 23 1 1 1 1 23 1 1 c(3,23) - 3 3 3 - - - - as.bgz((3,23)) 3 3 3 as.bgq((3,23)) 3 3 3 25 1 1 1 25 1 1 1 25 1 1 2.3 1 1 1 - 1 2 2 2 2 2 2 -4 1 1 1 - 1 2 4 4 4 2 4 4 1 1 1 - 1 2 4 4 4 2 4 0 23 23 23 - 25 2 4 4 0 34 32 as.bigz(34) 1 1 1 1 2 2 2 34 34 2 as.bg(32,7) 1 1 1 1 2 4 4 32 2 32 as.b(31,45) 1 1 1 1 1 1 1 31 1 1 NULL NA 23 23 23 25 2 4 4 0 34 32 -3L 1 1 1 - 1 1 1 1 3 1 1 as.bigz(31,45) NULL NA -3L 23 1 23 1 as.bigz(23) 1 23 1 as.bigq(23) 1 23 1 c(3,23) - as.bgz((3,23)) as.bgq((3,23)) 25 1 25 1 2.3 1 2 1 -4 1 4 1 4 1 4 1 0 31 0 3 as.bigz(34) 1 34 1 as.bg(32,7) 1 32 1 as.b(31,45) 31 31 1 NULL NA 31 0 3 -3L 1 3 3 ------------------------------------------ lcm.bigz -> num.fn.: lcm -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 256 in current 60 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 23 23 23 23 69 69 69 575 46 92 92 as.bigz(23) 23 23 23 69 69 69 575 46 92 92 as.bigq(23) 23 23 23 69 69 69 575 46 92 92 c(3,23) 69 69 69 3 3 3 75 6 12 12 as.bgz((3,23)) 69 69 69 3 3 3 75 6 12 12 as.bgq((3,23)) 69 69 69 3 3 3 75 6 12 12 25 575 575 575 75 75 75 25 50 100 100 2.3 46 46 46 6 6 6 50 2 4 4 -4 92 92 92 12 12 12 100 4 4 4 4 92 92 92 12 12 12 100 4 4 4 0 0 0 0 0 0 0 0 0 0 0 as.bigz(34) 782 782 782 102 102 102 850 34 68 68 as.bg(32,7) 736 736 736 96 96 96 800 32 32 32 as.b(31,45) (38 %% 45) (38 %% 45) (38 %% 45) (3 %% 45) (3 %% 45) (3 %% 45) (10 %% 45) (17 %% 45) (34 %% 45) (34 %% 45) NULL NA NA NA NA NA NA NA NA NA NA NA -3L 69 69 69 3 3 3 75 6 12 12 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 0 782 736 (38 %% 45) NA 69 as.bigz(23) 0 782 736 (38 %% 45) NA 69 as.bigq(23) 0 782 736 (38 %% 45) NA 69 c(3,23) 0 102 96 (3 %% 45) NA 3 as.bgz((3,23)) 0 102 96 (3 %% 45) NA 3 as.bgq((3,23)) 0 102 96 (3 %% 45) NA 3 25 0 850 800 (10 %% 45) NA 75 2.3 0 34 32 (17 %% 45) NA 6 -4 0 68 32 (34 %% 45) NA 12 4 0 68 32 (34 %% 45) NA 12 0 0 0 0 (0 %% 45) NA 0 as.bigz(34) 0 34 544 (19 %% 45) NA 102 as.bg(32,7) 0 544 32 (2 %% 45) NA 96 as.b(31,45) (0 %% 45) (19 %% 45) (2 %% 45) (31 %% 45) NA (3 %% 45) NULL NA NA NA NA NA NA NA -3L 0 102 96 (3 %% 45) NA 3 ------------------------------------------ as.bigq -> all.equal(target = res, current = F()): TRUE 23 as.bigz(23) as.bigq(23) 23 1 1 1 as.bigz(23) 1 1 1 as.bigq(23) 1 1 1 c(3,23) 3/23 3/23 3/23 as.bgz((3,23)) 3/23 3/23 3/23 as.bgq((3,23)) 3/23 3/23 3/23 25 25/23 25/23 25/23 2.3 2589569785738035/25895697857380352 2589569785738035/25895697857380352 2589569785738035/25895697857380352 -4 -4/23 -4/23 -4/23 4 4/23 4/23 4/23 0 0 0 0 as.bigz(34) 34/23 34/23 34/23 as.bg(32,7) 32/161 32/161 32/161 as.b(31,45) 31/23 31/23 31/23 NULL NA NA NA NA -3L -3/23 -3/23 -3/23 c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 23 23/3 23/3 23/3 as.bigz(23) 23/3 23/3 23/3 as.bigq(23) 23/3 23/3 23/3 c(3,23) 1 1 1 as.bgz((3,23)) 1 1 1 as.bgq((3,23)) 1 1 1 25 25/3 25/3 25/3 2.3 863189928579345/1125899906842624 863189928579345/1125899906842624 863189928579345/1125899906842624 -4 -4/3 -4/3 -4/3 4 4/3 4/3 4/3 0 0 0 0 as.bigz(34) 34/3 34/3 34/3 as.bg(32,7) 32/21 32/21 32/21 as.b(31,45) 31/3 31/3 31/3 NULL NA NA NA NA -3L -1 -1 -1 25 2.3 -4 23 23/25 25895697857380352/2589569785738035 -23/4 as.bigz(23) 23/25 25895697857380352/2589569785738035 -23/4 as.bigq(23) 23/25 25895697857380352/2589569785738035 -23/4 c(3,23) 3/25 1125899906842624/863189928579345 -3/4 as.bgz((3,23)) 3/25 1125899906842624/863189928579345 -3/4 as.bgq((3,23)) 3/25 1125899906842624/863189928579345 -3/4 25 1 5629499534213120/517913957147607 -25/4 2.3 517913957147607/5629499534213120 1 -2589569785738035/4503599627370496 -4 -4/25 -4503599627370496/2589569785738035 1 4 4/25 4503599627370496/2589569785738035 -1 0 0 0 0 as.bigz(34) 34/25 38280596832649216/2589569785738035 -17/2 as.bg(32,7) 32/175 36028797018963968/18126988500166245 -8/7 as.b(31,45) 31/25 34902897112121344/2589569785738035 -31/4 NULL NA NA NA NA -3L -3/25 -1125899906842624/863189928579345 3/4 4 0 as.bigz(34) as.bigq(32,7) 23 23/4 error 23/34 161/32 as.bigz(23) 23/4 error 23/34 161/32 as.bigq(23) 23/4 error 23/34 161/32 c(3,23) 3/4 error 3/34 21/32 as.bgz((3,23)) 3/4 error 3/34 21/32 as.bgq((3,23)) 3/4 error 3/34 21/32 25 25/4 error 25/34 175/32 2.3 2589569785738035/4503599627370496 error 2589569785738035/38280596832649216 18126988500166245/36028797018963968 -4 -1 error -2/17 -7/8 4 1 error 2/17 7/8 0 0 error 0 0 as.bigz(34) 17/2 error 1 119/16 as.bg(32,7) 8/7 error 16/119 1 as.b(31,45) 31/4 error 31/34 217/32 NULL NA NA NA NA NA -3L -3/4 error -3/34 -21/32 as.bigz(31,45) NULL NA -3L 23 23/31 NA -23/3 as.bigz(23) 23/31 NA -23/3 as.bigq(23) 23/31 NA -23/3 c(3,23) 3/31 NA -1 as.bgz((3,23)) 3/31 NA -1 as.bgq((3,23)) 3/31 NA -1 25 25/31 NA -25/3 2.3 2589569785738035/34902897112121344 NA -863189928579345/1125899906842624 -4 -4/31 NA 4/3 4 4/31 NA -4/3 0 0 NA 0 as.bigz(34) 34/31 NA -34/3 as.bg(32,7) 32/217 NA -32/21 as.b(31,45) 1 NA -31/3 NULL NA NA NA NA -3L -3/31 NA 1 ------------------------------------------ chooseZ -> num.fn.: choose -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 256 in current 31 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) 23 1 1 1 1771 1771 1771 0 253 0 8855 1 0 as.bigz(23) 1 1 1 1771 1771 1771 0 253 0 8855 1 0 as.bigq(23) 1 1 1 1771 1771 1771 0 253 0 8855 1 0 c(3,23) 0 0 0 1 1 1 0 3 0 0 1 0 as.bgz((3,23)) 0 0 0 1 1 1 0 3 0 0 1 0 as.bgq((3,23)) 0 0 0 1 1 1 0 3 0 0 1 0 25 300 300 300 2300 2300 2300 1 300 0 12650 1 0 2.3 0 0 0 0 0 0 0 1 0 0 1 0 -4 -2600 -2600 -2600 -20 -20 -20 -3276 10 0 35 1 7770 4 0 0 0 4 4 4 0 6 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 as.bigz(34) 286097760 286097760 286097760 5984 5984 5984 52451256 561 0 46376 1 1 as.bg(32,7) 28048800 28048800 28048800 4960 4960 4960 3365856 496 0 35960 1 0 as.b(31,45) 7888725 7888725 7888725 4495 4495 4495 736281 465 0 31465 1 0 NULL NA 0 0 0 0 0 0 0 0 0 0 1 0 -3L -300 -300 -300 -10 -10 -10 -351 6 0 15 1 630 as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 8855 0 0 0 as.bigz(23) 8855 0 0 0 as.bigq(23) 8855 0 0 0 c(3,23) 0 0 0 0 as.bgz((3,23)) 0 0 0 0 as.bgq((3,23)) 0 0 0 0 25 12650 0 0 0 2.3 0 0 0 0 -4 35 -5984 0 0 4 1 0 0 0 0 0 0 0 0 as.bigz(34) 46376 5984 0 0 as.bg(32,7) 35960 32 0 0 as.b(31,45) 31465 1 0 0 NULL NA 0 0 0 0 -3L 15 -528 0 0 ------------------------------------------ max -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 256 in current 130 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 23 - error error - error error 25 - - - as.bigz(23) 23 23 23 23 23 23 25 23 23 23 as.bigq(23) 23 23 23 23 23 23 25 23 23 23 c(3,23) - error error - error error 25 - - - as.bgz((3,23)) 23 23 23 23 23 23 25 23 23 23 as.bgq((3,23)) 23 23 23 23 23 23 25 23 23 23 25 25 error error 25 error error 25 25 25 4 2.3 - error error - error error 25 - - - -4 - error error - error error 25 - - - 4 - error error - error error 4 - - 4 0 - error error - error error 25 - - - as.bigz(34) 34 34 34 34 34 34 34 34 34 34 as.bg(32,7) 23 23 23 23 23 23 25 32/7 32/7 32/7 as.b(31,45) (31 %% 45) (31 %% 45) 31 (31 %% 45) (31 %% 45) 31 (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) NULL 23 error error 23 error error 25 2.3 -4 4 NA error error error error -3L - error error - error error 25 - - 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 - error error error 23 - as.bigz(23) 23 34 23 31 23 23 as.bigq(23) 23 34 23 31 23 23 c(3,23) - error error error 23 - as.bgz((3,23)) 23 34 23 31 23 23 as.bgq((3,23)) 23 34 23 31 23 23 25 25 error error error 25 25 2.3 - error error error 2.3 - -4 - error error error -4 - 4 - error error error 4 4 0 - error error error 0 - as.bigz(34) 34 34 34 34 34 34 as.bg(32,7) 32/7 34 32/7 31 32/7 32/7 as.b(31,45) (31 %% 45) (34 %% 45) 31 (31 %% 45) (31 %% 45) (31 %% 45) NULL 0 error error error -Inf -3 NA error error error -3L - error error error -3 -3 ------------------------------------------ min -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 256 in current 130 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 23 - error error - error error 23 - as.bigz(23) 23 23 23 3 3 3 23 2 as.bigq(23) 23 23 23 3 3 3 23 2589569785738035/1125899906842624 c(3,23) - error error - error error 25 - as.bgz((3,23)) 3 3 3 3 3 3 3 2 as.bgq((3,23)) 3 3 3 3 3 3 3 2589569785738035/1125899906842624 25 23 error error 25 error error 25 2.3 2.3 - error error - error error 2.3 - -4 - error error - error error -4 - 4 - error error - error error 25 - 0 - error error - error error 0 - as.bigz(34) 23 23 23 3 3 3 25 2 as.bg(32,7) 32/7 32/7 32/7 3 3 3 32/7 2589569785738035/1125899906842624 as.b(31,45) (23 %% 45) (23 %% 45) 23 (3 %% 45) (3 %% 45) 3 (25 %% 45) (2 %% 45) NULL 23 error error 3 error error 25 2.3 NA error error error error -3L - error error - error error -3 - -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 - - - error error error 23 - as.bigz(23) -4 4 0 23 32/7 23 23 -3 as.bigq(23) -4 4 0 23 32/7 23 23 -3 c(3,23) - - - error error error 3 - as.bgz((3,23)) -4 3 0 3 3 3 3 -3 as.bgq((3,23)) -4 3 0 3 3 3 3 -3 25 -4 25 0 error error error 25 -3 2.3 - - - error error error 2.3 - -4 - - - error error error -4 - 4 - 4 - error error error 4 -3 0 - - - error error error 0 - as.bigz(34) -4 4 0 34 32/7 31 34 -3 as.bg(32,7) -4 4 0 32/7 32/7 32/7 32/7 -3 as.b(31,45) (-4 %% 45) (4 %% 45) (0 %% 45) (31 %% 45) 32/7 (31 %% 45) (31 %% 45) (-3 %% 45) NULL -4 4 0 error error error Inf -3 NA error error error -3L - -3 - error error error -3 -3 ------------------------------------------ | -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 34 in current 51 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) 23 TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE TRUE TRUE as.bigz(23) TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE as.bigq(23) TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE c(3,23) TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE TRUE TRUE as.bgz((3,23)) TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE as.bgq((3,23)) TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE 25 error TRUE TRUE error TRUE TRUE error error error error error TRUE 2.3 TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE TRUE TRUE -4 TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE TRUE TRUE 4 TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE TRUE TRUE 0 TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE FALSE TRUE as.bigz(34) TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE as.bg(32,7) TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE as.b(31,45) TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE NULL error NA TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE TRUE -3L TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE TRUE TRUE as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 TRUE TRUE TRUE TRUE as.bigz(23) TRUE TRUE TRUE TRUE as.bigq(23) TRUE TRUE TRUE TRUE c(3,23) TRUE TRUE TRUE TRUE as.bgz((3,23)) TRUE TRUE TRUE TRUE as.bgq((3,23)) TRUE TRUE TRUE TRUE 25 TRUE TRUE error error error 2.3 TRUE TRUE TRUE TRUE -4 TRUE TRUE TRUE TRUE 4 TRUE TRUE TRUE TRUE 0 TRUE TRUE TRUE as.bigz(34) TRUE TRUE TRUE TRUE as.bg(32,7) TRUE TRUE TRUE TRUE as.b(31,45) TRUE TRUE TRUE TRUE NULL NA TRUE TRUE TRUE -3L TRUE TRUE TRUE TRUE ------------------------------------------ & -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 58 in current 73 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) 23 TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE FALSE TRUE as.bigz(23) TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE as.bigq(23) TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE c(3,23) TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE FALSE TRUE as.bgz((3,23)) TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE as.bgq((3,23)) TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE 25 error TRUE TRUE error TRUE TRUE error error error error error TRUE 2.3 TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE FALSE TRUE -4 TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE FALSE TRUE 4 TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE FALSE TRUE 0 FALSE FALSE FALSE FALSE FALSE FALSE error FALSE FALSE FALSE FALSE FALSE as.bigz(34) TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE as.bg(32,7) TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE as.b(31,45) TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE NULL error NA error FALSE -3L TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE FALSE TRUE as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 TRUE TRUE TRUE as.bigz(23) TRUE TRUE TRUE as.bigq(23) TRUE TRUE TRUE c(3,23) TRUE TRUE TRUE as.bgz((3,23)) TRUE TRUE TRUE as.bgq((3,23)) TRUE TRUE TRUE 25 TRUE TRUE error error error 2.3 TRUE TRUE TRUE -4 TRUE TRUE TRUE 4 TRUE TRUE TRUE 0 FALSE FALSE FALSE FALSE as.bigz(34) TRUE TRUE TRUE as.bg(32,7) TRUE TRUE TRUE as.b(31,45) TRUE TRUE TRUE NULL NA -3L TRUE TRUE TRUE ------------------------------------------ xor -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 60 in current 75 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) 23 FALSE FALSE FALSE FALSE FALSE FALSE error FALSE FALSE FALSE TRUE FALSE as.bigz(23) FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE as.bigq(23) FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE c(3,23) FALSE FALSE FALSE FALSE FALSE FALSE error FALSE FALSE FALSE TRUE FALSE as.bgz((3,23)) FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE as.bgq((3,23)) FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE 25 error FALSE FALSE error FALSE FALSE error error error error error FALSE 2.3 FALSE FALSE FALSE FALSE FALSE FALSE error FALSE FALSE FALSE TRUE FALSE -4 FALSE FALSE FALSE FALSE FALSE FALSE error FALSE FALSE FALSE TRUE FALSE 4 FALSE FALSE FALSE FALSE FALSE FALSE error FALSE FALSE FALSE TRUE FALSE 0 TRUE TRUE TRUE TRUE TRUE TRUE error TRUE TRUE TRUE FALSE TRUE as.bigz(34) FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE as.bg(32,7) FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE as.b(31,45) FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE NULL error NA error -3L FALSE FALSE FALSE FALSE FALSE FALSE error FALSE FALSE FALSE TRUE FALSE as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 FALSE FALSE FALSE as.bigz(23) FALSE FALSE FALSE as.bigq(23) FALSE FALSE FALSE c(3,23) FALSE FALSE FALSE as.bgz((3,23)) FALSE FALSE FALSE as.bgq((3,23)) FALSE FALSE FALSE 25 FALSE FALSE error error error 2.3 FALSE FALSE FALSE -4 FALSE FALSE FALSE 4 FALSE FALSE FALSE 0 TRUE TRUE TRUE as.bigz(34) FALSE FALSE FALSE as.bg(32,7) FALSE FALSE FALSE as.b(31,45) FALSE FALSE FALSE NULL NA -3L FALSE FALSE FALSE ------------------------------------------ c -> all.equal(target = res, current = F()): 'is.NA' value mismatch: 256 in current 63 in target 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 23 - 23 23 - 23 23 23 - - - as.bigz(23) 23 23 23 23 23 23 23 23 23 23 as.bigq(23) 23 23 23 23 23 23 23 23 23 23 c(3,23) - 3 3 - 3 3 3 - - - as.bgz((3,23)) 3 3 3 3 3 3 3 3 3 3 as.bgq((3,23)) 3 3 3 3 3 3 3 3 3 3 25 25 25 25 25 25 25 25 25 25 25 2.3 - 2.3 2.3 - 2.3 2.3 2.3 - - - -4 - -4 -4 - -4 -4 -4 - - - 4 - 4 4 - 4 4 4 - - 4 0 - 0 0 - 0 0 0 - - - as.bigz(34) 34 34 34 34 34 34 34 34 34 34 as.bg(32,7) 32/7 32/7 32/7 32/7 32/7 32/7 32/7 32/7 32/7 32/7 as.b(31,45) (31 %% 45) (31 %% 45) 31 (31 %% 45) (31 %% 45) 31 (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) NULL 23 01 01 3 02 02 25 2.3 -4 4 NA -3L - -3 -3 - -3 -3 -3 - - -3 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA -3L 23 - 23 23 23 23 23 - as.bigz(23) 23 23 23 23 23 23 23 as.bigq(23) 23 23 23 23 23 23 23 c(3,23) - 3 3 3 3 3 - as.bgz((3,23)) 3 3 3 3 3 3 3 as.bgq((3,23)) 3 3 3 3 3 3 3 25 25 25 25 25 25 25 25 2.3 - 2.3 2.3 2.3 2.3 2.3 - -4 - -4 -4 -4 -4 -4 - 4 - 4 4 4 4 4 4 0 - 0 0 0 0 0 - as.bigz(34) 34 34 34 34 34 34 34 as.bg(32,7) 32/7 32/7 32/7 32/7 32/7 32/7 32/7 as.b(31,45) (31 %% 45) (31 %% 45) 31 (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) NULL 0 01 01 01 -3 NA -3L - -3 -3 -3 -3 -3 -3 ------------------------------------------ cbind -> all.equal(target = res, current = F()): Mean relative difference: 0.01075094 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 23 23 23 23 23 23 23 as.bigz(23) 23 23 23 23 23 23 as.bigq(23) 23 23 23 23 23 23 c(3,23) 3 3 3 3 3 3 as.bgz((3,23)) 3 3 3 3 3 3 as.bgq((3,23)) 3 3 3 3 3 3 25 25 25 25 25 25 25 2.3 2.3 2 2589569785738035/1125899906842624 2.3 2 2589569785738035/1125899906842624 -4 -4 -4 -4 -4 -4 -4 4 4 4 4 4 4 4 0 0 0 0 0 0 0 as.bigz(34) 34 34 34 34 34 34 as.bg(32,7) 32/7 32/7 32/7 32/7 32/7 32/7 as.b(31,45) (31 %% 45) (31 %% 45) 31 (31 %% 45) (31 %% 45) 31 NULL 23 23 23 3 3 3 NA NA NA NA NA -3L -3 -3 -3 -3 -3 -3 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) 23 23 23 23 23 23 23 23 23 as.bigz(23) 23 23 23 23 23 23 23 23 as.bigq(23) 23 23 23 23 23 23 23 23 c(3,23) 3 3 3 3 3 3 3 3 as.bgz((3,23)) 3 3 3 3 3 3 3 3 as.bgq((3,23)) 3 3 3 3 3 3 3 3 25 25 25 25 25 25 25 25 25 2.3 2.3 2.3 2.3 2.3 2.3 2 2589569785738035/1125899906842624 2 -4 -4 -4 -4 -4 -4 -4 -4 -4 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0 0 0 0 as.bigz(34) 34 34 34 34 34 34 34 34 as.bg(32,7) 32/7 32/7 32/7 32/7 32/7 32/7 32/7 32/7 as.b(31,45) (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) 31 (31 %% 45) NULL 25 2.3 -4 4 0 34 32/7 (31 %% 45) NA NA NA NA -3L -3 -3 -3 -3 -3 -3 -3 -3 NULL NA -3L 23 23 23 23 as.bigz(23) 23 23 23 as.bigq(23) 23 23 23 c(3,23) 3 3 3 as.bgz((3,23)) 3 3 3 as.bgq((3,23)) 3 3 3 25 25 25 25 2.3 2.3 2.3 2.3 -4 -4 -4 -4 4 4 4 4 0 0 0 0 as.bigz(34) 34 34 34 as.bg(32,7) 32/7 32/7 32/7 as.b(31,45) (31 %% 45) (31 %% 45) (31 %% 45) NULL -3 NA -3L -3 -3 -3 ------------------------------------------ rbind -> all.equal(target = res, current = F()): Mean relative difference: 0.01075094 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 23 23 23 23 23 23 23 as.bigz(23) 23 23 23 23 23 23 as.bigq(23) 23 23 23 23 23 23 c(3,23) 3 3 3 3 3 3 as.bgz((3,23)) 3 3 3 3 3 3 as.bgq((3,23)) 3 3 3 3 3 3 25 25 25 25 25 25 25 2.3 2.3 2 2589569785738035/1125899906842624 2.3 2 2589569785738035/1125899906842624 -4 -4 -4 -4 -4 -4 -4 4 4 4 4 4 4 4 0 0 0 0 0 0 0 as.bigz(34) 34 34 34 34 34 34 as.bg(32,7) 32/7 32/7 32/7 32/7 32/7 32/7 as.b(31,45) (31 %% 45) (31 %% 45) 31 (31 %% 45) (31 %% 45) 31 NULL 23 23 23 3 3 3 NA NA NA NA NA -3L -3 -3 -3 -3 -3 -3 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) 23 23 23 23 23 23 23 23 23 as.bigz(23) 23 23 23 23 23 23 23 23 as.bigq(23) 23 23 23 23 23 23 23 23 c(3,23) 3 3 3 3 3 3 3 3 as.bgz((3,23)) 3 3 3 3 3 3 3 3 as.bgq((3,23)) 3 3 3 3 3 3 3 3 25 25 25 25 25 25 25 25 25 2.3 2.3 2.3 2.3 2.3 2.3 2 2589569785738035/1125899906842624 2 -4 -4 -4 -4 -4 -4 -4 -4 -4 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0 0 0 0 as.bigz(34) 34 34 34 34 34 34 34 34 as.bg(32,7) 32/7 32/7 32/7 32/7 32/7 32/7 32/7 32/7 as.b(31,45) (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) 31 (31 %% 45) NULL 25 2.3 -4 4 0 34 32/7 (31 %% 45) NA NA NA NA -3L -3 -3 -3 -3 -3 -3 -3 -3 NULL NA -3L 23 23 23 23 as.bigz(23) 23 23 23 as.bigq(23) 23 23 23 c(3,23) 3 3 3 as.bgz((3,23)) 3 3 3 as.bgq((3,23)) 3 3 3 25 25 25 25 2.3 2.3 2.3 2.3 -4 -4 -4 -4 4 4 4 4 0 0 0 0 as.bigz(34) 34 34 34 as.bg(32,7) 32/7 32/7 32/7 as.b(31,45) (31 %% 45) (31 %% 45) (31 %% 45) NULL -3 NA -3L -3 -3 -3 There were 3988 warnings (use warnings() to see them) > > summary(warnings()) # ideally *not* platform dependent Summary of (a total of 3988) warning messages: 3563x : In sortie(e) : NAs introduced by coercion 35x : In FUN(x[[i]], x[[j]]) : returning NA for (modulus) 0 in RHS 5x : In `/.bigz`(x[[i]], x[[j]]) : pow(x, -|n|) returning NA as x has no inverse wrt modulus 9x : In `%%.bigz`(x[[i]], x[[j]]) : biginteger division by zero: returning NA 284x : In FUN(x[[i]], x[[j]]) : inv(x,m) returning NA as x has no inverse modulo m 52x : In FUN(x[[i]], x[[j]]) : inv(0) returning NA 17x : In FUN(x[[i]], x[[j]]) : 'k' (2.30) must be integer, rounded to 2 17x : In FUN(x[[i]], x[[j]]) : 'k' (4.57) must be integer, rounded to 5 3x : In FUN(x[[i]], x[[j]]) : no non-missing arguments to max; returning -Inf 3x : In FUN(x[[i]], x[[j]]) : no non-missing arguments to min; returning Inf > > ##============================================================================== > > for(fid in unaryfunctionid) + { + cat ("------------------------------------------\n", fid, "\n\n", sep="") + FUN <- get(fid, envir = gmp.NS, mode="function") + print(as.data.frame(test(FUN, x, unary=TRUE))) + } ------------------------------------------ log 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA 1 - 3.135494 error - 1.098612 error error - - - - 3.526361 error 3.433987 error -3L 1 - ------------------------------------------ log2 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA 1 - 4.523562 error - 1.584963 error error - - - - 5.087463 error 4.954196 error -3L 1 - ------------------------------------------ log10 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA 1 - 1.361728 error - 0.4771213 error error - - - - 1.531479 error 1.491362 error -3L 1 - ------------------------------------------ c 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA -3L 1 - 23 23 - 3 3 25 - - 4 - 34 32/7 (31 %% 45) -3 ------------------------------------------ isprime 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA -3L 1 2 2 2 2 2 2 0 2 0 0 0 0 0 2 0 2 ------------------------------------------ nextprime 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA -3L 1 29 29 29 5 5 5 29 3 2 5 2 37 37 37 2 2 ------------------------------------------ factorialZ 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 1 25852016738884976640000 25852016738884976640000 25852016738884976640000 6 6 6 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA 1 15511210043330985984000000 2 0 24 1 295232799039604140847618609643520000000 24 8222838654177922817725562880000000 0 -3L 1 0 ------------------------------------------ sizeinbase 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA -3L 1 2 2 2 1 1 1 2 1 1 1 1 2 2 2 1 1 ------------------------------------------ fibnum 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL 1 28657 28657 28657 2 2 2 75025 1 error 3 0 5702887 3 1346269 NA -3L 1 error error ------------------------------------------ fibnum2 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) 1 17711 17711 17711 1 1 1 46368 1 error 2 1 3524578 2 832040 NULL NA -3L 1 error error error ------------------------------------------ lucnum 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) 1 64079 64079 64079 4 4 4 167761 3 error 7 2 12752043 7 3010349 NULL NA -3L 1 error error ------------------------------------------ lucnum2 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) 1 39603 39603 39603 3 3 3 103682 1 error 4 -1 7881196 4 1860498 NULL NA -3L 1 error error error ------------------------------------------ factorize 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL 1 23 23 23 3 3 3 5 2 -1 2 error 2 2 31 NA -3L 1 error -1 ------------------------------------------ abs 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) as.bigz(31,45) NULL NA 1 - 23 23 - 3 3 error - - 4 - 34 32/7 (31 %% 45) error -3L 1 3 ------------------------------------------ ! 23 as.bigz(23) as.bigq(23) c(3,23) as.bigz(c(3,23)) as.bigq(c(3,23)) 25 2.3 -4 4 0 as.bigz(34) as.bigq(32,7) 1 FALSE FALSE FALSE FALSE FALSE FALSE error FALSE FALSE FALSE TRUE FALSE FALSE as.bigz(31,45) NULL NA -3L 1 FALSE error FALSE Warning messages: 1: In FUN(x[[j]]) : NaNs produced 2: In FUN(x[[j]]) : NaNs produced 3: In FUN(x[[j]]) : NaNs produced 4: In FUN(x[[j]]) : NaNs produced 5: In FUN(x[[j]]) : NaNs produced 6: In FUN(x[[j]]) : NaNs produced > > ##============================================================================== > > ###----------- matrix ----------------------------- > x <- matrix(1:6,3) > stopifnot(identical(as.bigz(x), matrix(as.bigz(as.vector(x)), 3)), + dim(x) == 3:2, + dim(x) == dim(ym <- as.bigz(x, 6:1)), + dim(x) == dim(ymr <- as.bigz(x, 4:6)), + dim(x) == dim(ymc <- as.bigz(x, 4)), + dim(x) == dim(ymq <- as.bigq(x)), + dim(x) == dim(y <- as.bigq(x, 6:1)) + , + apply(ym,1,max) == 1:3, + apply(ym,2,min) == c(1,0)) > > x %*% t(x) [,1] [,2] [,3] [1,] 17 22 27 [2,] 22 29 36 [3,] 27 36 45 > > ym %*% t(ym) Big Integer ('bigz') 3 x 3 matrix: [,1] [,2] [,3] [1,] 2 3 3 [2,] 3 5 6 [3,] 3 6 9 > ym %*% t(ymr) Big Integer ('bigz') 3 x 3 matrix: [,1] [,2] [,3] [1,] 1 2 3 [2,] 2 4 6 [3,] 3 6 9 > ymc %*% t(ymc) [,1] [,2] [,3] [1,] (1 %% 4) (2 %% 4) (3 %% 4) [2,] (2 %% 4) (1 %% 4) (0 %% 4) [3,] (3 %% 4) (0 %% 4) (1 %% 4) > ymq %*% t(ymq) Big Rational ('bigq') 3 x 3 matrix: [,1] [,2] [,3] [1,] 17 22 27 [2,] 22 29 36 [3,] 27 36 45 > y %*% t(y) Big Rational ('bigq') 3 x 3 matrix: [,1] [,2] [,3] [1,] 65/36 17/5 65/8 [2,] 17/5 641/100 153/10 [3,] 65/8 153/10 585/16 > > dd <- dim(D <- diag(1:4)) > stopifnot(dd == dim(Dmq <- as.bigq(D)), + dd == dim(Dz <- as.bigz(D)), + dd == dim(Dm <- as.bigz(D,6:1)), + dd == dim(Dmr <- as.bigz(D,7)), + dd == dim(Dmc <- as.bigz(D,4)), + TRUE) > solve(D) [,1] [,2] [,3] [,4] [1,] 1 0.0 0.0000000 0.00 [2,] 0 0.5 0.0000000 0.00 [3,] 0 0.0 0.3333333 0.00 [4,] 0 0.0 0.0000000 0.25 > solve(Dmq) Big Rational ('bigq') 4 x 4 matrix: [,1] [,2] [,3] [,4] [1,] 1 0 0 0 [2,] 0 1/2 0 0 [3,] 0 0 1/3 0 [4,] 0 0 0 1/4 > solve(Dmr) [,1] [,2] [,3] [,4] [1,] (1 %% 7) (0 %% 7) (0 %% 7) (0 %% 7) [2,] (0 %% 7) (4 %% 7) (0 %% 7) (0 %% 7) [3,] (0 %% 7) (0 %% 7) (5 %% 7) (0 %% 7) [4,] (0 %% 7) (0 %% 7) (0 %% 7) (2 %% 7) > tools::assertError(solve(Dmc))# Error: argument has no inverse > tools::assertError(solve(Dm)) # Error: System is singular > > (D.D <- D %*% t(Dm))# now [>= Jan.2012] works too Big Integer ('bigz') 4 x 4 matrix: [,1] [,2] [,3] [,4] [1,] 1 0 0 0 [2,] 0 0 0 0 [3,] 0 0 3 0 [4,] 0 0 0 4 > vq <- as.bigq(1:4, 4) > r41 <- cbind(as.bigq((1:4)^2, 4)) > stopifnot(identical(D.D, tcrossprod(D,Dm)), + dim(r41) == c(4,1), + identical(r41, Dz %*% vq), ## bigz %*% bigq - used to fail + identical(r41, crossprod(Dz, vq))## ditto + ) > > ## > ## some specific tests > > factorize("33162879029270137") Big Integer ('bigz') object of length 5: [1] 7 29 11867 75679 181903 > > factorize(15959989) Big Integer ('bigz') object of length 2: [1] 3989 4001 > > ## assignation > x = as.bigz(1:8) > x[3:2] = 9:10 > x Big Integer ('bigz') object of length 8: [1] 1 10 9 4 5 6 7 8 > > x = as.bigz(matrix(1:12,3)) > x[3:2,] = 1:8 > x Big Integer ('bigz') 3 x 4 matrix: [,1] [,2] [,3] [,4] [1,] 1 4 7 10 [2,] 2 4 6 8 [3,] 1 3 5 7 > x[,2] = 0 > x Big Integer ('bigz') 3 x 4 matrix: [,1] [,2] [,3] [,4] [1,] 1 0 7 10 [2,] 2 0 6 8 [3,] 1 0 5 7 > > tools::assertError(x[,5]) > > > proc.time() user system elapsed 0.952 0.068 1.027 gmp/tests/basic-ex.R0000644000176200001440000001702214662047300014021 0ustar liggesuserslibrary(gmp) assertError <- tools::assertError Z1 <- as.bigz(1) ; Z1[FALSE] Q1 <- as.bigq(1) ; Q1[FALSE] stopifnot(0 == length(z0 <- as.bigz(0[FALSE])),# failed earlier 0 == length(q0 <- as.bigq(0[FALSE])),# ditto is.bigz(Z1), is.bigz(z0), !is.bigz(1L), !is.bigz(1), !is.bigz(Q1), is.bigq(Q1), is.bigq(q0), !is.bigq(1L), !is.bigq(1/2), !is.bigq(Z1)) Z1[integer()] <- 2 # segfaulted earlier Q1[integer()] <- 2 # ditto assertError(Z1[1] <- list(1)) # segfaulted assertError(Q1[1] <- list(1)) # " assertError(Z1[1] <- NULL ) # " assertError(Q1[1] <- NULL ) # " stopifnot(identical(Z1, as.bigz(1L)), identical(Q1, as.bigq(1L)), identical(1L, as.integer(Z1)), identical(1L, as.integer(Q1)),## failed earlier identical(as.bigz(1[FALSE]), Z1[FALSE]), identical(as.bigz(1[-1]), Z1[-1]), identical(Z1[-1], rep(Z1, 0)) , ##----------- bigq ------------- identical(as.bigq(1[FALSE]), Q1[-1]), identical(Q1[FALSE], Q1[-1]), identical(Q1[-1], rep(Q1, 0)), identical(q0, rep(Q1, 0)) ) stopifnot(length(1[0]) == 0, 0 == length(Z1[0])) Z <- as.bigz(I <- 2^(5*0:5)); mZ <- as.bigz(mI <- matrix(I, 2,3)) Q <- Z / 4 ; mQ <- matrix(Q, 2,3) ii <- c(3:2,0:2,1:0,0:2) i. <- c(2:0,1:0,1); j. <- ii[1:7] i <- i.[i. != 0] j <- j.[j. != 0] I[ii] ; mI[i.,j.] stopifnot(all.equal( Z[ii], I[ii], tol=0), all.equal(4*Q[ii], I[ii], tol=0), identical(mI[i,j], mI[i.,j.]), identical(mZ[i,j], mZ[i.,j.]), identical(mQ[i,j], mQ[i.,j.])) stopifnot(all.equal(asNumeric(mZ[i,j]), mI[i,j], tol=0), all.equal( 4*mQ[i,j], mI[i,j], tol=0)) ## Outside indexing for *matrices* now gives an error: assertError(mI[1,4]); assertError(mZ[1,4]); assertError(mQ[1,4]) assertError(mI[3,2]); assertError(mZ[3,2]); assertError(mQ[3,2]) ## whereas outside indexing of vectors should give NA: stopifnot(identical(I[8:5], asNumeric(Z[8:5])), identical(I[8:5], asNumeric(Q[8:5] * 4))) ## "basics", including as.matrix(), as.array(), as.list() : i <- 1:9 (x <- as.bigz(i, mod = 3)) mx <- as.matrix(x) ## used to "bomb" badly: ## (terminate called after throwing an instance of 'std::bad_alloc') lx <- as.list(x) stopifnot(5*x == (5*i) %% 3, identical(as.bigz(x), x), # was not the case in gmp 0.5-14 identical(mx, as.array(x)), is(mx, "bigz"), dim(mx) == c(9,1), is.list(lx), identical(unlist(lx), unlist(lapply(x, unclass)))) ## remove modulus "the new way" (NULL did fail): modulus(x) <- NULL Q <- x / 2 mq <- as.matrix(Q) lq <- as.list(Q) stopifnot(identical(x, as.bigz(i %% 3)), identical(mq, as.array(Q)), is(mq, "bigq"), dim(mq) == c(9,1), is.list(lq), identical(unlist(lq), unlist(lapply(Q, unclass)))) ## Check that as.bigq() is exact *and* asNumeric() is its inverse -------------- set.seed(47) summary(x1 <- rt(10000, df = 0.5)) # really long tailed summary(x2 <- rlnorm(10000, 200, 100)) x <- c(x1, x2) qx <- as.bigq(x) nx <- asNumeric(qx) ## asNumeric()'s method for "bigq" is internal .bigq2num() stopifnot(identical(x, nx), identical(nx, gmp:::.bigq2num(qx)) ) ## duplicated(), unique() : ---------------------- q7 <- as.bigq(-5:7, 7) if(FALSE)# not yet {well, *HARD* / impossible(?) without S4 } Q <- q7^2 * as.bigz(77)^10 Q <- q7^2 * as.bigq(77, 2)^10 (uQ <- unique(Q)) (sDup <- sum(duplicated(Q))) # = 5 stopifnot(!duplicated(uQ), sDup + length(uQ) == length(Q)) nQ <- asNumeric(Q) stopifnot( identical(duplicated(Q), duplicated(nQ)) , all.equal(unique(Q), unique(nQ)) , sort(asNumeric(unique(denominator(Q)))) == 4^c(0, 3:5) , TRUE) ## _ TODO _ rep() [times, length.out, each] checkRep <- function(x) { if((n <- length(x)) < 2) stop("'length(x)' must at least be 2, for these checks") ii <- seq_len(n) n1 <- pmin(.9*n, n-1) stopifnot(identical(rep(x, 1), x), identical(rep(x, 3), c(x,x,x)), identical(rep(x, length.out=n1), x[1:n1]) , identical(rep(x, length.out=n+2), x[c(ii,1:2)]) , ## times is *not* considered when 'length.out' is specified: identical(rep(x, 4, length.out=n+2), x[c(ii,1:2)]) , identical(rep(x, 2, length.out=n1), x[1:n1]) , identical(x, rep(x, each=2)[2*ii]) ) } checkRep(Q) checkRep(q7) (Nu <- numerator(uQ)) checkRep(Nu) ##------ Now check that base :: pmin() / pmax() works *in simple cases* for bigz ##------ (because rep(., length.out) works: ## {{MM: compare with ~/R/Pkgs/Rmpfr/tests/arith-ex.R }} (x <- as.bigz(ix <- 2^(3* 0:7))) (x9 <- pmin(x,9)) xp123 <- pmax(x, 123) stopifnot(x9 == c(1,8, rep(9,6)), xp123[1:3] == 123, xp123[-(1:3)] > 123) chk.pmin <- function(x) { message(deparse(sys.call()),": ") x9 <- pmin(x, 9) xp123 <- pmax(x, 123) stopifnot( identical(x, pmin(x, Inf)), identical(x9, pmin(x, 23, Inf, 9)) , identical(dim(x9), dim(x)) , identical(dim(xp123), dim(x)) ) } chk.pmin(x) mx <- matrix(x, nrow=3) # with correct warning chk.pmin(mx) qq <- x / 47 Mq <- matrix(qq, nrow=3) # with correct warning if(FALSE) { ## FIXME: pmin() / pmax() are completely wrong for "bigq" !! chk.pmin(qq) chk.pmin(Mq) } ## [<- : Used to return a *matrix* -- not what we want! chk.subassign <- function(x, i, value) { x0 <- x x[i] <- value stopifnot(identical(dim(x0), dim(x)), # only when not indexing *outside* all(x[i] == value))# not always identical() invisible(x) } x. <- chk.subassign(x , 1, -1) q. <- chk.subassign(qq, 1, -1) q. <- chk.subassign(Mq, 1, -1) x. <- chk.subassign(mx, 1, -1) if(require("Rmpfr") && packageVersion("Rmpfr") >= "0.5-2") { stopifnot( all.equal(pmin(14, x, 9), pmin(14, ix, 9), tol=0) , all.equal(mq <- pmin(14, x/3, 9), ## numbers + bigq pmin(14, ix/3, 9), tol= 1e-15) , is.bigq(mq)) ## ## Now, does pmin etc still work for bigz {it did fail!} chk.pmin(x) if(FALSE) ## FIXME: "Rmpfr's pmin / pmax methods destroy this ==> Fix Rmpfr! chk.pmin(mx) if(FALSE) { ## FIXME: pmin() / pmax() are completely wrong for "bigq" !! chk.pmin(qq) chk.pmin(Mq) } ## ## Ditto for "[<-" : x. <- chk.subassign(x , 1, -1) q. <- chk.subassign(qq, 1, -1) q. <- chk.subassign(Mq, 1, -1) x. <- chk.subassign(mx, 1, -1) ## } 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)) ## all.equal() stopifnot(exprs = { is.character(all.equal(as.bigz(7), rep(7, 3))) }) ##------------------ cbind(), rbind() ------------------------------- a <- as.bigz(123); a[2] <- a[1] ; a[4] <- -4 stopifnot(all.equal(a, c(123, 123, NA, -4))) # bigz <--> numeric (caa <- cbind(a,a)) # ok stopifnot(exprs = { identical(caa, cbind(a,a, deparse.level=1)) # did prepend a column of 1 identical(t(caa), rbind(a,a, deparse.level=0)) # did prepend a row of 0 identical(ca2 <- cbind(a/2, a, deparse.level=0), cbind(a, a/2)[, 2:1]) # wrongly remained bigz, just using numerator... identical(ra2 <- rbind(a/2, a, deparse.level=0), rbind(a, a/2)[2:1, ]) # wrongly remained bigz ... identical(dim(ca2), c(4L, 2L)) identical(dim(ra2), c(2L, 4L)) }) gmp/tests/gmp-test.R0000644000176200001440000001424214444267422014076 0ustar liggesuserslibrary(gmp) ## ##' @title Test a unary (if unary=TRUE) or *binary* function ##' @param FUN a function, such as add.bigq() ... ##' @param x a list of "numbers" ##' @param out string determining output class; if "str", use characters, otherwise double ##' @return ##' @author Antoine Lucas (& Martin Maechler) ##' @examples test(as.bigq, 0) test <- function(FUN, x, xlabs, out = "str", unary = FALSE) { if(missing(xlabs)) xlabs <- if(is.character(names(x))) names(x) else sapply(x, formatN) stopifnot(is.function(FUN), is.list(x), (n <- length(x)) >= 1, length(xlabs) == n) if(out == "str") { sortie <- as.character res <- "" error <- "error" } else { sortie <- as.double res <- 0 error <- NA } nr <- if(unary) 1 else n xlabs <- gsub(" ", "", xlabs) res <- matrix(res, nr, n, dimnames = list(if(!unary) abbreviate(xlabs, 11, named=FALSE), xlabs)) for(i in 1:nr){ classNameI = class(x[[i]]) for(j in 1:n) { classNameJ = class(x[[j]]) e <- if(unary) tryCatch(FUN(x[[j]]), error=identity) else tryCatch(FUN(x[[i]],x[[j]]), error=identity) if(inherits(e, "error")) e <- error else if(length(e) == 0) e <- numeric() ## we don't test standard R floating operations. if( (classNameI[1] == "numeric" || classNameI[1] == "integer") && ( classNameJ[1] == "numeric" || classNameJ[1] == "integer") && class(e)[1] == "numeric") e <- "-" ## ## now, for some functions also compute the corresponding numeric values if(length(e) > 0 && is.double(e[1]) && is.finite(e[1])) e <- format(signif(e[1], digits=14), digits=7) # signif(), not round() res[i,j] <- sortie(e)[1] } } res ## for printing, the user may prefer as.data.frame(.) }## end{test} allfunctionid <- c("as.bigz","+","-","*", "divq.bigz","/","%%","^", "inv.bigz", "gcd.bigz", "gcdex", "lcm.bigz", "as.bigq", "chooseZ", "max","min","|","&","xor","c","cbind","rbind") unaryfunctionid <- c("log","log2","log10","c", "isprime","nextprime", "factorialZ", "sizeinbase","fibnum","fibnum2","lucnum","lucnum2", "factorize","abs","!") numericFunName <- function(gmpName) { if(gmpName != (r <- sub("[ZQ]$","", gmpName)) && r!="as" && existsFunction(r)) # e.g. chooseZ return(r) if(gmpName != (r <- sub("\\.big[zq]$","", gmpName)) && r!="as" && r!="sub" && existsFunction(r)) return(r) ttt <- c("add" = "+", "sub" = "-", "mul" = "*", "pow" = "^", "div" = "/", "divq" = "%/%", "mod" = "%%") if(!is.na(t.r <- ttt[r])) t.r[[1L]] else ## return argument gmpName } options(width = 140, nwarnings = 10000) sapply(allfunctionid, numericFunName) sapply(unaryfunctionid, numericFunName) ex <- expression(23,as.bigz(23),as.bigq(23),c(3,23),as.bigz(c(3,23)),as.bigq(c(3,23)), "25", 2.3, -4, 4L, 0, as.bigz(34), as.bigq(32,7), as.bigz(31,45), NULL,NA, -3L)## TODO: as.bigz(3)^700 x <- lapply(ex, eval) ## Those "numbers" in x for which arithmetic should also work in double precision: ## not modulo-arithmetic, not larger than double.prec useN <- sapply(x, function(u) is.null(u[1]) || is.na(u[1]) || (is.finite(as.numeric(u[1])) && (!inherits(u[1], "bigz") || is.null(modulus(u[1]))))) names(x) <- vapply(ex, format, "") if(FALSE)## shorter & easier {but *not* the original calls from 'ex'} names(x) <- sapply(x, formatN) str(x) x. <- x[useN] nx <- lapply(x., as.numeric) gmp.NS <- asNamespace("gmp")# also get namespace *hidden* functions, i.e. methods: for(fid in allfunctionid) { cat ("------------------------------------------\n", fid," ", sep="") FUN <- get(fid, envir = gmp.NS, mode="function") rc <- test(FUN, x ) res <- test(FUN, x. , out = "numeric") if((nfid <- numericFunName(fid)) != fid || existsFunction(nfid, where=baseenv())) { FUN <- get(nfid, envir = gmp.NS, mode="function") if(nfid != fid) cat("-> num.fn.:", nfid) nres <- test(FUN, nx, out = "numeric") cat("\n-> all.equal(target = res, current = F()): ", all.equal(res, nres), "\n") } else cat("\n\n") print(as.data.frame(rc)); cat("\n") ## ^^^^^^^^^^^^^ (for now, to diminuish difference to last version ) } summary(warnings()) # ideally *not* platform dependent ##============================================================================== for(fid in unaryfunctionid) { cat ("------------------------------------------\n", fid, "\n\n", sep="") FUN <- get(fid, envir = gmp.NS, mode="function") print(as.data.frame(test(FUN, x, unary=TRUE))) } ##============================================================================== ###----------- matrix ----------------------------- x <- matrix(1:6,3) stopifnot(identical(as.bigz(x), matrix(as.bigz(as.vector(x)), 3)), dim(x) == 3:2, dim(x) == dim(ym <- as.bigz(x, 6:1)), dim(x) == dim(ymr <- as.bigz(x, 4:6)), dim(x) == dim(ymc <- as.bigz(x, 4)), dim(x) == dim(ymq <- as.bigq(x)), dim(x) == dim(y <- as.bigq(x, 6:1)) , apply(ym,1,max) == 1:3, apply(ym,2,min) == c(1,0)) x %*% t(x) ym %*% t(ym) ym %*% t(ymr) ymc %*% t(ymc) ymq %*% t(ymq) y %*% t(y) dd <- dim(D <- diag(1:4)) stopifnot(dd == dim(Dmq <- as.bigq(D)), dd == dim(Dz <- as.bigz(D)), dd == dim(Dm <- as.bigz(D,6:1)), dd == dim(Dmr <- as.bigz(D,7)), dd == dim(Dmc <- as.bigz(D,4)), TRUE) solve(D) solve(Dmq) solve(Dmr) tools::assertError(solve(Dmc))# Error: argument has no inverse tools::assertError(solve(Dm)) # Error: System is singular (D.D <- D %*% t(Dm))# now [>= Jan.2012] works too vq <- as.bigq(1:4, 4) r41 <- cbind(as.bigq((1:4)^2, 4)) stopifnot(identical(D.D, tcrossprod(D,Dm)), dim(r41) == c(4,1), identical(r41, Dz %*% vq), ## bigz %*% bigq - used to fail identical(r41, crossprod(Dz, vq))## ditto ) ## ## some specific tests factorize("33162879029270137") factorize(15959989) ## assignation x = as.bigz(1:8) x[3:2] = 9:10 x x = as.bigz(matrix(1:12,3)) x[3:2,] = 1:8 x x[,2] = 0 x tools::assertError(x[,5]) gmp/MD50000644000176200001440000001057714662153602011364 0ustar liggesusers39fd9c0876fc9bc122c97bb8cfc9210c *ChangeLog ebb3e86d6b9fae7939450340f88b351e *Changes 1497247236d5e385b87a972051a6b791 *DESCRIPTION c0c893f9d5ca79bcf51bec6f6ed1a22d *NAMESPACE 031eddddcfbf9c2a9bc74c83342699e5 *R/AllClasses-etc.R 9aa71dab886de7604ee1c33ce14ec35b *R/Stirling-n-etc.R 7e54d5f08fc979198fb277423e8b86cc *R/biginteger.R 06c0c3990fe4960a246e7893f8e2d7d0 *R/bigq.R 148e5baac0cbb043d07e62369301fd5a *R/matrix-prods.R b6c07e29fb643e9385ef42e69d4b4738 *R/matrixq.R fb757b3d54ac3901f4bc6b233f4035d5 *R/matrixz.R 95f68ef3a6a5a0effdd2bd05bd6e91ef *R/zzz.R 0f1028b8542eaab2e409d127ff93b46b *TODO a8d707d0cad53cb4e52a114d1a441af8 *cleanup c4b815c07240206fcf7acfea4750ae9e *configure 65c713341ab0f7a730666645b6e9d007 *configure.ac c4ff09724b77a5383751dacc935b493f *data/Oakley1.R 76f950c0330af250fae4d9c1d5b13f84 *data/Oakley2.R ad746e23b07ecef7d2262f22c121e95b *man/BernoulliQ.Rd 5f6686564ecbbe8169b01377ccb05f48 *man/Oakley.Rd a195adba6ed88f2bd1969ea116139531 *man/Stirling.Rd 1880c26ba00eed98b29d4f0483006b0a *man/add.biginteger.Rd c67bdf971595c0339917ebe3c37f101b *man/apply.Rd 61e8bbe0f0fe7dd77b1af6974e30342f *man/asNumeric.Rd 70ad624ee83598cd6cc85d8fff4d4c1b *man/base-copies.Rd ccf930a97bb3127f9a62dbf17b21ba68 *man/biginteger.Rd 7896a01d450cb341ff0d547da198c022 *man/biginteger.rand.Rd cc6483b895776bc7cec1882a9da123e6 *man/bigrational.Rd 7a14c412536d57dfff347e257ba80d83 *man/binomQ.Rd f6814f8926e412d2a8a0d5880f434e8a *man/comp.biginteger.Rd 4c1e5520660a32530461f2f1f46eb665 *man/comp.bigq.Rd 5447ec49bb927b8807dfa4dbe32eaf98 *man/cumsum.Rd 0b8423af947fc21964d007cb8c59c7a2 *man/extract.Rd e084edcfc181ee02f5413ca29b5014d2 *man/extreme.Rd c637559f1daa1a09087c5879a3bfa939 *man/factor.Rd ad80cd8d85a4ef4d37cad1a78908c45a *man/factorialZ.Rd 2c8fc14724add744a5d5433f1a254c1c *man/fibonacci.Rd 7190fe72f8d431f47d8f3cb01527ef78 *man/formatN.Rd 66317fdc70826ceae15cbf0a30a61ef1 *man/frexpZ.Rd 707164fa9dd861b5b0ec93465c759d4c *man/gcd.Rd b4c7fe18f86b07055b1d12356809b968 *man/gcdex.Rd 453a9e2afec73e5e0f69903fc4728d36 *man/is.whole.Rd 61197493dbc44d8e0545d59cd159fd0e *man/isprime.Rd c5ec1ec30e9483a4cb02f45854dc653b *man/matrix.Rd 13ff65f59b4f53d6f504cf1d9372aac1 *man/modulus.Rd 8ee2b6889bb87c3cd38404b444a8b12c *man/mpfr.Rd 158a7d9b7fe35cb25762c7a53205a2c1 *man/nextprime.Rd 57f0d94dafcbcb7b3ce249d610cef66a *man/operators_bigq.Rd abafd95558517a2a0b6f8a9b4671f514 *man/powm.Rd 6188c692e3c6e7213f05b7eeb0b827b2 *man/roundQ.Rd bf889df64a7c88dace8e491e9eb67d35 *man/sizeinbase.Rd 8ff72446e3d97f374074ebaed3215503 *man/solve.Rd d8cb9c64227e9cabd609dd235eb3dd86 *man/utils.Rd 6efbea6ed0404655104f141b49a9e6ab *src/Makevars.in 055d49e4a190e10444c376787b2b54ca *src/Makevars.win cca3fe0ad8e8e547c04660f30c6610b5 *src/Rgmp.h 7254469978a02a5777868d5ec9d115d2 *src/apply.cc 2f25f95aedc17f66633efad43411089a *src/apply.h 27807d8c7d4d8fd10e3ed2503369c18f *src/biginteger.cc 1a49e287fb30d67c40c1d3027ba7fd34 *src/biginteger.h 7d247547fa1ec53449522ccd7cfa3791 *src/bigintegerR.cc 260726a3a45e8a50eebe59db1d37efed *src/bigintegerR.h 672d44b87f9ba7318b42a759218c9468 *src/bigmod.cc f2d008af0cee40156041b5b553b0a9d9 *src/bigmod.h a5a9d32e6b952c98f94fae50e07ccfdc *src/bigrational.cc 8782f3ecebbd0a5f0ddfd09d6e561081 *src/bigrational.h fcd11fad04cd7aaa2f7eb617b80ccdf2 *src/bigrationalR.cc 4cd8917e7563a9069a4fe6440ee597bb *src/bigrationalR.h 4f31610a5647b81440ec4e41b7294b15 *src/bigvec.cc a7adb610efac5194b89416c6aa844020 *src/bigvec.h 5eb5104bfea539fa388ed758262e0f37 *src/bigvec_q.cc 1382f5f9462a099eedcd567f1280f357 *src/bigvec_q.h f790bcc5f9fee1e039f07f341c7c8889 *src/extract_matrix.cc 238beedaedce69af34e0db79dc52af46 *src/extract_matrix.h 3c29cdb07b3ad1a5bcc96011673df6f4 *src/factor.cc c2c8803dbb6bb4aa409704e91b4ce6b5 *src/factor.h 8dacd53e9a8c5be245b8c74b2bd2efd3 *src/factorize.cc fa4b1298454f3eab5efccd4dc82d2c78 *src/factorize.h 8f93458848582beaa61cb672ada2892a *src/init.cc 96ff77b54462a57fa7a5afd159c101f4 *src/matrix.cc 476f0db7a86aeba7d5cc05cda88345c1 *src/matrix.h 09041b8017b4365a5a87fab848b88bc0 *src/matrixq.cc e4455d2faa62646eb8bdbb6ee92ee23c *src/matrixq.h 7ddf216fc7d6c1796f6eac06289eb8de *src/primes.h 82b3817dc630f18e2556edacc8bdc618 *src/solve.cc 71a758c8543a923b60658a8b7faf3311 *src/solve.h 71d8cfe2fbe71f04b94d3bf0688f218a *src/templateMatrix.h 7076c656465f9b92e0278367734a2b5a *tests/arith-ex.R 2eef91cbf19cbc90243c6472702189bb *tests/basic-ex.R c1debb0876b2e1b11ac96708f1a7dcc6 *tests/gmp-test.R f8760f443f57e3eb8e3b7557bdfde731 *tests/gmp-test.Rout.save gmp/Changes0000644000176200001440000000656214444267422012352 0ustar liggesusersSat Apr 10 2010: 0.4.12 * fix for sun c++ compiler * add sum() functions. Tue Oct 27 2009: 0.4.11 * minor R & cpp warnings fix Sat Jan 24 2009: 0.4.9 * move printf to Rprintf function * add powm function. Mon Feb 25 2008: 0.4.8 * correct a bug on extract matrix (in affectation x[y]<- value #...) * correct a bug on extract matrix (an invalid memory read, cause invalid result erraticly) Mon Feb 17 2008: 0.4.7 * suppress a bug on rational matrix. Tue Sep 14 2007: 0.4-6 * correction on c++: supress all g++ warnings Tue Sep 14 2007: 0.4-5 * correction of bug ref 698 [abs.bigz] * man pages corrected Tue May 12 2007: 0.4-4 * Other corrections of S3 generic/method consistency (add parameter ... on some functions) Tue May 10 2007: 0.4-3 * correction of S3 generic/method consistency (add parameter ... on some functions) Sun Jan 21 2007: 0.4-2 Sun Dec 17 2006 * add apply function Sun Dec 03 2006 * add cumsum & prod * correct bugs on NA & not finite values. move NA_REAL check to R_FINITE check use carefully getValueTemp as it does not contains NA flag. Sun Nov 05 2006 * add max & min (bigintegers) Mon Oct 09 2006 0.4-1 * Correction of bug on function urand.bigz() Sat Jun 17 2006 0.4-0 * extract functions done with matrix (x[i,j] & x[i,j] <- value) Sun May 28 2006 * Matrix integration & solve function in Z/nZ or Q Thu May 19 2006 * rewritten bigrational class with mpq_t value * use of 2 new class bigvec & bigvec_q that includes vector(s) + nrow value. * catch bug in fibnum & lucnum when negative values or NULL. Wed Mar 15 2006 * catch bug when negative integer values (like as.bigz(as.integer(-4))) Tue Mar 14 2006 * catch bug with c.bigz(3,NULL) (and other bugs with NULL argument while add cas NILSXP in create_vector * check for positive values in lucnum & fibnum. Thu Jan 20 2006 0.3-4 * minor changes on data Oakley Wed Jul 27 2005 0.3-3 * minor changes on man page Fri May 06 2005 Minor bug fixed... * error message corrected on function pow * bug fixed (a test to check 0 values with mpz_sgn instead of as_long) * man page modified for as.bigz Wed Mar 23 2005 * catch illegal base argument at as.character.bigz (fix segfault) * added RFC 2409 global unique Diffie-Hellman groups as data constants * typos in DESCRIPTION Thu Mar 17 2005 * add a base 16 output function * Makevars.win Thu Jan 13 2005 * bug fixed on rational numbers class & use of negatives values allowed for both rational and integer class. Mon Jan 10 2005 * bug fixed on rational numbers class Wed Jan 5 2005 * First try for a class for rational numbers Fri Dec 10 2004 * Function Factorize Fri Dec 09 2004: 0.2-2 Thu Dec 02 2004: * biginteger class changed to bigz * man page updated. Sat Nov 27 2004: * New function c.biginteger, rep.biginteger, sizeinbase * former functions nextprime, isprime, gcdex, random rewritten. => no more gmp.cc, gmp.R * Functions for Fibonacci and Lucas number computation ! * Some changes in C++ comments to have a doc with doxygen. Wed Nov 24 2004: * Modifs on doc Tue Nov 09 2004: 0.2-1 * Suppressed macro definitions in Rinternals.h, and replaced macro calls with plain function names. Trying to avoid collisions with stl definitions, i.e. length() Wed Oct 27 2004: 0.2 * Vectorized engine rewritten Mon Sep 27 2004: 0.1 * Initial revision gmp/R/0000755000176200001440000000000014662051405011241 5ustar liggesusersgmp/R/AllClasses-etc.R0000644000176200001440000000216414444267422014174 0ustar liggesusers ## This helps to define single-dispatch methods for asNumeric() : 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 <- unclass(x) # don't want class-specific subset methods i1 <- -seq_len(lag) if (ismat) for (i in seq_len(differences)) x <- x[i1, , drop = FALSE] - x[-nrow(x):-(nrow(x)-lag+1L), , drop = FALSE] else for (i in seq_len(differences)) x <- x[i1] - x[-length(x):-(length(x)-lag+1L)] ##>> class(r) <- oldClass(x) x } ##--> and entries in ../NAMESPACE gmp/R/matrixq.R0000644000176200001440000000242314662051403013050 0ustar liggesusersmatrix.bigq <- function(data=NA,nrow=1, ncol=1, byrow=FALSE, dimnames =NULL, den = NA, ...) { if(!is.null(dimnames)) warning("'dimnames' are not implemented for this class") .Call(as_matrixq, data, as.integer(nrow), as.integer(ncol), as.integer(byrow), den) } as.matrix.bigq <- function(x, ...) { if(is.matrix(x) || is.data.frame(x) || length(dim(x)) == 2L) { d <- dim(x) n <- d[1L] p <- d[2L] } else { n <- length(x) p <- 1L } matrix.bigq(x, nrow=n, ncol=p) } as.vector.bigq <- function(x, mode="any") { if(mode == "list") { ## "easy"; TODO: gmpToListQ() withOUT matrix .Call(gmpMatToListQ, matrix.bigq(x, nrow=length(x), ncol=1L), 1L) } else if (mode == "any") { attr(x,"nrow") <- NULL x } else as.vector(as.double(x), mode=mode) } t.bigq <- function(x) .Call(bigq_transposeR, x) cbind.bigq <- function(..., deparse.level = 1) .Call(bigrational_cbind, list(...)) rbind.bigq <- function(..., deparse.level = 1) .Call(bigrational_rbind, list(...)) apply.bigq <- function(X, MARGIN, FUN, ...) { ## change matrix to a list: X <- .Call(gmpMatToListQ, X, as.integer(MARGIN)) ## then use std lapply() and convert back to vector: .Call(bigrational_c, lapply(X, FUN, ...)) } gmp/R/bigq.R0000644000176200001440000002760614447321743012327 0ustar liggesusers#---------------------------------------------------------- # # Author : Antoine Lucas (adapted from biginteger class made by # Immanuel Scholz) # # Brief : Stub to call the dll functions # # Licence : GPL (>= 2) # #---------------------------------------------------------- add.bigq <- function(e1, e2) .Call(bigrational_add, e1, e2) add.big <- function(e1, e2) { if(!is.bigq(e1) && !is.bigq(e2)) # try integer .Call(biginteger_add, e1, e2) else .Call(bigrational_add, e1, e2) } ## the 'e2=NULL' has been documented forever sub.bigq <- function(e1, e2=NULL) { if(is.null(e2)) .Call(bigrational_sub, 0,e1) else .Call(bigrational_sub,e1,e2) } ## simple version: .sub.bigq <- function(e1, e2) .Call(bigrational_sub,e1,e2) sub.big <- function(e1, e2=NULL) { if(!is.bigq(e1) && !is.bigq(e2)) # try integer sub.bigz(e1, e2) else if(is.null(e2)) .Call(bigrational_sub, 0,e1) else .Call(bigrational_sub,e1,e2) } mul.bigq <- function(e1, e2) .Call(bigrational_mul, e1, e2) mul.big <- function(e1, e2) { if(!is.bigq(e1) && !is.bigq(e2)) # try integer .Call(biginteger_mul, e1, e2) else .Call(bigrational_mul, e1, e2) } div.bigq <- function(e1, e2) .Call(bigrational_div, e1, e2) div.big <- function(e1, e2) { if(!is.bigq(e1) && !is.bigq(e2)) # try integer .Call(biginteger_div, e1, e2) else .Call(bigrational_div, e1, e2) } pow.bigq <- function(e1, e2) { if(!all(is.whole(e2[is.finite(e2)]))) stop(" ^ is not rational; consider require(Rmpfr); mpfr(*) ^ *") .Call(bigrational_pow, e1, as.bigz(e2)) } pow.big <- function(e1, e2) { if(!all(is.whole(e2[is.finite(e2)]))) stop(" ^ is not rational; consider require(Rmpfr); mpfr(*) ^ *") if(!is.bigq(e1)) .Call(biginteger_pow, e1, as.bigz(e2)) else .Call(bigrational_pow, e1, as.bigz(e2)) } print.bigq <- function(x, quote = FALSE, initLine = TRUE, ...) { if((n <- length(x)) > 0) { if(initLine) { cat("Big Rational ('bigq') ") kind <- if(!is.null(nr <- attr(x, "nrow"))) sprintf("%d x %d matrix", nr, n/nr) else if(n > 1) sprintf("object of length %d", n) else "" cat(kind,":\n", sep="") } print(as.character(x), quote = quote, ...) } else cat("bigq(0)\n") invisible(x) } as.bigq <- function(n, d = 1L) { .Call(bigrational_as, n, d) } as.character.bigq <- function(x, b = 10L, ...) { .Call(bigrational_as_character, x, b) } formatN.bigq <- function(x, ...) { r <- as.character(x, ...) if(any(iI <- is.whole.bigq(x))) r[iI] <- paste0(r[iI],"/1") r } as.double.bigq <- function(x,...) .Call(bigrational_as_numeric, x) ## maybe sub-optimal, but at least "R-consistent" in warnings/errors...: as.integer.bigq <- function(x,...) as.integer(.Call(bigrational_as_numeric, x)) .bigq2num <- function(x) { ## cat(".bigq2num():\n") r <- .Call(bigrational_as_numeric, x) if(!is.null(d <- dim(x))) dim(r) <- d r } setMethod("asNumeric", "bigq", .bigq2num) denominator <- function(x) { r <- .Call(bigrational_den,x) if(!is.null(d <- dim(x))) dim(r) <- d r } "denominator<-" <- function(x,value) as.bigq(numerator(x),value) numerator <- function(x) { r <- .Call(bigrational_num,x) if(!is.null(d <- dim(x))) dim(r) <- d r } "numerator<-" <- function(x,value) as.bigq(value,denominator(x)) as.bigz.bigq <- function(a, mod = NA) { ## "FIXME": considerably faster in C / C++ if(any(ina <- is.na.bigq(a))) { r <- rep.bigz(NA_bigz_, length(a)) if(any(ii <- !ina)) { a <- a[ii] r[ii] <- as.bigz(numerator(a) %/% denominator(a), mod[ii]) } attr(r,"nrow") <- attr(a, "nrow") r } else # no NA's as.bigz(numerator(a) %/% denominator(a), mod) } length.bigq<- function(x) .Call(bigrational_length, x) `length<-.bigq` <- function(x, value) .Call(bigrational_setlength, x, value) ## .bigq(): *not* used lt.bigq <- function(e1, e2) .Call(bigrational_lt, e1, e2) gt.bigq <- function(e1, e2) .Call(bigrational_gt, e1, e2) lte.bigq <- function(e1, e2) .Call(bigrational_lte, e1, e2) gte.bigq <- function(e1, e2) .Call(bigrational_gte, e1, e2) eq.bigq <- function(e1, e2) .Call(bigrational_eq, e1, e2) neq.bigq <- function(e1, e2) .Call(bigrational_neq, e1, e2) is.na.bigq <- function(x) .Call(bigrational_is_na, x) is.whole.bigq <- function(x) .Call(bigrational_is_int, x) is.finite.bigq <- function(x) !is.na.bigq(x) # otherwise all are finite is.infinite.bigq <- function(x) rep.int(FALSE, length(x)) if(FALSE) ## This does not work: is.atomic is primitive *NON*-generic: is.atomic.bigq <- function(x) FALSE # otherwise does return TRUE ! ### o --- really dispatch on two arguments --> use S4 if(FALSE) { ## not working really --- see also ./matrix-prods.R setMethod("Ops", signature(e1 = "bigq", e2 = "bigz"), function(e1, e2) callGeneric(e1, as.bigq(e2))) setMethod("Ops", signature(e1 = "bigz", e2 = "bigq"), function(e1, e2) callGeneric(as.bigq(e1), e2)) } ###------------------------- 'Math' S3 group ------------------------------ ## Most 'Math' group functions should go via CRAN package 'Rmpfr' : Math.bigq <- function(x, ...) { if(requireNamespace("Rmpfr", quietly=TRUE)) { NextMethod(Rmpfr::.bigq2mpfr(x), ...) # FIXME use ..bigq2mpfr (two '.') in future } else stop("Math group method ", dQuote(.Generic), "is available via CRAN R package 'Rmpfr'.\n", "Install it and try again") } abs.bigq <- function(x) { numerator(x) <- abs(numerator(x)) x } sign.bigq <- function(x) sign(numerator(x)) trunc.bigq <- function(x, ...) ## := sign(x) * floor(abs(x)) = sign.bigq(x) * as.bigz.bigq(abs.bigq(x)) floor.bigq <- function(x) as.bigz.bigq(x) ceiling.bigq <- function(x) -as.bigz.bigq(-x) if(FALSE) ## this was used in round.bigq() for several months in 2020: round0 <- function(x) as.bigz.bigq(x + as.bigq(1, 2)) ##' rounding to integer a la "nearbyint()" -- i.e. "round to even" round0 <- function(x) { nU <- as.bigz.bigq(xU <- x + as.bigq(1, 2)) # traditional round: .5 rounded up if(any(I <- is.whole.bigq(xU))) { # I <==> x == .5 : "hard case" I[I] <- .mod.bigz(nU[I], 2L) == 1L # rounded up is odd ==> round *down* nU[I] <- nU[I] - 1L } nU } roundQ <- function(x, digits = 0, r0 = round0) { ## round(x * 10^d) / 10^d -- vectorizing in both (x, digits) p10 <- as.bigz(10) ^ digits # class: if(all(digits >= 0)) "bigz" else "bigq" r0(x * p10) / p10 } ##' round() method ==> signature = (x, digits) {round0 *not* allowed as argument} round.bigq <- function(x, digits = 0) roundQ(x, digits) cumsum.bigq <- function(x) .Call(bigrational_cumsum, x) ## TODO: add cummax(), cummin(), cumprod() ## FIXME: implement log() etc --- see ./biginteger.R ##------------end{'Math'} group ------------------------------------- ##' to be applied e.g. to the result of lapply(, Fn) c_bigq <- function(L) .Call(bigrational_c, L) c.bigq <- function(..., recursive = FALSE) c_bigq(list(...)) ## This is practically identical to grid :: rep.unit : rep.bigq <- function(x, times=1, length.out=NA, each=1, ...) { ## if (length(x) == 0) ## stop("invalid 'unit' object") if(!missing(times) && missing(length.out) && missing(each)) .Call(bigrational_rep,x,times) else { ## Determine an appropriate index, then call subsetting code x[ rep(seq_along(x), times=times, length.out=length.out, each=each) ] } } duplicated.bigq <- duplicated.bigz ## cheap (for now) ## unique.bigq <- function(x, incomparables = FALSE, ...) ## x[!duplicated(x, incomparables=incomparables, ...)] unique.bigq <- unique.bigz ##' mean() method needed for all.equal.bigq() below: mean.bigq <- function(x, trim = 0, na.rm = FALSE, ...) { if(trim != 0) stop("'trim > 0' is not yet implemented for \"bigq\"") if (na.rm) x <- x[!is.na(x)] sum(x) / length(x) } ## Almost: ## all.equal.bigq <- all.equal.numeric ## environment(all.equal.bigq) <- environment()# i.e. of 'gmp' name space ## but we copy-paste all.equal.numeric {and slightly modify}: all.equal.bigq <- function(target, current, tolerance = .Machine$double.eps ^ .5, scale = NULL, check.attributes = FALSE, check.class=FALSE, ...) { msg <- if(check.attributes) attr.all.equal(target, current, tolerance=tolerance, scale=scale, ...) if(check.class && data.class(target) != data.class(current)) { msg <- c(msg, paste0("target is ", data.class(target), ", current is ", data.class(current))) return(msg) } lt <- length(target) lc <- length(current) cplx <- FALSE if(lt != lc) { ## *replace* the 'Lengths' msg[] from attr.all.equal(): if(!is.null(msg)) msg <- msg[- grep("\\bLengths\\b", msg)] msg <- c(msg, paste0("bigq", ": lengths (", lt, ", ", lc, ") differ")) return(msg) } ## remove atttributes (remember these are both numeric or complex vectors) ## one place this is needed is to unclass Surv objects in the rpart test suite. target <- as.vector(target) current <- as.vector(current) out <- is.na(target) if(any(out != is.na(current))) { msg <- c(msg, paste("'is.NA' value mismatch:", sum(is.na(current)), "in current", sum(out), "in target")) return(msg) } out <- out | target == current if(all(out)) { if (is.null(msg)) return(TRUE) else return(msg) } target <- target[!out] current <- current[!out] if(is.integer(target) && is.integer(current)) target <- as.double(target) xy <- mean((if(cplx) Mod else abs)(target - current)) what <- if(is.null(scale)) { xn <- mean(abs(target)) if(is.finite(xn) && xn > tolerance) { xy <- xy/xn "relative" } else "absolute" } else { xy <- xy/scale "scaled" } if (cplx) what <- paste(what, "Mod") # PR#10575 if(is.na(xy) || xy > tolerance) msg <- c(msg, paste("Mean", what, "difference:", format(xy))) if(is.null(msg)) TRUE else msg } solve.bigq <- function(a,b,...) { if(missing(b)) .Call(inverse_q,a) else .Call(solve_q,a,b) } `[[.bigq`<- function(x, i=NA) { .Call(bigrational_get_at, x, i) } `[[<-.bigq` <- function(x, i=NA, value) { .Call(bigrational_set_at, x, i, value) } `[.bigq` <- function(x, i=NULL, j=NULL, drop=TRUE) { mdrop <- missing(drop) Narg <- nargs() - (!mdrop) # matrix access [i,j] [,j] [i,] # vector access [i] matrixAccess = Narg > 2 has.j <- !missing(j) if(!is.null(attr(x, "nrow")) & matrixAccess) { ## matrix .Call(matrix_get_at_q, x, i,j) } else { ## non-matrix if(has.j) stop("invalid vector subsetting") r <- .Call(bigrational_get_at, x, i) attr(r,"nrow") <- NULL r } } `[<-.bigq` <- function(x,i=NULL,j=NULL,value) { matrixAccess = nargs() > 3 has.j <- !missing(j) if(!is.null(attr(x, "nrow")) & matrixAccess) { ## matrix .Call(matrix_set_at_q, x, value,i,j ) } else { ## non-matrix -- ugly workaround: if(has.j) stop("invalid vector subsetting") r <- .Call(bigrational_set_at, x, i, value ) attr(r,"nrow") <- attr(x, "nrow") r } } max.bigq <- function(...,na.rm=FALSE) { .Call(bigrational_max, c.bigq(...), na.rm) } min.bigq <- function(...,na.rm=FALSE) { .Call(bigrational_min, c.bigq(...), na.rm) } ## FIXME: implement faster in C setMethod("which.max", "bigq", function(x) which.max(x == max(x))) setMethod("which.min", "bigq", function(x) which.max(x == min(x))) sum.bigq <- function(..., na.rm = FALSE) { X <- c.bigq(...) .Call(bigrational_sum, if(na.rm) X[!is.na(X)] else X) } prod.bigq <- function(..., na.rm = FALSE) { X <- c.bigq(...) .Call(bigrational_prod, if(na.rm) X[!is.na(X)] else X) } "!.bigq" <- function(a) a == 0 "|.bigq" <- function(a,b) { a1 = a != 0 b1 = b != 0 a1 | b1 } "&.bigq" <- function(a,b) { a1 = a != 0 b1 = b != 0 a1 & b1 } "xor.bigq" <- function(x,y) { a = x != 0 b = y != 0 xor(a, b) } gmp/R/zzz.R0000755000176200001440000000131114444267422012226 0ustar liggesusers## we "need" S4 methods for dispatch on both (x,y) .noGenerics <- TRUE .conflicts.OK <- TRUE ## gmp-ify base function(s): environment(outer) <- environment()# i.e. asNamespace("gmp") .gmpVersion <- function() .Call(R_gmp_get_version) gmpVersion <- function() numeric_version(sub("^([0-9]+\\.[0-9]+\\.[0-9]+).*","\\1", .gmpVersion())) .onLoad <- function(libname, pkgname) { options("gmp:warnModMismatch" = TRUE, ## see ../man/biginteger.Rd "gmp:warnNoInv" = TRUE) ## ../man/add.biginteger.Rd | ../src/bigmod.cc ## as.big[zq]() need package dynloaded : gmpEnv <- parent.env(environment()) gmpEnv$ NA_bigz_ <- as.bigz(NA) gmpEnv$ NA_bigq_ <- as.bigq(NA) invisible() } gmp/R/biginteger.R0000644000176200001440000003423314662051324013510 0ustar liggesusersis.bigz <- function(x) is.raw(x) && inherits(x, "bigz") is.bigq <- function(x) is.raw(x) && inherits(x, "bigq") setGeneric("asNumeric", useAsDefault = function(x) { if(is.numeric(x)) x else if(is.atomic(x)) { storage.mode(x) <- "numeric"; x } else as(x, "numeric") }) #---------------------------------------------------------- # # Author : Immanuel Scholz (immanuel.scholz@gmx.de) # Technische Universitaet Dresden # # Brief : Stub to call the dll functions # # Licence : GPL (>= 2) # #---------------------------------------------------------- add.bigz <- function(e1, e2) { if(inherits(e2, "bigq")) .Call(bigrational_add, e1, e2) else .Call(biginteger_add, e1, e2) } sub.bigz <- function(e1, e2=NULL) { if(is.null(e2)) .Call(biginteger_sub, 0, e1) ## else if(inherits(e2, "bigq")) ## .Call(bigrational_sub, e1, e2) else .Call(biginteger_sub, e1, e2) } mul.bigz <- function(e1, e2) { if(inherits(e2, "bigq")) .Call(bigrational_mul, e1, e2) else .Call(biginteger_mul, e1, e2) } ## divq : integer division "%/%.bigz" <- divq.bigz <- function(e1, e2) { if(inherits(e2, "bigq")) { if(!all(is.whole(e2[is.finite(e2)]))) e2 <- as.bigz(e2) else stop("In 'n %/% d', d must be integer") } .Call(biginteger_divq, e1, e2) } ## div : division of integers -> either rational or (mod) integer division div.bigz <- function(e1, e2) { if(inherits(e2, "bigq")) .Call(bigrational_div, e1, e2) else .Call(biginteger_div, e1, e2) } "%%.bigz" <- mod.bigz <- function(e1, e2) { if(inherits(e2, "bigq")) { if(!all(is.whole.bigq(e2[is.finite(e2)]))) e2 <- as.bigz(e2) else stop("In 'n %% d', d must be integer") } .Call(biginteger_mod, e1, e2) } .mod.bigz <- function(e1, e2) .Call(biginteger_mod, e1, e2) pow.bigz <- function(e1, e2,...) { if(inherits(e2, "bigq")) pow.bigq(e1, e2) else .Call(biginteger_pow, e1, e2) } ##' Inverse: inv(a,b) := (1 / a) (modulo b) inv.bigz <- function(a,b,...) .Call(biginteger_inv,a,b) "!.bigz" <- function(a) a == 0 ## as.boolean(x): x != 0 "|.bigz" <- function(a,b) { a1 = a != 0 b1 = b != 0 a1 | b1 } "&.bigz" <- function(a,b) { a1 = a != 0 b1 = b != 0 a1 & b1 } "xor.bigz" <- function(x,y) { a1 = x != 0 b1 = y != 0 xor(a1 , b1) } gcd <- function(a,b) UseMethod("gcd") gcd.default <- function(a,b) as.integer(gcd.bigz(a,b)) gcd.bigz <- function(a,b) .Call(biginteger_gcd,a,b) ## just because lcm() is a trivial function in 'graphics' .. hmm ##lcm <- function(a,b) ## UseMethod("lcm") lcm.default <- function(a,b) as.integer(lcm.bigz(a,b)) lcm.bigz <- function(a,b) .Call(biginteger_lcm,a,b) print.bigz <- function(x, quote = FALSE, initLine = is.null(modulus(x)), ...) { if((n <- length(x)) > 0) { if(initLine) { cat("Big Integer ('bigz') ") kind <- if(!is.null(nr <- attr(x, "nrow"))) sprintf("%d x %d matrix", nr, n/nr) else if(n > 1) sprintf("object of length %d", n) else "" cat(kind,":\n", sep="") } print(as.character(x), quote = quote, ...) } else cat("bigz(0)\n") invisible(x) } as.bigz <- function(a, mod = NA) { if(isZ <- missing(mod) && inherits(a, "bigz")) mod <- modulus(a) # possibly NULL if(is.null(mod)) mod <- NA if(!isZ && inherits(a, "bigq")) as.bigz.bigq(a, mod) else .Call(biginteger_as, a, mod) } ## the .as*() functions are exported for Rmpfr .as.bigz <- function(a, mod = NA) { if(inherits(a, "bigq")) as.bigz.bigq(a, mod) else .Call(biginteger_as, a, mod) } ..as.bigz <- function(a, mod = NA) .Call(biginteger_as, a, mod) .as.char.bigz <- as.character.bigz <- function(x, b = 10L, ...) .Call(biginteger_as_character, x, b) ##' format() Numbers such as to distinguish bigz, integer, double, mpfr, etc formatN <- function(x, ...) UseMethod("formatN") formatN.integer <- function(x, ...) paste0(as.character(x, ...), "L") formatN.bigz <- function(x, ...) { r <- as.character(x, ...) if(any(noMod <- is.null(modulus(x)))) r[noMod] <- paste0(r[noMod],"_Z") r } formatN.double <- function(x, ...) { r <- vapply(x, format, "", ...) if(any(intLike <- !grepl("[^-0-9]",r))) r[intLike] <- paste0(r[intLike],".") r } ##' Default Method: Use the standard format() --- e.g. for complex formatN.default <- function(x, ...) format(x, ...) as.double.bigz <- function(x,...) .Call(biginteger_as_numeric, x) as.integer.bigz <- function(x,...) .Call(biginteger_as_integer, x) .bigz2num <- function(x) { r <- .Call(biginteger_as_numeric, x) if(!is.null(d <- dim(x))) dim(r) <- d r } setMethod("asNumeric", "bigz", .bigz2num) length.bigz <- function(x) .Call(biginteger_length, x) "length<-.bigz"<- function(x, value) .Call(biginteger_setlength, x, value) modulus <- function(a) UseMethod("modulus") modulus.bigz <- function(a) attr(a, "mod") `modulus<-` <- function(a, value) UseMethod("modulus<-") `modulus<-.bigz` <- function(a, value) as.bigz(a, value) ## inv <- function(a,...) UseMethod("inv") ## pow <- function(a,...) UseMethod("pow") powm <- function(x,y, n) .Call(biginteger_powm, x,y,n) ## .bigz(): *not* used lt.bigz <- function(e1, e2) .Call(biginteger_lt, e1, e2) gt.bigz <- function(e1, e2) .Call(biginteger_gt, e1, e2) lte.bigz <- function(e1, e2) .Call(biginteger_lte, e1, e2) gte.bigz <- function(e1, e2) .Call(biginteger_gte, e1, e2) eq.bigz <- function(e1, e2) .Call(biginteger_eq, e1, e2) neq.bigz <- function(e1, e2) .Call(biginteger_neq, e1, e2) lt.big <- function(e1, e2) { if(!is.bigq(e1) && !is.bigq(e2)) # try integer .Call(biginteger_lt, e1, e2) else .Call(bigrational_lt, e1, e2) } gt.big <- function(e1, e2) { if(!is.bigq(e1) && !is.bigq(e2)) # try integer .Call(biginteger_gt, e1, e2) else .Call(bigrational_gt, e1, e2) } lte.big <- function(e1, e2) { if(!is.bigq(e1) && !is.bigq(e2)) # try integer .Call(biginteger_lte, e1, e2) else .Call(bigrational_lte, e1, e2) } gte.big <- function(e1, e2) { if(!is.bigq(e1) && !is.bigq(e2)) # try integer .Call(biginteger_gte, e1, e2) else .Call(bigrational_gte, e1, e2) } eq.big <- function(e1, e2) { if(!is.bigq(e1) && !is.bigq(e2)) # try integer .Call(biginteger_eq, e1, e2) else .Call(bigrational_eq, e1, e2) } neq.big <- function(e1, e2) { if(!is.bigq(e1) && !is.bigq(e2)) # try integer .Call(biginteger_neq, e1, e2) else .Call(bigrational_neq, e1, e2) } is.whole <- function(x) UseMethod("is.whole") is.whole.default <- function(x) { n <- length(x) if(is.atomic(x)) { if(is.integer(x) || is.logical(x)) return(rep.int(TRUE, n)) if(is.numeric(x)) return(x == floor(x)) if(is.complex(x)) return(x == round(x)) } ## else: logical(n) ## == rep.int(FALSE, length(x)) } is.na.bigz <- function(x) .Call(biginteger_is_na, x) is.finite.bigz <- function(x) !is.na.bigz(x) # otherwise all are finite is.whole.bigz <- function(x) rep.int(TRUE, length(x)) is.infinite.bigz <- function(x) rep.int(FALSE, length(x)) frexpZ <- function(x) .Call(bigI_frexp, x) ##' @title log2(Inverse of frexpZ(a)) ##' @param L list(d = ., exp = .) ##' @return numeric vector ##' @author Martin Maechler lg2.invFrexp <- function(L) { stopifnot(is.list(L), is.numeric(d <- L$d), is.numeric(ex <- L$exp), (length(d)) == length(ex)) ex + log2(d) } ###------------------------- 'Math' S3 group ------------------------------ ## o 'abs', 'sign', 'sqrt', ## 'floor', 'ceiling', 'trunc', ## 'round', 'signif' ## o 'exp', 'log', 'expm1', 'log1p', ## 'cos', 'sin', 'tan', ## 'acos', 'asin', 'atan' ## 'cosh', 'sinh', 'tanh', ## 'acosh', 'asinh', 'atanh' ## o 'lgamma', 'gamma', 'digamma', 'trigamma' ## o 'cumsum', 'cumprod', 'cummax', 'cummin' ## Most 'Math' group functions should go via CRAN package 'Rmpfr' : Math.bigz <- function(x, ...) { if(requireNamespace("Rmpfr", quietly=TRUE)) { NextMethod(Rmpfr::.bigz2mpfr(x)) # FIXME use ..bigz2mpfr (two '.') in future } else stop("Math group method ", dQuote(.Generic), "is available via CRAN R package 'Rmpfr'.\n", "Install it and try again") } abs.bigz <- function(x) .Call(biginteger_abs,x) sign.bigz <- function(x) .Call(biginteger_sgn,x) floor.bigz <- ceiling.bigz <- function(x) x trunc.bigz <- function(x, ...) x round.bigz <- function(x, digits=0) { ## round(x * 10^d) / 10^d stopifnot(length(digits) == 1L) if(digits >= 0) x else { # digits < 0 p10 <- as.bigz(10) ^ -digits # still bigz round(x / p10) * p10 } } gamma.bigz <- function(x) factorialZ(x-1) cumsum.bigz <- function(x) .Call(biginteger_cumsum, x) ## TODO: add cummax(), cummin(), cumprod() log2.bigz <- function(x) .Call(biginteger_log2, x) ## not exported: ln.bigz <- function(x) .Call(biginteger_log, x) log.bigz <- function(x, base=exp(1)) { if(missing(base)) ln.bigz(x) else ln.bigz(x)/log(base) } log10.bigz <- function(x) ln.bigz(x) / log(10) ##------------end{'Math'} group ------------------------------------- ###------------------------- 'Summary' S3 group ------------------------------ ##---- "max" "min" "range" "prod" "sum" "any" "all" ----- max.bigz <- function(...,na.rm=FALSE) { X <- c.bigz(...) if(inherits(X, "bigq")) .Call(bigrational_max, X, na.rm) else .Call(biginteger_max, X, na.rm) } min.bigz <- function(...,na.rm=FALSE) { X <- c.bigz(...) if(inherits(X, "bigq")) .Call(bigrational_min, X, na.rm) else .Call(biginteger_min, X, na.rm) } ## range(): works automatically via range.default() and the above min(), max() prod.bigz <- function(..., na.rm = FALSE) { X <- c.bigz(...) if(inherits(X, "bigq")) .Call(bigrational_prod, if(na.rm) X[!is.na(X)] else X) else .Call(biginteger_prod, if(na.rm) X[!is.na(X)] else X) } sum.bigz <- function(..., na.rm = FALSE) { X <- c.bigz(...) if(inherits(X, "bigq")) .Call(bigrational_sum, if(na.rm) X[!is.na(X)] else X) else .Call(biginteger_sum, if(na.rm) X[!is.na(X)] else X) } ##------------end{Summary group}------------------------------------ ## FIXME: implement faster in C setMethod("which.max", "bigz", function(x) which.max(x == max(x))) setMethod("which.min", "bigz", function(x) which.max(x == min(x))) ##' to be applied e.g. to the result of lapply(, Fn) c_bigz <- function(L) .Call(biginteger_c, L) c.bigz <- function(..., recursive = FALSE) { argL <- list(...) if(any(vapply(argL, inherits, NA, what="bigq"))) c_bigq(argL) else c_bigz(argL) } ## This is practically identical to grid :: rep.unit : rep.bigz <- function(x, times=1, length.out=NA, each=1, ...) { ## if (length(x) == 0) ## stop("invalid 'unit' object") if(!missing(times) && missing(length.out) && missing(each)) .Call(biginteger_rep, x, times) else { ## Determine an appropriate index, then call subsetting code x[ rep(seq_along(x), times=times, length.out=length.out, each=each) ] } } duplicated.bigz <- function(x, incomparables = FALSE, ...) { x <- as.character(x) # lazy and inefficient --> TODO in C++ NextMethod("duplicated", x) } unique.bigz <- function(x, incomparables = FALSE, ...) x[!duplicated(x, incomparables, ...)] all.equal.bigz <- function(target, current, ...) { if(is.bigq(target)) return(all.equal.bigq(target, current, ...)) ## Using tolerance = 0 --- implicitly below if(length(target) != length(current)) return("lengths differ") if(!identical(dim(target), dim(current))) return("dimensions differ") target <- as.vector(target) current <- as.vector(current) ina <- is.na(target) if(any(ina != is.na(current))) paste("'is.NA' value mismatch:", sum(is.na(current)), "in current", sum(ina), "in target") else if(all(ina | target == current)) # equal NAs _or_ numbers TRUE else "'target'(bigz) and 'current' differ" } # Isprime, return: # 0 if not prime # 1 if probably prime # 2 if prime isprime <- function(n,reps=40) { .Call(biginteger_is_prime, n, as.integer(reps)) } nextprime <- function(n) .Call(biginteger_nextprime, n) gcdex <- function(a, b) .Call(biginteger_gcdex, a, b) urand.bigz <- function(nb=1, size=200, seed=0) { ok <- (seed != 0) .Call(biginteger_rand_u, as.integer(nb), as.integer(size), seed, as.integer(ok)) } sizeinbase <- function(a, b=10) { if(as.integer(b) < 2) stop("base must be >= 2") .Call(biginteger_sizeinbase, a, as.integer(b)) } factorialZ <- function(n) .Call(bigI_factorial, as.integer(n)) chooseZ <- function(n, k) .Call(bigI_choose, n, as.integer(k)) fibnum <- function(n) .Call(bigI_fibnum, as.integer(n)) fibnum2 <- function(n) .Call(bigI_fibnum2, as.integer(n)) lucnum <- function(n) .Call(bigI_lucnum, as.integer(n)) lucnum2 <- function(n) .Call(bigI_lucnum2, as.integer(n)) factorize <- function(n) .Call(factorR, as.bigz(n)) solve.bigz <- function(a, b,...) { if(missing(b)) .Call(inverse_z, a) else .Call(solve_z, a, b) } `[[.bigz` <- function(x, i=NA) .Call(biginteger_get_at, x, i) `[[<-.bigz` <- function(x, i=NA, value) .Call(biginteger_set_at, x, i, value) `[.bigz` <- function(x, i=NULL, j=NULL, drop=TRUE) { mdrop <- missing(drop) Narg <- nargs() - (!mdrop) # matrix access [i,j] [,j] [i,] # vector access [i] matrixAccess = Narg > 2 has.j <- !missing(j) if(!is.null(attr(x, "nrow")) & matrixAccess) { ## matrix .Call(matrix_get_at_z, x, i,j) } else { ## non-matrix if(has.j) stop("invalid vector subsetting") r <- .Call(biginteger_get_at, x, i) attr(r,"nrow") <- NULL r } } `[<-.bigz` <- function(x, i=NULL, j=NULL, value) { # matrix access [i,j] [,j] [i,] # vector access [i] matrixAccess = nargs() > 3 has.j <- !missing(j) if(!is.null(attr(x, "nrow")) & matrixAccess) { ## matrix .Call(matrix_set_at_z, x, value, i,j) } else { ## non-matrix if(has.j) stop("invalid vector subsetting") r <- .Call(biginteger_set_at, x, i, value) attr(r,"nrow") <- attr(x, "nrow") r } } gmp/R/matrixz.R0000644000176200001440000000721014662051405013062 0ustar liggesusersmatrix <- function(data=NA, nrow=1, ncol=1, byrow=FALSE, ...) UseMethod("matrix") matrix.default <- function(...) base::matrix(...) ## ## looks "better", but results wrongly, e.g. matrix(1:6, 3) : ## matrix.default <- function(data = NA, nrow = 1, ncol = 1, byrow = FALSE, ## dimnames = NULL, ...) ## ## here, rightly, any "..." will give an error from base::matrix ## base::matrix(data, nrow=nrow, ncol=ncol, byrow=byrow, ## dimnames=dimnames, ...) matrix.bigz <- function(data=NA, nrow=1, ncol=1, byrow=FALSE, dimnames=NULL, mod=NA, ...) { if(!is.null(dimnames)) warning("'dimnames' are not implemented for this class") .Call(as_matrixz, data, as.integer(nrow), as.integer(ncol), as.integer(byrow), mod) } as.matrix.bigz <- function(x, ...) { if(is.matrix(x) || is.data.frame(x) || length(dim(x)) == 2L) { d <- dim(x) n <- d[1L] p <- d[2L] } else { n <- length(x) p <- 1L } matrix.bigz(x, nrow=n, ncol=p) } as.vector.bigz <- function(x, mode="any") { if(mode == "list") { ## "easy"; TODO: gmpToListZ() withOUT matrix .Call(gmpMatToListZ, matrix.bigz(x, nrow=length(x), ncol=1L), 1L) } else if (mode == "any") { attr(x,"nrow") <- NULL x } else as.vector(as.double(x), mode=mode) } t.bigz <- function(x) .Call(bigint_transposeR, x) ##aperm.bigz <- function(a,perm, resize= TRUE) ## { ## dims <- dim(a) ## if (missing(perm)) ## perm <- c(1,2) ## if(perm[1] > perm[2]) ## ans = .Call("bigint_transposeR", ## a, ## PACKAGE="gmp") ## else ## ans = a ## if(!resize) ## dim(ans) <- dims ## ans ##} ## MM: the attr(*, "nrow") implementation is hack -- not allowing >= 3d arrays ## --==> advertize .dimZQ(), .nrowZQ(), etc instead of the "nrow" attr ##' Is 'x' a "bigz" or "bigq" matrix ##' @return \code{ !is.null(attr(x,"nrow")) } but faster is.matrixZQ <- function(x) .Call(is_matrix_zq, x) ## NB '%/%' in .dimZQ() and .ncolZQ() to "remain" 'integer' .dimZQ <- function(x) {# return NULL for non-array {as standard R} if(is.null(n <- attr(x,"nrow"))) n else c(n, if(n) length(x) %/% n else 0L) } .dimsetZQ <- function(x,value) { attr(x,"nrow") <- if(is.null(value)) { ## dim(m) <- NULL as in standard R: NULL } else { stopifnot(value == (v <- as.integer(value)), v >= 0, prod(v) == length(x)) v[1L] } x } .nrowZQ <- function(x) attr(x,"nrow") .ncolZQ <- function(x) if(is.null(n <- attr(x,"nrow"))) n else if(n) length(x) %/% n else 0L dim.bigz <- .dimZQ dim.bigq <- .dimZQ `dim<-.bigz` <- .dimsetZQ `dim<-.bigq` <- .dimsetZQ ## not usable as S3, as long as ncol(), nrow() are not S3 generic ## FIXME? remove these ... ncol() / nrow() go via dim() anyway! nrow.bigz <- .nrowZQ nrow.bigq <- .nrowZQ ncol.bigz <- .ncolZQ ncol.bigq <- .ncolZQ cbind.bigz <- function(..., deparse.level = 1) { argL <- list(...) if(any(vapply(argL, inherits, NA, what="bigq"))) .Call(bigrational_cbind, argL) else .Call(biginteger_cbind, argL) } rbind.bigz <- function(..., deparse.level = 1) { argL <- list(...) if(any(vapply(argL, inherits, NA, what="bigq"))) .Call(bigrational_rbind, argL) else .Call(biginteger_rbind, argL) } apply <- function(X, MARGIN, FUN, ...) UseMethod("apply") apply.default <- function(X, MARGIN, FUN, ...) base::apply(X, MARGIN, FUN, ...) apply.bigz <- function(X, MARGIN, FUN, ...) { ## change matrix to a list: X <- .Call(gmpMatToListZ, X, as.integer(MARGIN)) ## then use std lapply() and convert back to vector: .Call(biginteger_c, lapply(X, FUN, ...)) } gmp/R/Stirling-n-etc.R0000644000176200001440000002334714662051230014170 0ustar liggesusers###--------- Stirling numbers of 1st and 2nd kind ---- ### ==================================== ### The "double prec" version of this is currently in package 'nacopula' ### (MM: >>> ../../nacopula/R/special-func.R ) ##' Compute Stirling numbers of the 1st kind ##' ##' s(n,k) = (-1)^{n-k} times ##' the number of permutations of 1,2,...,n with exactly k cycles ##' ##' NIST DLMF 26.8 --> http://dlmf.nist.gov/26.8 ##' ##' @title Stirling Numbers of the 1st Kind ##' @param n ##' @param k ##' @return s(n,k) ##' @author Martin Maechler Stirling1 <- function(n,k) { ## NOTA BENE: There's no "direct" method available here stopifnot(length(n) == 1, length(k) == 1) if (k < 0 || n < k) stop("'k' must be in 0..n !") if(n == 0) return(as.bigz(1)) if(k == 0) return(as.bigz(0)) S1 <- function(n,k) { if(k == 0 || n < k) return(as.bigz(0)) if(is.na(S <- St[[n]][k])) { ## s(n,k) = s(n-1,k-1) - (n-1) * s(n-1,k) for all n, k >= 0 St[[n]][[k]] <<- S <- if(n1 <- n-1L) S1(n1, k-1) - n1* S1(n1, k) else as.bigz(1) } S } if(compute <- (nt <- length(St <- .Stirl..env$ S1.tab)) < n) { ## extend the "table": length(St) <- n for(i in (nt+1L):n) St[[i]] <- rep.bigz(NA_bigz_, i) } else compute <- is.na(S <- St[[n]][k]) if(compute) { S <- S1(n,k) ## store it back: .Stirl..env$ S1.tab <- St } S } ##' Full Vector of Stirling Numbers of the 1st Kind ##' ##' @title Stirling1(n,k) for all k = 1..n ##' @param n ##' @return the same as sapply(1:n, Stirling1, n=n) ##' @author Martin Maechler Stirling1.all <- function(n) { stopifnot(length(n) == 1) if(!n) return(as.bigz(numeric(0))) if(.Stirl..env$ S1.full.n < n) { .Stirl..env$ S1.full.n <- n do.call(c, lapply(seq_len(n), Stirling1, n=n))# which fills "S1.tab" } else .Stirl..env$ S1.tab[[n]] } ##' Compute Stirling numbers of the 2nd kind ##' ##' S^{(k)}_n = number of ways of partitioning a set of $n$ elements into $k$ ##' non-empty subsets ##' (Abramowitz/Stegun: 24,1,4 (p. 824-5 ; Table 24.4, p.835) ##' Closed Form : p.824 "C." ##' ##' @title Stirling Numbers of the 2nd Kind ##' @param n ##' @param k ##' @param method ##' @return S(n,k) = S^{(k)}_n ##' @author Martin Maechler, "direct": May 28 1992 Stirling2 <- function(n,k, method = c("lookup.or.store","direct")) { stopifnot(length(n) == 1, length(k) == 1) if (k < 0 || n < k) stop("'k' must be in 0..n !") method <- match.arg(method) switch(method, "direct" = { sig <- rep(c(1,-1)*(-1)^k, length.out= k+1) # 1 for k=0; -1 1 (k=1) k <- 0:k # (!) ga <- factorialZ(k) # = gamma(k+1) sum( sig * k^n /(ga * rev(ga))) }, "lookup.or.store" = { if(n == 0) return(as.bigz(1)) ## else: if(k == 0) return(as.bigz(0)) S2 <- function(n,k) { if(k == 0 || n < k) return(as.bigz(0)) if(is.na(S <- St[[n]][k])) ## S(n,k) = S(n-1,k-1) + k * S(n-1,k) for all n, k >= 0 St[[n]][[k]] <<- S <- if(n1 <- n-1L) S2(n1, k-1) + k* S2(n1, k) else as.bigz(1) ## n = k = 1 S } if(compute <- (nt <- length(St <- .Stirl..env$ S2.tab)) < n) { ## extend the "table": length(St) <- n for(i in (nt+1L):n) St[[i]] <- rep.bigz(NA_bigz_, i) } else compute <- is.na(S <- St[[n]][k]) if(compute) { S <- S2(n,k) ## store it back: .Stirl..env$ S2.tab <- St } S }) } ##' Full Vector of Stirling Numbers of the 2nd Kind ##' ##' @title Stirling2(n,k) for all k = 1..n ##' @param n ##' @return the same as sapply(1:n, Stirling2, n=n) ##' @author Martin Maechler Stirling2.all <- function(n) { stopifnot(length(n) == 1) if(!n) return(as.bigz(numeric(0))) if(.Stirl..env$ S2.full.n < n) { .Stirl..env$ S2.full.n <- n do.call(c, lapply(seq_len(n), Stirling2, n=n))# which fills "S2.tab" } else .Stirl..env$ S2.tab[[n]] } ##' Compute Eulerian numbers (German "Euler Zahlen") A(n,k) ##' ##' A(n,k) = number of permutations of n with exactly k ascents (or k descents) ##' --> http://dlmf.nist.gov/26.14 ##' ##' @title Eulerian Numbers ##' @param n ##' @param k ##' @param method ##' @return A(n,k) = < n \\ k > ##' @author Martin Maechler, April 2011 Eulerian <- function(n,k, method = c("lookup.or.store","direct")) { stopifnot(length(n) == 1, length(k) == 1) if(k < 0 || n < k) stop("'k' must be in 0..n !") if(n && k == n) return(as.bigz(0)) ## have __ 0 <= k < n __ method <- match.arg(method) switch(method, "direct" = { if(k == 0) return(as.bigz(1)) if(k == n) return(as.bigz(0)) ## else 0 <= k < n >= 2 ## http://dlmf.nist.gov/26.14.E9 : A(n,k) = A(n, n-1-k), n >= 1 if(k >= (n+1)%/% 2) k <- n-(k+1L) k1 <- k+1L sig <- rep(c(1,-1), length.out = k1) # 1 for k=0; 1 -1 (k=1), ... sum( sig * chooseZ(n+1, 0:k) * (k1:1L)^n ) }, "lookup.or.store" = { Eul <- function(n,k) { ## Quick return for those that are *not* stored: if(k < 0 || k > n || (0 < n && n == k)) return(as.bigz(0)) if(n == 0) return(as.bigz(1)) ## now -- 0 <= k < n -- are stored if(is.na(r <- E.[[n]][k1 <- k+1L])) ## compute it (via recursion) ## A(n,k) = (k+1)* A(n-1,k) + (n-k)*A(n-1,k-1) for n >= 2, k >= 0 ## http://dlmf.nist.gov/26.14.E8 E.[[n]][[k1]] <<- r <- if(n1 <- n-1L) k1*Eul(n1, k)+ (n-k)* Eul(n1, k-1) else as.bigz(1) ## n=1, k=0 r } if(compute <- (nt <- length(E. <- .Stirl..env$ Eul.tab)) < n) { ## extend the "table": length(E.) <- n for(i in (nt+1L):n) E.[[i]] <- rep.bigz(NA_bigz_, i) } else compute <- is.na(E <- E.[[n]][k+1L]) if(compute) { E <- Eul(n,k) ## store it back: .Stirl..env$ Eul.tab <- E. } E }) } ##' Full Vector of Eulerian Numbers == row of Euler triangle ##' ##' @title Eulerian(n,k) for all k = 0..n-1 ##' @param n ##' @return (for n >= 1), the same as sapply(0:(n-1), Eulerian, n=n) ##' @author Martin Maechler, April 2011 Eulerian.all <- function(n) { stopifnot(length(n) == 1, n >= 0) if(!n) return(as.bigz(1)) if(.Stirl..env$ Eul.full.n < n) { .Stirl..env$ Eul.full.n <- n do.call(c, lapply(0:(n-1L), Eulerian, n=n))# which fills "Eul.tab" } else .Stirl..env$ Eul.tab[[n]] } ## Our environment for tables etc: no hash, as it will contain *few* objects: .Stirl..env <- new.env(parent=emptyenv(), hash=FALSE) assign("S2.tab", list(), envir = .Stirl..env) ## S2.tab[[n]][k] == S(n, k) assign("S1.tab", list(), envir = .Stirl..env) ## S1.tab[[n]][k] == s(n, k) assign("S2.full.n", 0 , envir = .Stirl..env) assign("S1.full.n", 0 , envir = .Stirl..env) assign("Eul.tab", list(), envir = .Stirl..env) ## Eul.tab[[n]][k] == A(n, k) == < n \\ k > (Eulerian) assign("Eul.full.n", 0 , envir = .Stirl..env) ## Bernoulli numbers (have also in 'Rmpfr' via zeta(), but they *are* rational after all!) .Bernl..env <- new.env(parent=emptyenv(), hash=FALSE) ## Want .Bernl..env$B[n] == B_{2n}, n = 1,2,... ## ==> not storing BernoulliQ(0) = 1, nor BernoulliQ(1) = +1/2 B1 <- function(n) { # stopifnot( length(n) == 1 ) half <- as.bigq(1L, 2L) if(n == 0L) as.bigq(1L) else if(n == 1L) ## B_1 = + 1/2 ("B_n+"; -1/2 according to "old" B_n- definition) half else if(n %% 2 == 1L) as.bigq(0L) else { ## n in {2, 4, 6, ..}: n2 <- n %/% 2L if((lB <- length(B <- .Bernl..env$B)) < n2) { ## compute Bernoulli(n) ## if(verbose) cat("n=",n,": computing from ", lB+1L, sep='', "\n") if(!lB) B <- as.bigq(1L, 6L) # B_2 = 1/6 ## n2 >= 2; n >= 4 length(B) <- n2 # (fills missing parts with NA_bigq_ ## recurse: if(lB+1L < n2) for(k in (lB+1L):(n2-1L)) B[k] <- B1(2*k) k0 <- seq_len(n2-1L) # (1, 2, .., n2-1) B. <- half - (1 + sum( chooseZ(n+1L, k0+k0) * B[k0])) / (n+1L) B[n2] <- B. .Bernl..env$B <- B B. } else B[n2] } }# end B1() BernoulliQ <- function(n, verbose = getOption("verbose", FALSE)) { if(!(N <- length(n))) return(as.bigq(n)) # else: length(n) >= 1 : stopifnot(n >= 0, n == as.integer(n)) if(N == 1L) B1(n) else .Call(bigrational_c, lapply(n, B1)) } ## rational dbinom() probabilities dbinomQ <- function(x, size, prob, log=FALSE) { if(log) stop("'log=TRUE' not allowed; use log(mpfr(dbinomQ(..), precB))") if(!is.bigq(prob)) { warning("Calling 'as.bigq(prob)'; rather provide exact bigrational yourself") prob <- as.bigq(prob) } if(!is.bigz(x)) x <- as.bigz(x) if(!is.bigz(size)) size <- as.bigz(size) chooseZ(size,x) * prob^x * (1 - prob)^(size - x) } ## rational pbinom() probabilities pbinomQ <- function(q, size, prob, lower.tail = TRUE, log.p = FALSE) { if(log) stop("'log.p=TRUE' not allowed; use log(mpfr(pbinomQ(..), precB))") if(!is.bigq(prob)) { warning("Calling 'as.bigq(prob)'; rather provide exact bigrational yourself") prob <- as.bigq(prob) } if(!is.bigz(q)) q <- as.bigz(q) if(!is.bigz(size)) size <- as.bigz(size) ## FIXME need to vectorize in 'q' sum(dbinomZ(....)) .NotYetImplemented() ## FIXME 2 if(!lower.tail) .NotYetImplemented() chooseZ(size,q) * prob^q * (1 - prob)^(size - q) } gmp/R/matrix-prods.R0000644000176200001440000001041514444267422014024 0ustar liggesusersif(FALSE) {## a nice idea --- but not working: setOldClass() is fine, ## but then dispatch here only works if you create new("bigz",...) objects ## (though dispatch *does* work for asNumeric(.) -- really just R bug ??? ## see also 'if(FALSE)' in ./bigq.R ## NOTE: %*% is an S4, but *not* an S3 generic ==> Let's use S4 methods here setMethod("%*%", signature(x = "bigz", y = "bigz"), function(x,y) .Call(matrix_mul_z, x, y, 0L)) setMethod("%*%", signature(x = "bigz", y = "ANY"), function(x,y) .Call(matrix_mul_z, x, y, 0L)) setMethod("%*%", signature(x = "ANY", y = "bigz"), function(x,y) .Call(matrix_mul_z, x, y, 0L)) setMethod("crossprod", signature(x = "bigz", y = "bigz"), function(x,y) .NotYetImplemented()) setMethod("crossprod", signature(x = "bigz", y = "ANY"), function(x,y) .NotYetImplemented()) setMethod("crossprod", signature(x = "ANY", y = "bigz"), function(x,y) .NotYetImplemented()) setMethod("tcrossprod", signature(x = "bigz", y = "bigz"), function(x,y) .NotYetImplemented()) setMethod("tcrossprod", signature(x = "bigz", y = "ANY"), function(x,y) .NotYetImplemented()) setMethod("tcrossprod", signature(x = "ANY", y = "bigz"), function(x,y) .NotYetImplemented()) setMethod("%*%", signature(x = "bigq", y = "bigq"), function(x,y) .Call(matrix_mul_q, x, y, 0L)) setMethod("%*%", signature(x = "bigq", y = "ANY"), function(x,y) .Call(matrix_mul_q, x, y, 0L)) setMethod("%*%", signature(x = "ANY", y = "bigq"), function(x,y) .Call(matrix_mul_q, x, y, 0L)) setMethod("crossprod", signature(x = "bigq", y = "bigq"), function(x,y) .NotYetImplemented()) setMethod("crossprod", signature(x = "bigq", y = "ANY"), function(x,y) .NotYetImplemented()) setMethod("crossprod", signature(x = "ANY", y = "bigq"), function(x,y) .NotYetImplemented()) setMethod("tcrossprod", signature(x = "bigq", y = "bigq"), function(x,y) .NotYetImplemented()) setMethod("tcrossprod", signature(x = "bigq", y = "ANY"), function(x,y) .NotYetImplemented()) setMethod("tcrossprod", signature(x = "ANY", y = "bigq"), function(x,y) .NotYetImplemented()) } else { ## less nice -- S3-only -- way: -------------------------------------------- `%*%` <- function(x,y) UseMethod("%*%") `%*%.default` <- function(x,y) { ## dispatch on y (!) if(inherits(y, "bigz")) .Call(matrix_mul_z, x, y, 0L) else if(inherits(y, "bigq")) .Call(matrix_mul_q, x, y, 0L) else base::"%*%"(x,y) } ## matrix_mul_z (SEXP a, SEXP b, SEXP right, SEXP trans) ## right if(right), compute b %*% T(a) , else T(a) %*% b ## trans if(trans), T(a) := t(a) = a', else T(a) := a `%*%.bigz` <- function(x,y) .Call(matrix_mul_z, x, y, 0L) `%*%.bigq` <- function(x,y) .Call(matrix_mul_q, x, y, 0L) crossprod <- function(x,y=NULL, ...) UseMethod("crossprod") tcrossprod <- function(x,y=NULL, ...) UseMethod("tcrossprod") crossprod.default <- function(x,y=NULL, ...) { if(is.null(y)) return(base::crossprod(x)) if(inherits(y, "bigz")) .Call(matrix_mul_z, x, y, 1L) else if(inherits(y, "bigq")) .Call(matrix_mul_q, x, y, 1L) else base::crossprod(x,y) } crossprod.bigz <- function(x,y=NULL, ...) { if(is.null(y)) .Call(matrix_crossp_z, x, FALSE) else if(inherits(y, "bigq")) .Call(matrix_mul_q, x, y, 1L) else .Call(matrix_mul_z, x, y, 1L) } crossprod.bigq <- function(x,y=NULL, ...) { if(is.null(y)) .Call(matrix_crossp_q, x, FALSE) else .Call(matrix_mul_q, x, y, 1L) } ##----------------------------------------------- tcrossprod.default <- function(x,y=NULL, ...) { if(is.null(y)) return(base::tcrossprod(x)) if(inherits(y, "bigz")) .Call(matrix_mul_z, x, y, 2L) else if(inherits(y, "bigq")) .Call(matrix_mul_q, x, y, 2L) else base::tcrossprod(x,y) } tcrossprod.bigz <- function(x,y=NULL, ...) { if(is.null(y)) .Call(matrix_crossp_z, x, TRUE) else if(inherits(y, "bigq")) .Call(matrix_mul_q, x, y, 2L) else .Call(matrix_mul_z, x, y, 2L) } tcrossprod.bigq <- function(x,y=NULL, ...) { if(is.null(y)) .Call(matrix_crossp_q, x, TRUE) else .Call(matrix_mul_q, x, y, 2L) } }# end{S3-way} gmp/cleanup0000755000176200001440000000020714662142527012422 0ustar liggesusers#!/bin/sh rm -f ./config.* rm -f src/Makevars rm -f src/Makedeps rm -f src/gmp_res.rc rm -f src/*.o rm -f src/.so rm -f src/*.d gmp/data/0000755000176200001440000000000014444267422011757 5ustar liggesusersgmp/data/Oakley2.R0000644000176200001440000000077714444267422013423 0ustar liggesusers# RFC 2409 Diffie Hellman Key Exchange Groups (standardized generators and primes) Oakley2 <- NULL if(requireNamespace("gmp", quietly = TRUE)) Oakley2 <- gmp::as.bigz(2,"0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF") else warning("Data for RFC 2409 Oakley groups requires package 'gmp'") gmp/data/Oakley1.R0000644000176200001440000000067614444267422013420 0ustar liggesusers# RFC 2409 Diffie Hellman Key Exchange Groups (standardized generators and primes) Oakley1 <- NULL if(requireNamespace("gmp", quietly=TRUE)) Oakley1 <- gmp::as.bigz(2, "0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A63A3620FFFFFFFFFFFFFFFF") else warning("Data for RFC 2409 Oakley groups requires package 'gmp'") gmp/src/0000755000176200001440000000000014662142527011635 5ustar liggesusersgmp/src/bigrational.h0000644000176200001440000001507214444267421014305 0ustar liggesusers/*! \file bigrational.h * \brief Description of class bigrational * * \date Created: 22/05/06 * \date Last modified: Time-stamp: <2023-01-24 18:42:58 (antoine)> * * \author Antoine Lucas (adapted from biginteger class made by * Immanuel Scholz) * * \note Licence: GPL (>= 2) */ #ifndef BIGRATIONAL_HEADER_ #define BIGRATIONAL_HEADER_ 1 #include #include "biginteger.h" /** * \brief Class for rational value. * * A big rational. Actually a wrapper for mpq_t to work with plus * some special stuff. * * The bigrational special state "NA" means, no value is assigned. * This does not mean, the internal state is not constructed, but * the value explicit is "not available". */ class bigrational { private: /** * The rational = n/d . */ mpq_t value ; /** * \brief a flag: true => NA value. */ bool na; public: /** * Construct a "NA" bigrational. */ bigrational(); /** * Construct a bigrational from a raw expression. * in fact in raw: we will store an mpz_export of * either numerator, or denominator */ bigrational(void* raw); /** * Create a bigrational from a value. Remember to free the * parameter's mpz_t if you allocated them by yourself - * biginteger will copy the value. */ bigrational(const mpq_t& value_); /** * \brief create a rational from an [big] integer */ bigrational(const mpz_t& value_); /** * Construct a bigrational from a long value. */ bigrational(int value_); /** * Construct a bigrational from a long value. */ bigrational(int num_, int den_); /** * Construct a bigrational from a double value. */ bigrational(double value_); /** * Construct a bigrational from a string value. it can be "4343" or "2322/4343" */ bigrational(const std::string& value_); /** * Copy constructor (mpz_t aren't standard-copyable) */ bigrational(const biginteger & rhs) ; /** * Copy constructor (mpz_t aren't standard-copyable) */ bigrational(const bigrational & rhs); /** * Free the owned mpz_t structs */ virtual ~bigrational(); /** \brief overload affectation operator * */ bigrational & operator= (const bigrational& rhs); /** * Set the bigrational to state "NA". */ void setValue() {mpq_set_si(value, 0,1); na = true;} /** * Set the bigrational to a specific value. */ void setValue(const mpq_t value_ ) { mpq_set(value, value_); na = false; } /** \brief Set Denominator: return value = value / value_ */ void setDenValue(const mpq_t value_ ) { if(!na) mpq_div(value,value, value_); } /** * \brief set value from integer */ void setValue(int value_) { if(value_ == NA_INTEGER) {mpq_set_ui(value, 0,1); na = true ;} else { mpq_set_si(value, value_,1); na = false; } } /** \brief set value from unsigned int */ void setValue(unsigned long int value_) { if((int)value_ == NA_INTEGER) {mpq_set_ui(value, 0,1); na = true ;} else {mpq_set_ui(value, value_,1); na = false;} } /** \brief set value from float (double) */ void setValue(double value_) { if( R_FINITE (value_ ) ) {mpq_set_d(value, value_); na = false;} else {mpq_set_ui(value, 0,1); na = true ;} } /** * \brief set value from big integer */ void setValue(const mpz_t & value_) { mpq_set_z(value,value_); na = false; } /** * \brief set value from biginteger value */ void setValue(const biginteger & value_) { mpq_set_z(value,value_.getValueTemp()); na = value_.isNA(); } /** * \brief set value from biginteger value */ void setValue(const bigrational & value_) { mpq_set(value,value_.getValueTemp()); na = value_.isNA(); } /** * For const-purposes, return the value. Remember, that the return value * only lives as long as this class live, so do not call getValueTemp on * temporary objects. */ const mpq_t& getValueTemp() const {return value;} /** * Return true, if the value is NA. */ bool isNA() const {return na;} /** * set NA value */ void NA(bool value_p) {na = value_p;} /** * Return 1, if the value is > 0; -1 when negative, 0 when 0. */ int sgn() const {return mpq_sgn(value);} /** * Convert the bigrational into a standard string. */ std::string str(int b) const; /** * \brief Convert the bigrational into a double value * (you may loose precision) */ double as_double() const {return mpq_get_d(value);} /** * Convert the bigrational to a raw memory block. Obtain the size needed * from biginteger_raw_size() first and make sure, the buffer provided is * large enough to hold the data. * * Also remember, that the modulus is not saved this way. To obtain a * modulus raw byte use get_modulus().as_raw(void*). * * @return number of bytes used (same as raw_size()) */ // int as_raw(void* raw) const; /** * Return the number of bytes needed to store the numerator only in a * continous memory block. */ size_t raw_size() const; /** \brief simplify n/d (use of mpq_canonical) * */ void simplify (); /** * \brief return 1/x */ bigrational inv(); }; /** \brief mpq struct. * * Use this to clear mpq_t structs at end-of-function automatically */ struct mpq_t_sentry { /** the bigrational */ mpq_t& value; /** initialisation */ mpq_t_sentry(mpq_t& v): value(v) {} /** free all */ ~mpq_t_sentry() { mpq_clear(value); } }; /** * \brief set denominator to a bigrational (in fact divide * bigrational by value m. */ bigrational set_denominator(const bigrational& x, const bigrational& m); /** * \brief Add two bigrationals together. * */ bigrational operator+(const bigrational& rhs, const bigrational& lhs); /** * \brief Subtract two bigrationals. */ bigrational operator-(const bigrational& rhs, const bigrational& lhs); /** * \brief Multiply two bigrationals. */ bigrational operator*(const bigrational& rhs, const bigrational& lhs); /** *\brief Divide two bigrationals. */ bigrational operator/(const bigrational& rhs, const bigrational& lhs); /** *\brief x^y = pow(x,y) : bigrational ^ biginteger */ bigrational operator^(const bigrational& rhs, const biginteger& lhs); /** \brief comparison operator */ bool operator> (const bigrational& rhs, const bigrational& lhs); /** \brief comparison operator */ bool operator< (const bigrational& rhs, const bigrational& lhs); /** \brief comparison operator */ bool operator!= (const bigrational& rhs, const bigrational& lhs); #endif gmp/src/matrix.h0000644000176200001440000000250014444267422013307 0ustar liggesusers/*! \file matrix.h * \brief C++ function to add matrix support * * \version 1 * * \date Created: 25/05/06 * \date Last modified: Time-stamp: <2022-12-09 14:56:06 (antoine)> * * \author A. Lucas * * \note * as usually, matrix x[i,j] (n x p) is represented by a vector * x[i + j x n] (i=0..n-1 ; j=0..p-1) * * \note Licence: GPL (>= 2) */ #ifndef MATRIXZ_HEADER_ #define MATRIXZ_HEADER_ 1 extern "C" { /** \brief is x a bigz or bigz matrix ? */ SEXP is_matrix_zq(SEXP x); /** * \brief build a matrix x with dimensions p&q byrow: 0 or 1 */ SEXP as_matrixz(SEXP x, SEXP p, SEXP q, SEXP byrow, SEXP mod); /** * \brief transpose a "matrix" n x p into the transpose p x n */ SEXP bigint_transposeR(SEXP x); /** \brief matrix cross product */ SEXP matrix_crossp_z (SEXP a, SEXP trans); /** \brief matrix multiplication */ SEXP matrix_mul_z (SEXP a, SEXP b, SEXP op); /** \brief for function rbind */ SEXP biginteger_rbind(SEXP args) ; /** \brief for function rbind */ SEXP biginteger_cbind(SEXP args) ; } /** \brief C functions for matrix */ namespace matrixz{ /** \brief C function use to transpose a matrix */ bigvec bigint_transpose ( bigvec & mat); /** \brief Check dimension compatibility */ int checkDims(int dima,int dimb); } #endif gmp/src/solve.h0000644000176200001440000000354714446557440013153 0ustar liggesusers/*! \file solve.h * \brief functions to solve matrix * * \version 1 * * \date Created: 25/05/06 * \date Last modified: $Date: 2012-01-12 17:46:59 $ * * \author A. Lucas * * \note * as usually, matrix x[i,j] (n x p) is represented by a vector * x[i + j x n] (i=0..n-1 ; j=0..p-1) * * \note Licence: GPL (>= 2) */ #ifndef SOLVE_HEADER_GMP_R_ #define SOLVE_HEADER_GMP_R_ 1 #include #include #include #include "bigvec_q.h" extern "C" { /** \brief inverse a rational matrix */ SEXP inverse_q(SEXP A); /** \brief solve matrix system AX=B */ SEXP solve_q(SEXP A,SEXP B); /** \brief inverse a matrix in Z/nZ */ SEXP inverse_z(SEXP A); /** \brief solve matrix system AX=B in Z/nZ*/ SEXP solve_z(SEXP A,SEXP B); } namespace solve_gmp_R { /** \brief solve matrix * * solve A X = B (return X) with A & B matrix (of rational or biginteger) * * A is of dimension nxn X nxm and B nxm (X will be return a B address) * We use the Gauss algorithm */ template< class T> void solve (math::Matrix & A , math::Matrix & B) { // A [ i ,j] = A[ i + j * A.nrow] for(unsigned int k = 0 ; k < A.nRows(); ++k) { if(A.get(k, k).sgn() == 0 ){ A.clear(); B.clear(); throw std::invalid_argument("System is singular"); } // l_k <- (1/akk) l_k T tmpValeur =A.get(k , k).inv() ; A.mulLine(k,tmpValeur); B.mulLine(k,tmpValeur); for(unsigned int i = 0; i < A.nRows(); ++i) { if(i == k) continue; // l_i <- l_i - a_ik l_k tmpValeur= A.get(i, k) ; A.subLine(i,k, tmpValeur) ; B.subLine(i,k, tmpValeur) ; } } } /** \brief inverse a rational matrix * */ SEXP inverse_q(bigvec_q A); /** \brief solve matrix equation AX = B */ SEXP solve_q(bigvec_q A,bigvec_q B); } #endif gmp/src/Makevars.win0000644000176200001440000000002514444267421014121 0ustar liggesusers PKG_LIBS = -lgmp gmp/src/biginteger.h0000644000176200001440000001513114444267421014125 0ustar liggesusers/*! \file biginteger.h * \brief Description of class biginteger * * \date Created: 2004 * \date Last modified: Time-stamp: <2023-01-28 15:50:33 (antoine)> * * \author Immanuel Scholz * * \note Licence: GPL (>= 2) */ #ifndef biginteger_HEADER #define biginteger_HEADER 1 #include #include #include "Rgmp.h" /** \mainpage Gmp package for R language. * * Theses pages made to help developpers to enter into the C++ code related to * the gmp package. * * \section sec_intro Introduction * * The gmp R package uses directly the gmp C/C++ library (http://gmplib.org) * to provide powerful computation of big integers and rational within R. * This package is more than a simple wrapper as it allows to handle * - easy computation in Z/nZ (it is an option of bigz class) * - matrix computation * */ /** \brief mpz struct * * Use this to clear mpz_t structs at end-of-function automatically */ struct mpz_t_sentry { /** \brief value */ mpz_t& value; /** \brief constructor */ mpz_t_sentry(mpz_t& v): value(v) {} /** \brief detructor (and clear mpz) */ ~mpz_t_sentry() {mpz_clear(value);} }; /** \brief Class biginteger * * A big integer. Actually a wrapper for mpz_t to work with plus * some special stuff. * * The biginteger special state "NA" means, no value is assigned. * This does not mean, the internal state is not constructed, but * the value explicit is "not available". */ class biginteger { private: /** * The actual integer value. */ mpz_t value; /** * True, if the value is "NA". */ bool na; public: /** * Construct a "NA" biginteger. */ biginteger() ; /** * Construct a biginteger from a raw expression. */ biginteger(const char* raw); /** * Create a biginteger from a value. Remember to free the * parameter's mpz_t if you allocated them by yourself - * biginteger will copy the value. */ biginteger(const mpz_t value_); /** * Construct a biginteger from a int value. */ biginteger(const int value_); /** * Construct a biginteger from a long value. */ biginteger(const long int value_); /** * Construct a biginteger from a unsigned long value. */ biginteger(const unsigned long int value_); /** * Construct a biginteger from a double value. */ biginteger(const double value_); /** * Construct a biginteger from a string value. */ biginteger(const std::string& value_); /** * Copy constructor (mpz_t aren't standard-copyable) */ biginteger(const biginteger& rhs) ; /** * Free the owned mpz_t structs */ virtual ~biginteger(); /** * Set the biginteger to state "NA". */ inline void setValue() {mpz_set_si(value, 0); na = true;} /** * Set the biginteger to a specific value. */ inline void setValue(const mpz_t & value_ ) { mpz_set(value, value_); na = false; } /** \brief set value from an integer */ inline void setValue(int value_) { if(value_ == NA_INTEGER) {mpz_set_ui(value, 0); na = true ;} else { mpz_set_si(value, value_); na = false; } } /** \brief set value from a long integer */ inline void setValue(long int value_) { if(value_ == NA_INTEGER) {mpz_set_ui(value, 0); na = true ;} else { mpz_set_si(value, value_); na = false; } } /** \brief set value from an unsigned int */ inline void setValue(unsigned long int value_) { if((int)value_ == NA_INTEGER) {mpz_set_ui(value, 0); na = true ;} else { mpz_set_ui(value, value_); na = false; } } /** \brief set value from a float */ inline void setValue(double value_) { if(R_FINITE (value_) ) {mpz_set_d(value, value_); na = false;} else {mpz_set_ui(value, 0); na = true ;} } /** \brief set value from a biginteger */ void setValue(const biginteger & value_) { setValue(value_.getValueTemp()); na = value_.isNA(); } /** * For const-purposes, return the value. Remember, that the return value * only lives as long as this class live, so do not call getValueTemp on * temporary objects. */ inline const mpz_t& getValueTemp() const {return value;} /** \brief accessor on value */ inline mpz_t & getValue() { return value; } /** * Return true, if the value is NA. */ inline bool isNA() const {return na;} /** * set NA value */ inline void NA(bool value_p) {na = value_p;} /** * Return true, if the value is 0. */ inline int sgn() const {return mpz_sgn(value);} /** * Convert the biginteger into a standard string. */ std::string str(int b) const; /** * Convert the biginteger into a long value (cut off the msb's if it don't * fit). */ inline long as_long() const {return mpz_get_si(value);} /** * \brief Convert the biginteger into a double value * (you may loose precision) */ inline double as_double() const {return mpz_get_d(value);} /** * Convert the biginteger to a raw memory block. Obtain the size needed * from biginteger_raw_size() first and make sure, the buffer provided is * large enough to hold the data. * * Also remember, that the modulus is not saved this way. To obtain a * modulus raw byte use get_modulus().as_raw(void*). * * @return number of bytes used (same as raw_size()) */ int as_raw(char* raw) const; /** * Return the number of bytes needed to store this biginteger in a * continous memory block. */ size_t raw_size() const; /** * Swap values with the argument */ void swap(biginteger& other); /** * Test prime numbers */ int isprime(int reps) const {return mpz_probab_prime_p(value,reps);} /** \brief overload affectation operator */ biginteger & operator= (const biginteger& rhs); static int getCount(); }; /** \brief comparison operator */ bool operator!= (const biginteger& rhs, const biginteger& lhs); inline bool operator== (const biginteger& rhs, const biginteger& lhs){ return !(rhs != lhs); } /** \brief comparison operator */ bool operator> (const biginteger& rhs, const biginteger& lhs); /** \brief comparison operator */ bool operator< (const biginteger& rhs, const biginteger& lhs); /** \brief standard operator */ biginteger operator* (const biginteger& rhs, const biginteger& lhs); /** \brief standard operator */ biginteger operator- (const biginteger& rhs, const biginteger& lhs); /** \brief standard operator */ biginteger operator% (const biginteger& rhs, const biginteger& lhs); /** \brief function used by rational that should export * mpz value */ int as_raw(char* raw,mpz_t value,bool na); #endif gmp/src/factor.h0000644000176200001440000000175314444267422013272 0ustar liggesusers/*! \file factor.h * \brief header for factor functions set * * \version 1 * * \date Created: 2005 * \date Last modified: Time-stamp: <2008-02-17 21:41:29 antoine> * * * \note Licence: GPL (>= 2) */ #ifndef GMP_R_FACTOR_HEADER_ #define GMP_R_FACTOR_HEADER_ 1 #include "bigintegerR.h" extern "C" { /** * \brief function that gets values from R and send to functions * factor */ SEXP factorR (SEXP n); } /** \brief Function ued to test factorization with small numbers */ void factor_using_division (mpz_t t, unsigned int limit, bigvec & result) ; /** \brief Function used for factorization */ void factor_using_division_2kp (mpz_t t, unsigned int limit, unsigned long p, bigvec & result) ; /** \brief Pollard Rho method for factorization */ void factor_using_pollard_rho (mpz_t n, int a_int, unsigned long p, bigvec & result); /** \brief Function that call an algorithm for factorization */ void factor (mpz_t t, unsigned long p, bigvec & result); #endif gmp/src/init.cc0000644000176200001440000000764014446557376013132 0ustar liggesusers// This ensures registration -- see also useDynLib(...) in ../NAMESPACE #include "bigintegerR.h" #include #include // include those that have an extern "C" { .... } : #include "apply.h" #include "bigrationalR.h" // #include "extract_matrix.h" #include "factor.h" #include "matrix.h" #include "matrixq.h" #include "solve.h" #include #define CALLDEF(name, n) {#name, (DL_FUNC) &name, n} static R_CallMethodDef CallEntries[] = { // apply.h : CALLDEF(gmpMatToListZ, 2), CALLDEF(gmpMatToListQ, 2), // bigintegerR.h : CALLDEF(R_gmp_get_version, 0), CALLDEF(biginteger_add, 2), CALLDEF(biginteger_sub, 2), CALLDEF(biginteger_mul, 2), CALLDEF(biginteger_div, 2), CALLDEF(biginteger_divq, 2), CALLDEF(biginteger_mod, 2), CALLDEF(biginteger_pow, 2), CALLDEF(biginteger_inv, 2), CALLDEF(biginteger_gcd, 2), CALLDEF(biginteger_lcm, 2), // CALLDEF(biginteger_setmod, 2), CALLDEF(biginteger_get_at, 2), CALLDEF(biginteger_set_at, 3), CALLDEF(biginteger_as, 2), CALLDEF(biginteger_as_character, 2), CALLDEF(biginteger_as_numeric, 1), CALLDEF(biginteger_as_integer, 1), CALLDEF(biginteger_length, 1), CALLDEF(biginteger_setlength, 2), CALLDEF(biginteger_is_na, 1), CALLDEF(biginteger_sgn, 1), CALLDEF(biginteger_lt, 2), CALLDEF(biginteger_gt, 2), CALLDEF(biginteger_lte, 2), CALLDEF(biginteger_gte, 2), CALLDEF(biginteger_eq, 2), CALLDEF(biginteger_neq, 2), CALLDEF(biginteger_c, 1), CALLDEF(biginteger_cbind, 1), CALLDEF(biginteger_rep, 2), CALLDEF(biginteger_is_prime, 2), CALLDEF(biginteger_nextprime, 1), CALLDEF(biginteger_abs, 1), CALLDEF(biginteger_gcdex, 2), CALLDEF(biginteger_rand_u, 4), CALLDEF(biginteger_sizeinbase, 2), CALLDEF(bigI_frexp, 1), CALLDEF(bigI_choose, 2), CALLDEF(bigI_factorial, 1), CALLDEF(bigI_fibnum, 1), CALLDEF(bigI_fibnum2, 1), CALLDEF(bigI_lucnum, 1), CALLDEF(bigI_lucnum2, 1), CALLDEF(biginteger_max, 2), CALLDEF(biginteger_min, 2), CALLDEF(biginteger_cumsum, 1), CALLDEF(biginteger_sum, 1), CALLDEF(biginteger_prod, 1), CALLDEF(biginteger_powm, 3), CALLDEF(biginteger_log2, 1), CALLDEF(biginteger_log, 1), // bigrationalR.h: CALLDEF(bigrational_add, 2), CALLDEF(bigrational_sub, 2), CALLDEF(bigrational_mul, 2), CALLDEF(bigrational_div, 2), CALLDEF(bigrational_pow, 2), CALLDEF(bigrational_num, 1), CALLDEF(bigrational_den, 1), CALLDEF(bigrational_get_at, 2), CALLDEF(bigrational_set_at, 3), CALLDEF(bigrational_as, 2), CALLDEF(bigrational_as_character, 2), CALLDEF(bigrational_as_numeric, 1), CALLDEF(bigrational_length, 1), CALLDEF(bigrational_setlength, 2), CALLDEF(bigrational_is_na, 1), CALLDEF(bigrational_is_int, 1), CALLDEF(bigrational_lt, 2), CALLDEF(bigrational_gt, 2), CALLDEF(bigrational_lte, 2), CALLDEF(bigrational_gte, 2), CALLDEF(bigrational_eq, 2), CALLDEF(bigrational_neq, 2), CALLDEF(bigrational_c, 1), CALLDEF(bigrational_cbind, 1), CALLDEF(bigrational_rep, 2), CALLDEF(bigrational_max, 2), CALLDEF(bigrational_min, 2), CALLDEF(bigrational_cumsum, 1), CALLDEF(bigrational_sum, 1), CALLDEF(bigrational_prod, 1), // extract_matrix.h : CALLDEF(matrix_get_at_z, 3), CALLDEF(matrix_set_at_z, 4), CALLDEF(matrix_get_at_q, 3), CALLDEF(matrix_set_at_q, 4), // factor.h : CALLDEF(factorR, 1), // matrix.h : CALLDEF(is_matrix_zq, 1), CALLDEF(as_matrixz, 5), CALLDEF(bigint_transposeR, 1), CALLDEF(matrix_crossp_z, 2), CALLDEF(matrix_mul_z, 3), CALLDEF(biginteger_rbind, 1), // matrixq.h : CALLDEF(as_matrixq, 5), CALLDEF(bigq_transposeR, 1), CALLDEF(matrix_crossp_q, 2), CALLDEF(matrix_mul_q, 3), CALLDEF(bigrational_rbind, 1), // solve.h : CALLDEF(inverse_q, 1), CALLDEF(solve_q, 2), CALLDEF(inverse_z, 1), CALLDEF(solve_z, 2), {NULL, NULL, 0} }; extern "C" void R_init_gmp(DllInfo *dll) { R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); R_useDynamicSymbols(dll, (Rboolean)FALSE); } gmp/src/bigvec_q.cc0000644000176200001440000000406514444267422013730 0ustar liggesusers#include "bigvec_q.h" bigvec_q::bigvec_q(const bigvec_q & rhs): value(rhs.value.size()), nrow(0) { *this = rhs; } bigvec_q::bigvec_q(const bigvec & rhs): value(rhs.size()), nrow(rhs.nrow) { for(unsigned int i=0; i< rhs.size(); ++i) { value[i].setValue(rhs[i].getValue()); } } bigvec_q::~bigvec_q(){ value.clear(); } bigvec_q & bigvec_q::operator= (const bigvec_q & rhs) { if(this != &rhs) { nrow = rhs.nrow; value.resize(rhs.value.size()); std::vector::iterator it = value.begin(); std::vector::const_iterator jt = rhs.value.begin(); while(it != value.end()) { *it = *jt; ++it; ++jt; } } return(*this); } const bigrational & bigvec_q::operator[] (unsigned int i) const { return(value[i]); } bigrational & bigvec_q::operator[] (unsigned int i) { return(value[i]); } bigrational & bigvec_q::get(unsigned int row, unsigned int col) { bigrational & val = (*this)[row + col*nRows()]; return val; } void bigvec_q::set(unsigned int row, unsigned int col, const bigrational & val) { set( row + col*nRows(),val); } void bigvec_q::set(unsigned int i,const bigrational & val) { value[i] = val; } void bigvec_q::set(unsigned int i,const mpq_t & val) { if(i>=value.size()) { Rprintf("ERROR at bigvec_q_set_mpq __LINE__ \n"); return; } value[i].setValue(val); } void bigvec_q::push_back(const bigrational &i) { value.push_back(i); } unsigned int bigvec_q::size() const { return(value.size()); } unsigned int bigvec_q::nRows() const { return abs(nrow); } void bigvec_q::resize(unsigned int n) { value.resize(n); } void bigvec_q::clear() { value.clear(); nrow=0; } // never used void bigvec_q::print() { if(nrow>0) { for(int i=0; i < nrow; ++i) { for(unsigned int j=0; j < (value.size() / nrow); ++j) Rprintf("%s\t", value[i+j* nrow].str(10).c_str() ); Rprintf("\n"); } } else { for(unsigned int i=0; i < value.size(); ++i) Rprintf("%s\t", value[i].str(10).c_str() ); Rprintf("\n"); } } gmp/src/factorize.cc0000644000176200001440000001345014447026347014137 0ustar liggesusers/* Factoring with Pollard's rho method. Copyright 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2009, 2012 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. */ #include #include #include // This is needed as cinttypes is C++11 #include #include #include "factorize.h" static unsigned char primes_diff[] = { #define P(a,b,c) a, #include "primes.h" #undef P }; #define PRIMES_PTAB_ENTRIES (sizeof(primes_diff) / sizeof(primes_diff[0])) int flag_verbose = 0; /* Prove primality or run probabilistic tests. */ int flag_prove_primality = 1; /* Number of Miller-Rabin tests to run when not proving primality. */ #define MR_REPS 25 void factor_using_division (mpz_t t, bigvec & factors) { mpz_t q; unsigned long int p; mpz_init (q); p = mpz_scan1 (t, 0); mpz_div_2exp (t, t, p); while (p) { factors.push_back(2); --p; } p = 3; for (unsigned int i = 1; i <= PRIMES_PTAB_ENTRIES;) { if (! mpz_divisible_ui_p (t, p)) { if (i < PRIMES_PTAB_ENTRIES) { p += primes_diff[i++]; if (mpz_cmp_ui (t, p * p) < 0) break; } else break; } else { mpz_tdiv_q_ui (t, t, p); factors.push_back( p); } } mpz_clear (q); } static int mp_millerrabin (mpz_srcptr n, mpz_srcptr nm1, mpz_ptr x, mpz_ptr y, mpz_srcptr q, unsigned long int k) { unsigned long int i; mpz_powm (y, x, q, n); if (mpz_cmp_ui (y, 1) == 0 || mpz_cmp (y, nm1) == 0) return 1; for (i = 1; i < k; i++) { mpz_powm_ui (y, y, 2, n); if (mpz_cmp (y, nm1) == 0) return 1; if (mpz_cmp_ui (y, 1) == 0) return 0; } return 0; } int mp_prime_p (mpz_t n) { int k, is_prime; mpz_t q, a, nm1, tmp; bigvec factors; if (mpz_cmp_ui (n, 1) <= 0) return 0; /* We have already casted out small primes. */ if (mpz_cmp_ui (n, (long) FIRST_OMITTED_PRIME * FIRST_OMITTED_PRIME) < 0) return 1; mpz_init (q); mpz_init(a); mpz_init( nm1); mpz_init(tmp); /* Precomputation for Miller-Rabin. */ mpz_sub_ui (nm1, n, 1); /* Find q and k, where q is odd and n = 1 + 2**k * q. */ k = mpz_scan1 (nm1, 0); mpz_tdiv_q_2exp (q, nm1, k); mpz_set_ui (a, 2); /* Perform a Miller-Rabin test, finds most composites quickly. */ if (!mp_millerrabin (n, nm1, a, tmp, q, k)) { is_prime = 0; goto ret2; } if (flag_prove_primality) { /* Factor n-1 for Lucas. */ mpz_set (tmp, nm1); factor (tmp, factors); } /* Loop until Lucas proves our number prime, or Miller-Rabin proves our number composite. */ for (unsigned int r = 0; r < PRIMES_PTAB_ENTRIES; r++) { if (flag_prove_primality) { is_prime = 1; for (unsigned int i = 0; i < factors.size() && is_prime; i++) { mpz_divexact (tmp, nm1, factors[i].getValue().getValue()); mpz_powm (tmp, a, tmp, n); is_prime = mpz_cmp_ui (tmp, 1) != 0; } } else { /* After enough Miller-Rabin runs, be content. */ is_prime = (r == MR_REPS - 1); } if (is_prime) goto ret1; mpz_add_ui (a, a, primes_diff[r]); /* Establish new base. */ if (!mp_millerrabin (n, nm1, a, tmp, q, k)) { is_prime = 0; goto ret1; } } factors.clear(); throw std::invalid_argument( "Lucas prime test failure. This should not happen\n"); ret1: if (flag_prove_primality) factors.resize(0); ret2: mpz_clear (q); mpz_clear (a); mpz_clear(nm1); mpz_clear(tmp); return is_prime; } void factor_using_pollard_rho (mpz_t n, unsigned long a, bigvec & factors) { mpz_t x, z, y, P; mpz_t t, t2; unsigned long k, l, i; mpz_init (t); mpz_init(t2); mpz_init_set_si (y, 2); mpz_init_set_si (x, 2); mpz_init_set_si (z, 2); mpz_init_set_ui (P, 1); k = 1; l = 1; while (mpz_cmp_ui (n, 1) != 0) { for (;;) { do { mpz_mul (t, x, x); mpz_mod (x, t, n); mpz_add_ui (x, x, a); mpz_sub (t, z, x); mpz_mul (t2, P, t); mpz_mod (P, t2, n); if (k % 32 == 1) { mpz_gcd (t, P, n); if (mpz_cmp_ui (t, 1) != 0) goto factor_found; mpz_set (y, x); } } while (--k != 0); mpz_set (z, x); k = l; l = 2 * l; for (i = 0; i < k; i++) { mpz_mul (t, x, x); mpz_mod (x, t, n); mpz_add_ui (x, x, a); } mpz_set (y, x); } factor_found: do { mpz_mul (t, y, y); mpz_mod (y, t, n); mpz_add_ui (y, y, a); mpz_sub (t, z, y); mpz_gcd (t, t, n); } while (mpz_cmp_ui (t, 1) == 0); mpz_divexact (n, n, t); /* divide by t, before t is overwritten */ if (!mp_prime_p (t)) { factor_using_pollard_rho (t, a + 1, factors); } else { factors.push_back( t ); } if (mp_prime_p (n)) { factors.push_back( n); break; } mpz_mod (x, x, n); mpz_mod (z, z, n); mpz_mod (y, y, n); } mpz_clear (P); mpz_clear (t2); mpz_clear (t); mpz_clear (z); mpz_clear (x); mpz_clear (y); } void factor (mpz_t t, bigvec & factors) { if (mpz_sgn (t) != 0) { factor_using_division (t, factors); if (mpz_cmp_ui (t, 1) != 0) { if (mp_prime_p (t)) factors.push_back( t); else factor_using_pollard_rho (t, 1, factors); } } } gmp/src/bigmod.cc0000644000176200001440000002266114662137566013423 0ustar liggesusers#include "bigmod.h" #define DEBUG_bigmod #undef DEBUG_bigmod #ifdef DEBUG_bigmod #include #endif // for GetOption etc: #include #include using namespace std; #include // string representation of (.) wrt base 'b' : std::string bigmod::str(int b) const { if (value->isNA()) return "NA"; std::string s; // sstream seems to collide with libgmp :-( if (!modulus->isNA()) s = "("; s += value->str(b); if (!modulus->isNA()) { s += " %% "; s += modulus->str(b); s += ")"; } return s; } bigmod & bigmod::operator= (const bigmod& rhs) { if(this != &rhs) { modulus = make_shared(rhs.getModulus()); value = make_shared(rhs.getValue() ); } return(*this); } bigmod bigmod::inv () const { if(value->isNA() || modulus->isNA()) { return bigmod(); } mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); if (mpz_invert(val, getValue().getValueTemp(), getModulus().getValueTemp()) == 0) { SEXP wOpt = Rf_GetOption1(Rf_install("gmp:warnNoInv")); if(wOpt != R_NilValue && Rf_asInteger(wOpt)) Rf_warning("inv(x) returning NA as x has no inverse"); return bigmod(); // return NA; was } return bigmod(std::make_shared(val), std::make_shared(modulus->getValueTemp())); } bool operator!=(const bigmod& rhs, const bigmod& lhs) { if(rhs.getValue() != lhs.getValue()) return(true); return(rhs.getModulus() != lhs.getModulus()); } bool operator==(const bigmod& rhs, const bigmod& lhs) { if(rhs.getValue() != lhs.getValue()) return(false); // if(rhs.getModulusPtr().get() == lhs.getModulusPtr().get()) return true; // same pointer return(!(rhs.getModulus() != lhs.getModulus())); } bigmod operator+(const bigmod& lhs, const bigmod& rhs) { return create_bigmod(lhs, rhs, mpz_add); } bigmod operator-(const bigmod& lhs, const bigmod& rhs) { return create_bigmod(lhs, rhs, mpz_sub); } bigmod operator*(const bigmod& lhs, const bigmod& rhs) { return create_bigmod(lhs, rhs, mpz_mul); } /* called via biginteger_binary_operation(.) from biginteger_div() in * ./bigintegerR.cc from R's .Call(biginteger_div, a, b) * ~~~~~~~~~~~~~~ * itself called from "/.bigz" = div.bigz() */ bigmod div_via_inv(const bigmod& a, const bigmod& b) { // compute a/b as a * b^(-1) return operator*(a, pow(b, bigmod(-1))); } void integer_div(mpz_t result,const mpz_t a, const mpz_t b) { mpz_tdiv_q(result,a,b); // // si resulat < 0 et module != 0: on enleve 1. // i.e. 3 / -4 = -1 if (mpz_sgn(a) * mpz_sgn(b) == -1) { mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); mpz_mod(val, a, b); if (mpz_cmp_ui(val, 0) != 0) { mpz_sub_ui(result, result, 1); } } } /* called via biginteger_binary_operation(.) from R's * .Call(biginteger_divq, a, b) , itself called from '%/%.bigz' = divq.bigz() */ bigmod operator/(const bigmod& lhs, const bigmod& rhs) { return create_bigmod(lhs, rhs, integer_div, false); } bigmod operator%(const bigmod& lhs, const bigmod& rhs) { if (lhs.getValue().isNA() || rhs.getValue().isNA()) return bigmod(); if (mpz_sgn(rhs.getValue().getValueTemp()) == 0) { Rf_warning("biginteger division by zero: returning NA"); return bigmod(); } biginteger mod; if (!lhs.getModulus().isNA() || !rhs.getModulus().isNA()) mod = rhs.getValue(); mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); mpz_mod(val, lhs.getValue().getValueTemp(), rhs.getValue().getValueTemp()); return bigmod(val, mod); } // Either 'base' has a modulus, or it has not *and* exp >= 0 : bigmod pow(const bigmod& base, const bigmod& exp) { biginteger mod = get_modulus(base, exp); #ifdef DEBUG_bigmod if(mod.isNA() && !mpz_cmp_si(base.getValue().getValueTemp(), 1)) Rprintf("bigmod pow(1, exp=%d)\n", mpz_get_si(exp.getValue().getValueTemp())); else if(mod.isNA() && !mpz_cmp_si(exp.getValue().getValueTemp(), 0)) Rprintf("bigmod pow(base=%d, 0)\n", mpz_get_si(base.getValue().getValueTemp())); #endif // if (base == 1 or exp == 0) return 1 if(mod.isNA() && ((!base.getValue().isNA() && !mpz_cmp_si(base.getValue().getValueTemp(), 1)) || (! exp.getValue().isNA() && !mpz_cmp_si( exp.getValue().getValueTemp(), 0)))) return bigmod(biginteger(1)); if (base.getValue().isNA() || exp.getValue().isNA()) return bigmod(); int sgn_exp = mpz_sgn(exp.getValue().getValueTemp()); bool neg_exp = (sgn_exp < 0); // b ^ -|e| = 1 / b^|e| mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); #ifdef DEBUG_bigmod Rprintf("bigmod pow(base=%3s, exp=%3s [mod=%3s]) ..\n", base.getValue().str(10).c_str(), exp.getValue().str(10).c_str(), mod.str(10).c_str()); #endif if (mod.isNA()) { // <==> (both have no mod || both have mod. but differing) if(neg_exp){ throw invalid_argument(_("** internal error (negative powers for Z/nZ), please report!")); } if (!mpz_fits_ulong_p(exp.getValue().getValueTemp())) throw invalid_argument(_("exponent e too large for pow(z,e) = z^e"));// FIXME? return( "Inf" ) // else : mpz_pow_ui(val, base.getValue().getValueTemp(), mpz_get_ui(exp.getValue().getValueTemp())); } else if( mpz_sgn(mod.getValueTemp()) != 0) { // check modulus non-zero if(neg_exp) { // negative exponent -- only ok if inverse exists if (mpz_invert(val, base.getValue().getValueTemp(), mod.getValueTemp()) == 0) { SEXP wOpt = Rf_GetOption1(Rf_install("gmp:warnNoInv")); if(wOpt != R_NilValue && Rf_asInteger(wOpt)) Rf_warning("pow(x, -|n|) returning NA as x has no inverse wrt modulus"); return(bigmod()); // return NA; was } // else: val = x^(-1) already: ==> result = val ^ |exp| = val ^ (-exp) : // nExp := - exp mpz_t nExp; mpz_init(nExp); mpz_t_sentry val_ex(nExp); mpz_neg(nExp, exp.getValue().getValueTemp()); mpz_powm(val, val, nExp, mod.getValueTemp()); } else { // non-negative exponent mpz_powm(val, base.getValue().getValueTemp(), exp.getValue().getValueTemp(), mod.getValueTemp()); } } return bigmod(val, mod); } bigmod inv(const bigmod& x, const bigmod& m) { if (x.getValue().isNA() || m.getValue().isNA()) return bigmod(); SEXP wOpt = Rf_GetOption1(Rf_install("gmp:warnNoInv")); bool warnI = (wOpt != R_NilValue && Rf_asInteger(wOpt)); if (mpz_sgn(m.getValue().getValueTemp()) == 0) { if(warnI) Rf_warning("inv(0) returning NA"); return bigmod(); } biginteger mod = get_modulus(x, m); mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); if (mpz_invert(val, x.getValue().getValueTemp(), m.getValue().getValueTemp()) == 0) { if(warnI) Rf_warning("inv(x,m) returning NA as x has no inverse modulo m"); return(bigmod()); // return NA; was } return bigmod(val, mod); } // R as.bigz() : bigmod set_modulus(const bigmod& x, const bigmod& m) { if (!m.getValue().isNA() && mpz_sgn(m.getValue().getValueTemp()) == 0){ throw invalid_argument("modulus 0 is invalid"); } // if (!m.getValue().isNA() && mpz_cmp(x.getValue().getValueTemp(),m.getValue().getValueTemp())>=0) { if (!m.getValue().isNA() ) { bigmod t(x%m); return bigmod(t.getValue(), m.getValue()); } else return bigmod(x.getValue(), m.getValue()); } bigmod gcd(const bigmod& lhs, const bigmod& rhs) { return create_bigmod(lhs, rhs, mpz_gcd); } bigmod lcm(const bigmod& lhs, const bigmod& rhs) { return create_bigmod(lhs, rhs, mpz_lcm); } // return the modulus to use for the two bigmods. // NA if incompatible. biginteger get_modulus(const bigmod& b1, const bigmod& b2) { if (b1.getModulus().isNA()) // NA: means "no modulus" <==> R's is.null(modulus(.)) return b2.getModulus(); // if b2 is NA too, the return is correct: NA else if (b2.getModulus().isNA()) return b1.getModulus(); else if (mpz_cmp(b1.getModulus().getValueTemp(), b2.getModulus().getValueTemp())) { SEXP wOpt = Rf_GetOption1(Rf_install("gmp:warnModMismatch")); if(wOpt != R_NilValue && Rf_asInteger(wOpt)) Rf_warning("modulus mismatch in bigz.* arithmetic"); return biginteger(); // i.e. NA } else // equal return b1.getModulus(); } // typedef void (*gmp_binary)(mpz_t, const mpz_t, const mpz_t); // Create a bigmod from a binary combination of two other bigmods bigmod create_bigmod(const bigmod& lhs, const bigmod& rhs, gmp_binary f, bool zeroRhsAllowed) { if (lhs.getValue().isNA() || rhs.getValue().isNA()) return bigmod(); if (!zeroRhsAllowed && mpz_sgn(rhs.getValue().getValueTemp()) == 0) { Rf_warning("returning NA for (modulus) 0 in RHS"); return bigmod(); } biginteger mod = get_modulus(lhs, rhs); mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); f(val, lhs.getValue().getValueTemp(), rhs.getValue().getValueTemp()); //--- val := f(lhs, rhs) #ifdef DEBUG_bigmod bool iNA = biginteger(val).isNA(); char* buf; if(iNA) buf = NULL; else { buf = new char[mpz_sizeinbase(val, 10)+2]; // possible minus sign, size of number + '\0' mpz_get_str(buf, 10, val); } Rprintf("create_bigmod(lhs=%3s, rhs=%3s [mod=%3s]) = %s%s", lhs.getValue().str(10).c_str(), rhs.getValue().str(10).c_str(), mod.str(10).c_str(), (iNA)? "NA" : buf, (mod.isNA())? "\n" : " {before 'mod'}"); #endif if (!mod.isNA()) { mpz_mod(val, val, mod.getValueTemp()); #ifdef DEBUG_bigmod if(biginteger(val).isNA()) Rprintf(" -> val = NA\n"); else { mpz_get_str(buf, 10, val); Rprintf(" -> val = %s\n", buf); } #endif } return bigmod(val, mod); } gmp/src/factor.cc0000644000176200001440000000225514662137750013430 0ustar liggesusers/*! \file factor.cc * \brief C function used for factorization * * \version 1 * * \date Created: 04/12/04 * \date Last modified: Time-stamp: <2023-02-03 12:04:13 (antoine)> * * \author Antoine Lucas (help from Immanuel Scholz) (R adaptation) * Original C code from libgmp. * * \note Licence: GPL (>= 2) */ #include #include "factorize.h" #include "Rgmp.h" using namespace std; #include "factor.h" // // \brief function that gets values from R and send to functions // factor // SEXP factorR (SEXP n) { try{ bigvec v = bigintegerR::create_bignum(n), result; if(v.size() > 0) { mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); mpz_set(val,v[0].getValue().getValueTemp()); int sgn = mpz_sgn(val); if(sgn == 0){ v.clear(); throw invalid_argument(_("Cannot factorize 0")); } if(sgn<0) { mpz_abs(val,val); result.push_back(bigmod(biginteger(-1))); } // // function from gmplib, in demo/factorize.c // factor(val,result); } return bigintegerR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } gmp/src/bigvec_q.h0000644000176200001440000000505414444267422013571 0ustar liggesusers/*! \file bigve_cq.h * \brief bigvec_q class definition * * \version 1 * * \date Created: 2005 * \date Last modified: Time-stamp: <2023-01-20 19:13:13 (antoine)> * * * \note Licence: GPL (>= 2) */ #ifndef BIGVEC_Q_HEADER_ #define BIGVEC_Q_HEADER_ 1 #include "bigrational.h" #include "bigvec.h" /** \brief class bigvec_q for vector of bigrational * * It is a class composed of a vector of bigrational * and an nrow parameter. */ class bigvec_q : public math::Matrix { public: /** \brief The real value */ std::vector value; /** \brief optional parameter used with matrix -- set to -1 for non-matrix */ int nrow ; /** \brief constructor */ bigvec_q() : value(), nrow(-1) { } /** \brief strange constructors ! */ bigvec_q(double * & a, double * b): value(a,b),nrow(-1) {}; /** \brief strange constructors ! */ bigvec_q(int * & a, int * b): value(a,b),nrow(-1) {}; /** \brief create empty vector of size i */ bigvec_q(unsigned int i): value(i), nrow(-1){}; /** \brief copy constructor */ bigvec_q(const bigvec_q & rhs); /** \brief create from bigintegers */ bigvec_q(const bigvec & rhs); virtual ~bigvec_q(); inline bool isVector() const{ return nrow < 0 ; } /** \brief assignemt operator */ bigvec_q & operator= (const bigvec_q& rhs); /** * \brief extract a value. * \note it returns a reference on the value. */ const bigrational & operator[] (unsigned int i) const; /** * \brief extract a value. * \note it returns a reference on the value. */ bigrational & operator[] (unsigned int i) ; bigrational & get(unsigned int row, unsigned int col) ; void set(unsigned int row, unsigned int col, const bigrational & val); /** * \brief Set a value */ void set(unsigned int i,const bigrational & val); /** * \brief set a value * \note it change bigrational na flag to false */ void set(unsigned int i,const mpq_t & val); inline void erase(unsigned int index){ value.erase(value.begin() + index); } /** * \brief add a value */ void push_back(const bigrational &i); /** * \brief return size */ unsigned int size() const ; /** * \brief resize value */ void resize(unsigned int n); unsigned int nRows() const; /** * \brief clear all. */ void clear(); /** \brief print matrix to stdout * * use for debug purpose */ void print(); }; /** \brief comparison operator */ bool operator!= (const bigvec_q& rhs, const bigvec_q& lhs); #endif gmp/src/Rgmp.h0000644000176200001440000000102414444267422012710 0ustar liggesusers#ifndef R_gmp_HEADER #define R_gmp_HEADER 1 // gmp.h calls cstddef with __need_size_t defined #include #include #include #include #include #include #ifndef AS_INTEGER // the only thing we use from : #define AS_INTEGER(x) Rf_coerceVector(x,INTSXP) #endif #define class_P(_x_) CHAR(Rf_asChar(Rf_getAttrib(_x_, R_ClassSymbol))) #ifdef ENABLE_NLS #include #define _(String) dgettext ("main", String) #else #define _(String) (String) #endif #endif gmp/src/bigintegerR.h0000644000176200001440000001565714444267421014264 0ustar liggesusers/*! \file bigintegerR.h * \brief header for C++ functions used with R * * \version 1 * * \date Created: 2006 * \date Last modified: Time-stamp: <2023-01-24 15:52:06 (antoine)> * * * \note Licence: GPL (>= 2) */ #ifndef BIGINTEGERRRRRRR_HEADER_ #define BIGINTEGERRRRRRR_HEADER_ 1 #include "bigvec.h" #ifndef T_BIGMOD_BINARY_OPERATION #define T_BIGMOD_BINARY_OPERATION 1 /// A pointer to a binary operator for bigintegers typedef bigmod (*biginteger_binary_fn)(const bigmod&, const bigmod&); #endif #ifndef T_BIGMOD_BINARY_OPERATION_LOGICAL #define T_BIGMOD_BINARY_OPERATION_LOGICAL 1 typedef bool (*biginteger_logical_binary_fn)(const biginteger&, const biginteger&); #endif typedef const biginteger & (*bigmod_accessor_fn)(const bigmod&); struct lockSexp { lockSexp(const SEXP & value) { PROTECT(value); } ~lockSexp(){ UNPROTECT(1); } }; /** * \brief set of function useful for manipulation of SEXP and bigvec */ namespace bigintegerR{ /** \brief create a vector of bigmod, all without a modulus. */ bigvec create_vector(const SEXP & param); /** * \brief create a vector of bigmod */ bigvec create_bignum(const SEXP & param); /** * \brief create a vector of int */ std::vector create_int(const SEXP & param); /** * \brief export vector of biginteger to R value */ SEXP create_SEXP(const bigvec& v,bigmod_accessor_fn fct, unsigned int size); /** * \brief export bigvec to R value */ SEXP create_SEXP(const bigvec & v); SEXP biginteger_binary_operation(const bigvec & a,const bigvec & b, biginteger_binary_fn f); SEXP biginteger_binary_operation(const SEXP & a,const SEXP & b, biginteger_binary_fn f); SEXP biginteger_logical_binary_operation(const SEXP & a,const SEXP & b, biginteger_logical_binary_fn f); bool lt(const biginteger& lhs, const biginteger& rhs); bool gt(const biginteger& lhs, const biginteger& rhs); bool lte(const biginteger& lhs, const biginteger& rhs); bool gte(const biginteger& lhs, const biginteger& rhs); bool eq(const biginteger& lhs, const biginteger& rhs); bool neq(const biginteger& lhs, const biginteger& rhs); /** \brief return va[b] */ bigvec biginteger_get_at_C(bigvec va,SEXP b); } extern "C" { /** * \brief GMP version */ SEXP R_gmp_get_version(); /** * \brief Addition of a and b */ SEXP biginteger_add(SEXP a, SEXP b); /** * \brief Subtraction of a and b */ SEXP biginteger_sub(SEXP a, SEXP b); /** * \brief Multiplication of a and b */ SEXP biginteger_mul(SEXP a, SEXP b); /** * \brief Quotient of a / b or a %/% b */ SEXP biginteger_div (SEXP a, SEXP b);// integer division, possibly --> rational SEXP biginteger_divq(SEXP a, SEXP b);// integer division /** * \brief Modulus of a % b */ SEXP biginteger_mod(SEXP a, SEXP b); /** * \brief Power of base a to exponent b */ SEXP biginteger_pow(SEXP a, SEXP b); /** * \brief Inverse from a mod b */ SEXP biginteger_inv(SEXP a, SEXP b); /** * \brief Greatest common divisor of a and b */ SEXP biginteger_gcd(SEXP a, SEXP b); /** * \brief Least common multiply of a and b */ SEXP biginteger_lcm(SEXP a, SEXP b); /** * \brief Sets the intern modulus of a to b */ // SEXP biginteger_setmod(SEXP a, SEXP b); /** * \brief Return from vector a all elements specified in vector b */ SEXP biginteger_get_at(SEXP a, SEXP b); /** * \brief Return a vector with the values from src specified by * idx to sequentiell values from "value". */ SEXP biginteger_set_at(SEXP src, SEXP idx, SEXP value); /** * \brief Convert from an long value or a string into biginteger. * * If you want a modulus-set-bigint, just use * as.biginteger(value, modulus) */ SEXP biginteger_as(SEXP a, SEXP mod); /** * \brief Convert from a biginteger vector to a character string vector. */ SEXP biginteger_as_character(SEXP a,SEXP b); /** * \brief Convert from a biginteger vector to a real vector. */ SEXP biginteger_as_numeric(SEXP a); /** * \brief Convert from a biginteger vector to a integer vector. */ SEXP biginteger_as_integer(SEXP a); /** * \brief Return the length of the vector */ SEXP biginteger_length(SEXP a); /** * \brief Returns a resized vector cut at end or filled with NA. */ SEXP biginteger_setlength(SEXP vec, SEXP value); /** * \brief Return whether the parameter is NA */ SEXP biginteger_is_na(SEXP a); /** * \brief Return sign of a */ SEXP biginteger_sgn(SEXP a); /** * \brief Return whether a < b */ SEXP biginteger_lt(SEXP a, SEXP b); /** * \brief Return whether a > b */ SEXP biginteger_gt(SEXP a, SEXP b); /** * \brief Return whether a <= b */ SEXP biginteger_lte(SEXP a, SEXP b); /** * \brief Return whether a >= b */ SEXP biginteger_gte(SEXP a, SEXP b); /** * \brief Return whether a == b */ SEXP biginteger_eq(SEXP a, SEXP b); /** * \brief Return whether a != b */ SEXP biginteger_neq(SEXP a, SEXP b); /** * \brief For function c() */ SEXP biginteger_c(SEXP args); /** * \brief Create vector as n times x */ SEXP biginteger_rep(SEXP x, SEXP times); /** * \brief Return if a is prime with a proba test */ SEXP biginteger_is_prime(SEXP a, SEXP reps); /** * \brief Return next prime with a proba test */ SEXP biginteger_nextprime(SEXP a); /** * \brief Return absolute value of a */ SEXP biginteger_abs(SEXP a); /** * \brief Return bezoult coefficients */ SEXP biginteger_gcdex(SEXP a, SEXP b); /** * \brief Random number generation */ SEXP biginteger_rand_u (SEXP nb ,SEXP length,SEXP newseed, SEXP ok); /** * \brief Give size of integer */ SEXP biginteger_sizeinbase (SEXP x, SEXP exp); /** * \brief Compute {d, ex} === frexp(x): x = d * 2^ex, * where 1/2 <= d < 1. */ SEXP bigI_frexp(SEXP x); /** * \brief Compute Binomial Coefficient */ SEXP bigI_choose(SEXP n, SEXP k); /** * \brief Compute Factorial */ SEXP bigI_factorial(SEXP n); /** * \brief Compute Fibonacci number */ SEXP bigI_fibnum(SEXP n); /** * \brief Compute Fibonacci number */ SEXP bigI_fibnum2(SEXP n); /** * \brief Compute lucas number */ SEXP bigI_lucnum(SEXP n); /** * \brief Compute lucas number */ SEXP bigI_lucnum2(SEXP n); /** * \brief Return max */ SEXP biginteger_max(SEXP a, SEXP narm); /** * \brief Return min */ SEXP biginteger_min(SEXP a, SEXP narm); /** * \brief Return cumsum */ SEXP biginteger_cumsum(SEXP a); /** * \brief Return sum */ SEXP biginteger_sum(SEXP a); /** * \brief Return prod */ SEXP biginteger_prod(SEXP a); /** \brief Return x ^ y [ n ] */ SEXP biginteger_powm(SEXP x, SEXP y, SEXP n); /** * \brief Return log2(.) and natural log(.): */ SEXP biginteger_log2(SEXP x); SEXP biginteger_log (SEXP x); } #endif gmp/src/bigvec.h0000644000176200001440000000711714444267421013252 0ustar liggesusers/*! \file bigvec.h * \brief bigvec class definition * * \version 1 * * \date Created: 2005 * \date Last modified: Time-stamp: <2023-02-03 08:59:56 (antoine)> * * * \note Licence: GPL (>= 2) */ #ifndef BIGVEC_HEADER_ #define BIGVEC_HEADER_ 1 #include #include "bigmod.h" #include "templateMatrix.h" enum TYPE_MODULUS{ NO_MODULUS, MODULUS_GLOBAL, MODULUS_BY_CELL }; /** \brief class bigvec * * It a class composed of 2 vectors, (value & modulus) that * can be of different size and a nrow * parameter (for matrix support) */ class bigvec : public math::Matrix { protected: /** array with all bigmod, that are references to values in vector. */ std::vector values; TYPE_MODULUS type; std::shared_ptr modulus; public: /** \brief optional parameter used with matrix -- set to -1 for non-matrix */ int nrow ; /** \brief initialize value to size i */ bigvec(unsigned int i = 0); /** * \brief copy constructor */ bigvec(const bigvec & vecteur); virtual ~bigvec(); inline bool isVector() const{ return nrow < 0 ; } /** * \brief construct a bigmod at indice i * * It gets values from value[i] & modulus[i % modulus.size()] * * \note should not used for assignement */ const bigmod & operator[] (unsigned int i) const; bigmod & operator[] (unsigned int i) ; /** * \brief assign a value at indice i */ void set(unsigned int i,const bigmod & val); void set(unsigned int row, unsigned int col, const bigmod & val) ; bigmod & get(unsigned int row, unsigned int col) ; /** * \brief extend our vectors. * * This function will check if modulus should be added. * Modulus can be set "globaly" i.e. one modulus for the * whole vector/matrix. * Or set by row (a constant modulus for each row) * Or set by cell (as many modulus as value) */ void push_back(const bigmod &i); /** * insert int value */ void push_back(int value_p); inline void erase(unsigned int index){ values.erase(values.begin() + index); } /** * Insert Big Integer value */ void push_back(biginteger & value_p); void push_back(const __mpz_struct* value_p); /** * \brief return size of vector value */ unsigned int size() const ; unsigned int nRows() const; /** * \brief extend vector value. */ void resize(unsigned int i); /** * \brief clear all */ void clear(); /** * \brief Return as a human readible string */ std::string str(int i, int b) const; /** * \brief assignement operator */ bigvec & operator= (const bigvec & rhs); /** \brief print matrix to stdout * * use for debug purpose */ void print(); inline unsigned int getModulusSize(){ if(type == NO_MODULUS) return 0; if(type == MODULUS_GLOBAL) return 1; return size(); } void setGlobalModulus(std::shared_ptr & modulus); inline std::shared_ptr & getGlobalModulus(){ return modulus; } const TYPE_MODULUS getType() const { return type; } inline void setType(TYPE_MODULUS val){ type = val; if(val == MODULUS_GLOBAL && size() > 0){ modulus = (*this)[0].getModulusPtr(); } } inline void reserve(unsigned int size){ values.reserve(size); } /** return a global modulus if possible, null if not */ static std::shared_ptr getGlobalModulus(bigvec & first, bigvec & second); private: void checkValuesMod() ; void clearValuesMod() ; }; // /** \brief comparison operator */ bool operator!= (const bigvec& rhs, const bigvec& lhs); #endif gmp/src/apply.h0000644000176200001440000000014514444267421013132 0ustar liggesusersextern "C" { SEXP gmpMatToListZ(SEXP X, SEXP line); SEXP gmpMatToListQ(SEXP X, SEXP line); } gmp/src/templateMatrix.h0000644000176200001440000000500714444267421015007 0ustar liggesusers#ifndef TEMPLATE_MATRIX_GMP #define TEMPLATE_MATRIX_GMP 1 namespace math{ template< class T> class Vector{ public: Vector(); virtual unsigned int size() const = 0; virtual const T & operator[](unsigned int i) const=0; virtual T & operator[](unsigned int i) =0; virtual ~Vector(){}; }; template< class T> class Matrix : public Vector { private: Matrix * transposate; public: Matrix(); virtual ~Matrix() { if (transposate) delete transposate; } virtual unsigned int nRows() const = 0; virtual unsigned int nCols() const; virtual T & get(unsigned int row, unsigned int col) = 0; virtual void set(unsigned int row, unsigned int col, const T& val) =0; /** return true if matrix is supposed to be a vector and not a matrix n x 1 */ virtual bool isVector() const = 0; virtual void clear() = 0; /** * \brief assign a value at indice i */ // virtual void set(unsigned int i,const T & val) = 0; /** * \brief substract lambda * line j to line i */ void subLine(unsigned int i,unsigned int j,const T & lambda){ for(unsigned int k=0; k < nCols() ; ++k) set(i , k , get(i, k) - ( get(j , k) * lambda ) ); } /** * \brief multiply line i by lambda */ void mulLine(unsigned int i,const T & lambda){ for(unsigned int k=0; k < nCols(); ++k) set(i , k, get(i,k) * lambda ); } Matrix * transpose(); }; template< class T> class Transpose: public Matrix { private : Matrix & source; public: Transpose(Matrix & source_p) : source(source_p) { } unsigned int size() const{ return source.size(); } bool isVector() const { return false; } unsigned int nRows() const { return source.nCols(); } T & get(unsigned int i, unsigned int j) { return source.get(j,i); } void set(unsigned int i,unsigned int j, const T & val){ source.set(j,i,val); } }; // template code. template Vector::Vector() { } template Matrix::Matrix() : Vector(), transposate(NULL) { } template Matrix * Matrix::transpose(){ if (transposate == 0){ transposate =new Transpose(*this); } return transposate; } template unsigned int Matrix::nCols() const{ if(nRows() <=0) return this->size(); return this->size() / nRows(); } } #endif gmp/src/Makevars.in0000644000176200001440000000007214444267421013734 0ustar liggesusersPKG_CPPFLAGS=$(CPPFLAGS) PKG_LIBS=$(PKG_LDFLAGS) -lgmp gmp/src/primes.h0000644000176200001440000010111414444267421013302 0ustar liggesusersP( 1, 0xaaaaaaaaaaaaaaabUL, 0x5555555555555555UL) /* 3 */ P( 2, 0xcccccccccccccccdUL, 0x3333333333333333UL) /* 5 */ P( 2, 0x6db6db6db6db6db7UL, 0x2492492492492492UL) /* 7 */ P( 4, 0x2e8ba2e8ba2e8ba3UL, 0x1745d1745d1745d1UL) /* 11 */ P( 2, 0x4ec4ec4ec4ec4ec5UL, 0x13b13b13b13b13b1UL) /* 13 */ P( 4, 0xf0f0f0f0f0f0f0f1UL, 0x0f0f0f0f0f0f0f0fUL) /* 17 */ P( 2, 0x86bca1af286bca1bUL, 0x0d79435e50d79435UL) /* 19 */ P( 4, 0xd37a6f4de9bd37a7UL, 0x0b21642c8590b216UL) /* 23 */ P( 6, 0x34f72c234f72c235UL, 0x08d3dcb08d3dcb08UL) /* 29 */ P( 2, 0xef7bdef7bdef7bdfUL, 0x0842108421084210UL) /* 31 */ P( 6, 0x14c1bacf914c1badUL, 0x06eb3e45306eb3e4UL) /* 37 */ P( 4, 0x8f9c18f9c18f9c19UL, 0x063e7063e7063e70UL) /* 41 */ P( 2, 0x82fa0be82fa0be83UL, 0x05f417d05f417d05UL) /* 43 */ P( 4, 0x51b3bea3677d46cfUL, 0x0572620ae4c415c9UL) /* 47 */ P( 6, 0x21cfb2b78c13521dUL, 0x04d4873ecade304dUL) /* 53 */ P( 6, 0xcbeea4e1a08ad8f3UL, 0x0456c797dd49c341UL) /* 59 */ P( 2, 0x4fbcda3ac10c9715UL, 0x04325c53ef368eb0UL) /* 61 */ P( 6, 0xf0b7672a07a44c6bUL, 0x03d226357e16ece5UL) /* 67 */ P( 4, 0x193d4bb7e327a977UL, 0x039b0ad12073615aUL) /* 71 */ P( 2, 0x7e3f1f8fc7e3f1f9UL, 0x0381c0e070381c0eUL) /* 73 */ P( 6, 0x9b8b577e613716afUL, 0x033d91d2a2067b23UL) /* 79 */ P( 4, 0xa3784a062b2e43dbUL, 0x03159721ed7e7534UL) /* 83 */ P( 6, 0xf47e8fd1fa3f47e9UL, 0x02e05c0b81702e05UL) /* 89 */ P( 8, 0xa3a0fd5c5f02a3a1UL, 0x02a3a0fd5c5f02a3UL) /* 97 */ P( 4, 0x3a4c0a237c32b16dUL, 0x0288df0cac5b3f5dUL) /* 101 */ P( 2, 0xdab7ec1dd3431b57UL, 0x027c45979c95204fUL) /* 103 */ P( 4, 0x77a04c8f8d28ac43UL, 0x02647c69456217ecUL) /* 107 */ P( 2, 0xa6c0964fda6c0965UL, 0x02593f69b02593f6UL) /* 109 */ P( 4, 0x90fdbc090fdbc091UL, 0x0243f6f0243f6f02UL) /* 113 */ P(14, 0x7efdfbf7efdfbf7fUL, 0x0204081020408102UL) /* 127 */ P( 4, 0x03e88cb3c9484e2bUL, 0x01f44659e4a42715UL) /* 131 */ P( 6, 0xe21a291c077975b9UL, 0x01de5d6e3f8868a4UL) /* 137 */ P( 2, 0x3aef6ca970586723UL, 0x01d77b654b82c339UL) /* 139 */ P(10, 0xdf5b0f768ce2cabdUL, 0x01b7d6c3dda338b2UL) /* 149 */ P( 2, 0x6fe4dfc9bf937f27UL, 0x01b2036406c80d90UL) /* 151 */ P( 6, 0x5b4fe5e92c0685b5UL, 0x01a16d3f97a4b01aUL) /* 157 */ P( 6, 0x1f693a1c451ab30bUL, 0x01920fb49d0e228dUL) /* 163 */ P( 4, 0x8d07aa27db35a717UL, 0x01886e5f0abb0499UL) /* 167 */ P( 6, 0x882383b30d516325UL, 0x017ad2208e0ecc35UL) /* 173 */ P( 6, 0xed6866f8d962ae7bUL, 0x016e1f76b4337c6cUL) /* 179 */ P( 2, 0x3454dca410f8ed9dUL, 0x016a13cd15372904UL) /* 181 */ P(10, 0x1d7ca632ee936f3fUL, 0x01571ed3c506b39aUL) /* 191 */ P( 2, 0x70bf015390948f41UL, 0x015390948f40feacUL) /* 193 */ P( 4, 0xc96bdb9d3d137e0dUL, 0x014cab88725af6e7UL) /* 197 */ P( 2, 0x2697cc8aef46c0f7UL, 0x0149539e3b2d066eUL) /* 199 */ P(12, 0xc0e8f2a76e68575bUL, 0x013698df3de07479UL) /* 211 */ P(12, 0x687763dfdb43bb1fUL, 0x0125e22708092f11UL) /* 223 */ P( 4, 0x1b10ea929ba144cbUL, 0x0120b470c67c0d88UL) /* 227 */ P( 2, 0x1d10c4c0478bbcedUL, 0x011e2ef3b3fb8744UL) /* 229 */ P( 4, 0x63fb9aeb1fdcd759UL, 0x0119453808ca29c0UL) /* 233 */ P( 6, 0x64afaa4f437b2e0fUL, 0x0112358e75d30336UL) /* 239 */ P( 2, 0xf010fef010fef011UL, 0x010fef010fef010fUL) /* 241 */ P(10, 0x28cbfbeb9a020a33UL, 0x0105197f7d734041UL) /* 251 */ P( 6, 0xff00ff00ff00ff01UL, 0x00ff00ff00ff00ffUL) /* 257 */ P( 6, 0xd624fd1470e99cb7UL, 0x00f92fb2211855a8UL) /* 263 */ P( 6, 0x8fb3ddbd6205b5c5UL, 0x00f3a0d52cba8723UL) /* 269 */ P( 2, 0xd57da36ca27acdefUL, 0x00f1d48bcee0d399UL) /* 271 */ P( 6, 0xee70c03b25e4463dUL, 0x00ec979118f3fc4dUL) /* 277 */ P( 4, 0xc5b1a6b80749cb29UL, 0x00e939651fe2d8d3UL) /* 281 */ P( 2, 0x47768073c9b97113UL, 0x00e79372e225fe30UL) /* 283 */ P(10, 0x2591e94884ce32adUL, 0x00dfac1f74346c57UL) /* 293 */ P(14, 0xf02806abc74be1fbUL, 0x00d578e97c3f5fe5UL) /* 307 */ P( 4, 0x7ec3e8f3a7198487UL, 0x00d2ba083b445250UL) /* 311 */ P( 2, 0x58550f8a39409d09UL, 0x00d161543e28e502UL) /* 313 */ P( 4, 0xec9e48ae6f71de15UL, 0x00cebcf8bb5b4169UL) /* 317 */ P(14, 0x2ff3a018bfce8063UL, 0x00c5fe740317f9d0UL) /* 331 */ P( 6, 0x7f9ec3fcf61fe7b1UL, 0x00c2780613c0309eUL) /* 337 */ P(10, 0x89f5abe570e046d3UL, 0x00bcdd535db1cc5bUL) /* 347 */ P( 2, 0xda971b23f1545af5UL, 0x00bbc8408cd63069UL) /* 349 */ P( 4, 0x79d5f00b9a7862a1UL, 0x00b9a7862a0ff465UL) /* 353 */ P( 6, 0x4dba1df32a128a57UL, 0x00b68d31340e4307UL) /* 359 */ P( 8, 0x87530217b7747d8fUL, 0x00b2927c29da5519UL) /* 367 */ P( 6, 0x30baae53bb5e06ddUL, 0x00afb321a1496fdfUL) /* 373 */ P( 6, 0xee70206c12e9b5b3UL, 0x00aceb0f891e6551UL) /* 379 */ P( 4, 0xcdde9462ec9dbe7fUL, 0x00ab1cbdd3e2970fUL) /* 383 */ P( 6, 0xafb64b05ec41cf4dUL, 0x00a87917088e262bUL) /* 389 */ P( 8, 0x02944ff5aec02945UL, 0x00a513fd6bb00a51UL) /* 397 */ P( 4, 0x2cb033128382df71UL, 0x00a36e71a2cb0331UL) /* 401 */ P( 8, 0x1ccacc0c84b1c2a9UL, 0x00a03c1688732b30UL) /* 409 */ P(10, 0x19a93db575eb3a0bUL, 0x009c69169b30446dUL) /* 419 */ P( 2, 0xcebeef94fa86fe2dUL, 0x009baade8e4a2f6eUL) /* 421 */ P(10, 0x6faa77fb3f8df54fUL, 0x00980e4156201301UL) /* 431 */ P( 2, 0x68a58af00975a751UL, 0x00975a750ff68a58UL) /* 433 */ P( 6, 0xd56e36d0c3efac07UL, 0x009548e4979e0829UL) /* 439 */ P( 4, 0xd8b44c47a8299b73UL, 0x0093efd1c50e726bUL) /* 443 */ P( 6, 0x02d9ccaf9ba70e41UL, 0x0091f5bcb8bb02d9UL) /* 449 */ P( 8, 0x0985e1c023d9e879UL, 0x008f67a1e3fdc261UL) /* 457 */ P( 4, 0x2a343316c494d305UL, 0x008e2917e0e702c6UL) /* 461 */ P( 2, 0x70cb7916ab67652fUL, 0x008d8be33f95d715UL) /* 463 */ P( 4, 0xd398f132fb10fe5bUL, 0x008c55841c815ed5UL) /* 467 */ P(12, 0x6f2a38a6bf54fa1fUL, 0x0088d180cd3a4133UL) /* 479 */ P( 8, 0x211df689b98f81d7UL, 0x00869222b1acf1ceUL) /* 487 */ P( 4, 0x0e994983e90f1ec3UL, 0x0085797b917765abUL) /* 491 */ P( 8, 0xad671e44bed87f3bUL, 0x008355ace3c897dbUL) /* 499 */ P( 4, 0xf9623a0516e70fc7UL, 0x00824a4e60b3262bUL) /* 503 */ P( 6, 0x4b7129be9dece355UL, 0x0080c121b28bd1baUL) /* 509 */ P(12, 0x190f3b7473f62c39UL, 0x007dc9f3397d4c29UL) /* 521 */ P( 2, 0x63dacc9aad46f9a3UL, 0x007d4ece8fe88139UL) /* 523 */ P(18, 0xc1108fda24e8d035UL, 0x0079237d65bcce50UL) /* 541 */ P( 6, 0xb77578472319bd8bUL, 0x0077cf53c5f7936cUL) /* 547 */ P(10, 0x473d20a1c7ed9da5UL, 0x0075a8accfbdd11eUL) /* 557 */ P( 6, 0xfbe85af0fea2c8fbUL, 0x007467ac557c228eUL) /* 563 */ P( 6, 0x58a1f7e6ce0f4c09UL, 0x00732d70ed8db8e9UL) /* 569 */ P( 2, 0x1a00e58c544986f3UL, 0x0072c62a24c3797fUL) /* 571 */ P( 6, 0x7194a17f55a10dc1UL, 0x007194a17f55a10dUL) /* 577 */ P(10, 0x7084944785e33763UL, 0x006fa549b41da7e7UL) /* 587 */ P( 6, 0xba10679bd84886b1UL, 0x006e8419e6f61221UL) /* 593 */ P( 6, 0xebe9c6bb31260967UL, 0x006d68b5356c207bUL) /* 599 */ P( 2, 0x97a3fe4bd1ff25e9UL, 0x006d0b803685c01bUL) /* 601 */ P( 6, 0x6c6388395b84d99fUL, 0x006bf790a8b2d207UL) /* 607 */ P( 6, 0x8c51da6a1335df6dUL, 0x006ae907ef4b96c2UL) /* 613 */ P( 4, 0x46f3234475d5add9UL, 0x006a37991a23aeadUL) /* 617 */ P( 2, 0x905605ca3c619a43UL, 0x0069dfbdd4295b66UL) /* 619 */ P(12, 0xcee8dff304767747UL, 0x0067dc4c45c8033eUL) /* 631 */ P(10, 0xff99c27f00663d81UL, 0x00663d80ff99c27fUL) /* 641 */ P( 2, 0xacca407f671ddc2bUL, 0x0065ec17e3559948UL) /* 643 */ P( 4, 0xe71298bac1e12337UL, 0x00654ac835cfba5cUL) /* 647 */ P( 6, 0xfa1e94309cd09045UL, 0x00645c854ae10772UL) /* 653 */ P( 6, 0xbebccb8e91496b9bUL, 0x006372990e5f901fUL) /* 659 */ P( 2, 0x312fa30cc7d7b8bdUL, 0x006325913c07beefUL) /* 661 */ P(12, 0x6160ff9e9f006161UL, 0x006160ff9e9f0061UL) /* 673 */ P( 4, 0x6b03673b5e28152dUL, 0x0060cdb520e5e88eUL) /* 677 */ P( 6, 0xfe802ffa00bfe803UL, 0x005ff4017fd005ffUL) /* 683 */ P( 8, 0xe66fe25c9e907c7bUL, 0x005ed79e31a4dccdUL) /* 691 */ P(10, 0x3f8b236c76528895UL, 0x005d7d42d48ac5efUL) /* 701 */ P( 8, 0xf6f923bf01ce2c0dUL, 0x005c6f35ccba5028UL) /* 709 */ P(10, 0x6c3d3d98bed7c42fUL, 0x005b2618ec6ad0a5UL) /* 719 */ P( 8, 0x30981efcd4b010e7UL, 0x005a2553748e42e7UL) /* 727 */ P( 6, 0x6f691fc81ebbe575UL, 0x0059686cf744cd5bUL) /* 733 */ P( 6, 0xb10480ddb47b52cbUL, 0x0058ae97bab79976UL) /* 739 */ P( 4, 0x74cd59ed64f3f0d7UL, 0x0058345f1876865fUL) /* 743 */ P( 8, 0x0105cb81316d6c0fUL, 0x005743d5bb24795aUL) /* 751 */ P( 6, 0x9be64c6d91c1195dUL, 0x005692c4d1ab74abUL) /* 757 */ P( 4, 0x71b3f945a27b1f49UL, 0x00561e46a4d5f337UL) /* 761 */ P( 8, 0x77d80d50e508fd01UL, 0x005538ed06533997UL) /* 769 */ P( 4, 0xa5eb778e133551cdUL, 0x0054c807f2c0bec2UL) /* 773 */ P(14, 0x18657d3c2d8a3f1bUL, 0x005345efbc572d36UL) /* 787 */ P(10, 0x2e40e220c34ad735UL, 0x00523a758f941345UL) /* 797 */ P(12, 0xa76593c70a714919UL, 0x005102370f816c89UL) /* 809 */ P( 2, 0x1eef452124eea383UL, 0x0050cf129fb94acfUL) /* 811 */ P(10, 0x38206dc242ba771dUL, 0x004fd31941cafdd1UL) /* 821 */ P( 2, 0x4cd4c35807772287UL, 0x004fa1704aa75945UL) /* 823 */ P( 4, 0x83de917d5e69ddf3UL, 0x004f3ed6d45a63adUL) /* 827 */ P( 2, 0x882ef0403b4a6c15UL, 0x004f0de57154ebedUL) /* 829 */ P(10, 0xf8fb6c51c606b677UL, 0x004e1cae8815f811UL) /* 839 */ P(14, 0xb4abaac446d3e1fdUL, 0x004cd47ba5f6ff19UL) /* 853 */ P( 4, 0xa9f83bbe484a14e9UL, 0x004c78ae734df709UL) /* 857 */ P( 2, 0x0bebbc0d1ce874d3UL, 0x004c4b19ed85cfb8UL) /* 859 */ P( 4, 0xbd418eaf0473189fUL, 0x004bf093221d1218UL) /* 863 */ P(14, 0x44e3af6f372b7e65UL, 0x004aba3c21dc633fUL) /* 877 */ P( 4, 0xc87fdace4f9e5d91UL, 0x004a6360c344de00UL) /* 881 */ P( 2, 0xec93479c446bd9bbUL, 0x004a383e9f74d68aUL) /* 883 */ P( 4, 0xdac4d592e777c647UL, 0x0049e28fbabb9940UL) /* 887 */ P(20, 0xa63ea8c8f61f0c23UL, 0x0048417b57c78cd7UL) /* 907 */ P( 4, 0xe476062ea5cbbb6fUL, 0x0047f043713f3a2bUL) /* 911 */ P( 8, 0xdf68761c69daac27UL, 0x00474ff2a10281cfUL) /* 919 */ P(10, 0xb813d737637aa061UL, 0x00468b6f9a978f91UL) /* 929 */ P( 8, 0xa3a77aac1fb15099UL, 0x0045f13f1caff2e2UL) /* 937 */ P( 4, 0x17f0c3e0712c5825UL, 0x0045a5228cec23e9UL) /* 941 */ P( 6, 0xfd912a70ff30637bUL, 0x0045342c556c66b9UL) /* 947 */ P( 6, 0xfbb3b5dc01131289UL, 0x0044c4a23feeced7UL) /* 953 */ P(14, 0x856d560a0f5acdf7UL, 0x0043c5c20d3c9fe6UL) /* 967 */ P( 4, 0x96472f314d3f89e3UL, 0x00437e494b239798UL) /* 971 */ P( 6, 0xa76f5c7ed2253531UL, 0x0043142d118e47cbUL) /* 977 */ P( 6, 0x816eae7c7bf69fe7UL, 0x0042ab5c73a13458UL) /* 983 */ P( 8, 0xb6a2bea4cfb1781fUL, 0x004221950db0f3dbUL) /* 991 */ P( 6, 0xa3900c53318e81edUL, 0x0041bbb2f80a4553UL) /* 997 */ P(12, 0x60aa7f5d9f148d11UL, 0x0040f391612c6680UL) /* 1009 */ P( 4, 0x6be8c0102c7a505dUL, 0x0040b1e94173fefdUL) /* 1013 */ P( 6, 0x8ff3f0ed28728f33UL, 0x004050647d9d0445UL) /* 1019 */ P( 2, 0x680e0a87e5ec7155UL, 0x004030241b144f3bUL) /* 1021 */ P(10, 0xbbf70fa49fe829b7UL, 0x003f90c2ab542cb1UL) /* 1031 */ P( 2, 0xd69d1e7b6a50ca39UL, 0x003f71412d59f597UL) /* 1033 */ P( 6, 0x1a1e0f46b6d26aefUL, 0x003f137701b98841UL) /* 1039 */ P(10, 0x7429f9a7a8251829UL, 0x003e79886b60e278UL) /* 1049 */ P( 2, 0xd9c2219d1b863613UL, 0x003e5b1916a7181dUL) /* 1051 */ P(10, 0x91406c1820d077adUL, 0x003dc4a50968f524UL) /* 1061 */ P( 2, 0x521f4ec02e3d2b97UL, 0x003da6e4c9550321UL) /* 1063 */ P( 6, 0xbb8283b63dc8eba5UL, 0x003d4e4f06f1def3UL) /* 1069 */ P(18, 0x431eda153229ebbfUL, 0x003c4a6bdd24f9a4UL) /* 1087 */ P( 4, 0xaf0bf78d7e01686bUL, 0x003c11d54b525c73UL) /* 1091 */ P( 2, 0xa9ced0742c086e8dUL, 0x003bf5b1c5721065UL) /* 1093 */ P( 4, 0xc26458ad9f632df9UL, 0x003bbdb9862f23b4UL) /* 1097 */ P( 6, 0xbbff1255dff892afUL, 0x003b6a8801db5440UL) /* 1103 */ P( 6, 0xcbd49a333f04d8fdUL, 0x003b183cf0fed886UL) /* 1109 */ P( 8, 0xec84ed6f9cfdeff5UL, 0x003aabe394bdc3f4UL) /* 1117 */ P( 6, 0x97980cc40bda9d4bUL, 0x003a5ba3e76156daUL) /* 1123 */ P( 6, 0x777f34d524f5cbd9UL, 0x003a0c3e953378dbUL) /* 1129 */ P(22, 0x2797051d94cbbb7fUL, 0x0038f03561320b1eUL) /* 1151 */ P( 2, 0xea769051b4f43b81UL, 0x0038d6ecaef5908aUL) /* 1153 */ P(10, 0xce7910f3034d4323UL, 0x003859cf221e6069UL) /* 1163 */ P( 8, 0x92791d1374f5b99bUL, 0x0037f7415dc9588aUL) /* 1171 */ P(10, 0x89a5645cc68ea1b5UL, 0x00377df0d3902626UL) /* 1181 */ P( 6, 0x5f8aacf796c0cf0bUL, 0x00373622136907faUL) /* 1187 */ P( 6, 0xf2e90a15e33edf99UL, 0x0036ef0c3b39b92fUL) /* 1193 */ P( 8, 0x8e99e5feb897c451UL, 0x0036915f47d55e6dUL) /* 1201 */ P(12, 0xaca2eda38fb91695UL, 0x0036072cf3f866fdUL) /* 1213 */ P( 4, 0x5d9b737be5ea8b41UL, 0x0035d9b737be5ea8UL) /* 1217 */ P( 6, 0x4aefe1db93fd7cf7UL, 0x0035961559cc81c7UL) /* 1223 */ P( 6, 0xa0994ef20b3f8805UL, 0x0035531c897a4592UL) /* 1229 */ P( 2, 0x103890bda912822fUL, 0x00353ceebd3e98a4UL) /* 1231 */ P( 6, 0xb441659d13a9147dUL, 0x0034fad381585e5eUL) /* 1237 */ P(12, 0x1e2134440c4c3f21UL, 0x00347884d1103130UL) /* 1249 */ P(10, 0x263a27727a6883c3UL, 0x00340dd3ac39bf56UL) /* 1259 */ P(18, 0x78e221472ab33855UL, 0x003351fdfecc140cUL) /* 1277 */ P( 2, 0x95eac88e82e6faffUL, 0x00333d72b089b524UL) /* 1279 */ P( 4, 0xf66c258317be8dabUL, 0x0033148d44d6b261UL) /* 1283 */ P( 6, 0x09ee202c7cb91939UL, 0x0032d7aef8412458UL) /* 1289 */ P( 2, 0x8d2fca1042a09ea3UL, 0x0032c3850e79c0f1UL) /* 1291 */ P( 6, 0x82779c856d8b8bf1UL, 0x00328766d59048a2UL) /* 1297 */ P( 4, 0x3879361cba8a223dUL, 0x00325fa18cb11833UL) /* 1301 */ P( 2, 0xf23f43639c3182a7UL, 0x00324bd659327e22UL) /* 1303 */ P( 4, 0xa03868fc474bcd13UL, 0x0032246e784360f4UL) /* 1307 */ P(12, 0x651e78b8c5311a97UL, 0x0031afa5f1a33a08UL) /* 1319 */ P( 2, 0x8ffce639c00c6719UL, 0x00319c63ff398e70UL) /* 1321 */ P( 6, 0xf7b460754b0b61cfUL, 0x003162f7519a86a7UL) /* 1327 */ P(34, 0x7b03f3359b8e63b1UL, 0x0030271fc9d3fc3cUL) /* 1361 */ P( 6, 0xa55c5326041eb667UL, 0x002ff104ae89750bUL) /* 1367 */ P( 6, 0x647f88ab896a76f5UL, 0x002fbb62a236d133UL) /* 1373 */ P( 8, 0x8fd971434a55a46dUL, 0x002f74997d2070b4UL) /* 1381 */ P(18, 0x9fbf969958046447UL, 0x002ed84aa8b6fce3UL) /* 1399 */ P(10, 0x9986feba69be3a81UL, 0x002e832df7a46dbdUL) /* 1409 */ P(14, 0xa668b3e6d053796fUL, 0x002e0e0846857cabUL) /* 1423 */ P( 4, 0x97694e6589f4e09bUL, 0x002decfbdfb55ee6UL) /* 1427 */ P( 2, 0x37890c00b7721dbdUL, 0x002ddc876f3ff488UL) /* 1429 */ P( 4, 0x5ac094a235f37ea9UL, 0x002dbbc1d4c482c4UL) /* 1433 */ P( 6, 0x31cff775f2d5d65fUL, 0x002d8af0e0de0556UL) /* 1439 */ P( 8, 0xddad8e6b36505217UL, 0x002d4a7b7d14b30aUL) /* 1447 */ P( 4, 0x5a27df897062cd03UL, 0x002d2a85073bcf4eUL) /* 1451 */ P( 2, 0xe2396fe0fdb5a625UL, 0x002d1a9ab13e8be4UL) /* 1453 */ P( 6, 0xb352a4957e82317bUL, 0x002ceb1eb4b9fd8bUL) /* 1459 */ P(12, 0xd8ab3f2c60c2ea3fUL, 0x002c8d503a79794cUL) /* 1471 */ P(10, 0x6893f702f0452479UL, 0x002c404d708784edUL) /* 1481 */ P( 2, 0x9686fdc182acf7e3UL, 0x002c31066315ec52UL) /* 1483 */ P( 4, 0x6854037173dce12fUL, 0x002c1297d80f2664UL) /* 1487 */ P( 2, 0x7f0ded1685c27331UL, 0x002c037044c55f6bUL) /* 1489 */ P( 4, 0xeeda72e1fe490b7dUL, 0x002be5404cd13086UL) /* 1493 */ P( 6, 0x9e7bfc959a8e6e53UL, 0x002bb845adaf0cceUL) /* 1499 */ P(12, 0x49b314d6d4753dd7UL, 0x002b5f62c639f16dUL) /* 1511 */ P(12, 0x2e8f8c5ac4aa1b3bUL, 0x002b07e6734f2b88UL) /* 1523 */ P( 8, 0xb8ef723481163d33UL, 0x002ace569d8342b7UL) /* 1531 */ P(12, 0x6a2ec96a594287b7UL, 0x002a791d5dbd4dcfUL) /* 1543 */ P( 6, 0xdba41c6d13aab8c5UL, 0x002a4eff8113017cUL) /* 1549 */ P( 4, 0xc2adbe648dc3aaf1UL, 0x002a3319e156df32UL) /* 1553 */ P( 6, 0x87a2bade565f91a7UL, 0x002a0986286526eaUL) /* 1559 */ P( 8, 0x4d6fe8798c01f5dfUL, 0x0029d29551d91e39UL) /* 1567 */ P( 4, 0x3791310c8c23d98bUL, 0x0029b7529e109f0aUL) /* 1571 */ P( 8, 0xf80e446b01228883UL, 0x00298137491ea465UL) /* 1579 */ P( 4, 0x9aed1436fbf500cfUL, 0x0029665e1eb9f9daUL) /* 1583 */ P(14, 0x7839b54cc8b24115UL, 0x002909752e019a5eUL) /* 1597 */ P( 4, 0xc128c646ad0309c1UL, 0x0028ef35e2e5efb0UL) /* 1601 */ P( 6, 0x14de631624a3c377UL, 0x0028c815aa4b8278UL) /* 1607 */ P( 2, 0x3f7b9fe68b0ecbf9UL, 0x0028bb1b867199daUL) /* 1609 */ P( 4, 0x284ffd75ec00a285UL, 0x0028a13ff5d7b002UL) /* 1613 */ P( 6, 0x37803cb80dea2ddbUL, 0x00287ab3f173e755UL) /* 1619 */ P( 2, 0x86b63f7c9ac4c6fdUL, 0x00286dead67713bdUL) /* 1621 */ P( 6, 0x8b6851d1bd99b9d3UL, 0x002847bfcda6503eUL) /* 1627 */ P(10, 0xb62fda77ca343b6dUL, 0x002808c1ea6b4777UL) /* 1637 */ P(20, 0x1f0dc009e34383c9UL, 0x00278d0e0f23ff61UL) /* 1657 */ P( 6, 0x496dc21ddd35b97fUL, 0x002768863c093c7fUL) /* 1663 */ P( 4, 0xb0e96ce17090f82bUL, 0x0027505115a73ca8UL) /* 1667 */ P( 2, 0xaadf05acdd7d024dUL, 0x00274441a61dc1b9UL) /* 1669 */ P(24, 0xcb138196746eafb5UL, 0x0026b5c166113cf0UL) /* 1693 */ P( 4, 0x347f523736755d61UL, 0x00269e65ad07b18eUL) /* 1697 */ P( 2, 0xd14a48a051f7dd0bUL, 0x002692c25f877560UL) /* 1699 */ P(10, 0x474d71b1ce914d25UL, 0x002658fa7523cd11UL) /* 1709 */ P(12, 0x386063f5e28c1f89UL, 0x0026148710cf0f9eUL) /* 1721 */ P( 2, 0x1db7325e32d04e73UL, 0x002609363b22524fUL) /* 1723 */ P(10, 0xfef748d3893b880dUL, 0x0025d1065a1c1122UL) /* 1733 */ P( 8, 0x2f3351506e935605UL, 0x0025a48a382b863fUL) /* 1741 */ P( 6, 0x7a3637fa2376415bUL, 0x0025837190eccdbcUL) /* 1747 */ P( 6, 0x4ac525d2baa21969UL, 0x00256292e95d510cUL) /* 1753 */ P( 6, 0x3a11c16b42cd351fUL, 0x002541eda98d068cUL) /* 1759 */ P(18, 0x6c7abde0049c2a11UL, 0x0024e15087fed8f5UL) /* 1777 */ P( 6, 0x54dad0303e069ac7UL, 0x0024c18b20979e5dUL) /* 1783 */ P( 4, 0xebf1ac9fdfe91433UL, 0x0024ac7b336de0c5UL) /* 1787 */ P( 2, 0xfafdda8237cec655UL, 0x0024a1fc478c60bbUL) /* 1789 */ P(12, 0xdce3ff6e71ffb739UL, 0x002463801231c009UL) /* 1801 */ P(10, 0xbed5737d6286db1bUL, 0x0024300fd506ed33UL) /* 1811 */ P(12, 0xe479e431fe08b4dfUL, 0x0023f314a494da81UL) /* 1823 */ P( 8, 0x9dd9b0dd7742f897UL, 0x0023cadedd2fad3aUL) /* 1831 */ P(16, 0x8f09d7402c5a5e87UL, 0x00237b7ed2664a03UL) /* 1847 */ P(14, 0x9216d5c4d958738dUL, 0x0023372967dbaf1dUL) /* 1861 */ P( 6, 0xb3139ba11d34ca63UL, 0x00231a308a371f20UL) /* 1867 */ P( 4, 0x47d54f7ed644afafUL, 0x002306fa63e1e600UL) /* 1871 */ P( 2, 0x92a81d85cf11a1b1UL, 0x0022fd6731575684UL) /* 1873 */ P( 4, 0x754b26533253bdfdUL, 0x0022ea507805749cUL) /* 1877 */ P( 2, 0xbbe0efc980bfd467UL, 0x0022e0cce8b3d720UL) /* 1879 */ P(10, 0xc0d8d594f024dca1UL, 0x0022b1887857d161UL) /* 1889 */ P(12, 0x8238d43bcaac1a65UL, 0x00227977fcc49cc0UL) /* 1901 */ P( 6, 0x27779c1fae6175bbUL, 0x00225db37b5e5f4fUL) /* 1907 */ P( 6, 0xa746ca9af708b2c9UL, 0x0022421b91322ed6UL) /* 1913 */ P(18, 0x93f3cd9f389be823UL, 0x0021f05b35f52102UL) /* 1931 */ P( 2, 0x5cb4a4c04c489345UL, 0x0021e75de5c70d60UL) /* 1933 */ P(16, 0xbf6047743e85b6b5UL, 0x0021a01d6c19be96UL) /* 1949 */ P( 2, 0x61c147831563545fUL, 0x0021974a6615c81aUL) /* 1951 */ P(22, 0xedb47c0ae62dee9dUL, 0x00213767697cf36aUL) /* 1973 */ P( 6, 0x0a3824386673a573UL, 0x00211d9f7fad35f1UL) /* 1979 */ P( 8, 0xa4a77d19e575a0ebUL, 0x0020fb7d9dd36c18UL) /* 1987 */ P( 6, 0xa2bee045e066c279UL, 0x0020e2123d661e0eUL) /* 1993 */ P( 4, 0xc23618de8ab43d05UL, 0x0020d135b66ae990UL) /* 1997 */ P( 2, 0x266b515216cb9f2fUL, 0x0020c8cded4d7a8eUL) /* 1999 */ P( 4, 0xe279edd9e9c2e85bUL, 0x0020b80b3f43ddbfUL) /* 2003 */ P( 8, 0xd0c591c221dc9c53UL, 0x002096b9180f46a6UL) /* 2011 */ P( 6, 0x06da8ee9c9ee7c21UL, 0x00207de7e28de5daUL) /* 2017 */ P(10, 0x9dfebcaf4c27e8c3UL, 0x002054dec8cf1fb3UL) /* 2027 */ P( 2, 0x49aeff9f19dd6de5UL, 0x00204cb630b3aab5UL) /* 2029 */ P(10, 0x86976a57a296e9c7UL, 0x00202428adc37bebUL) /* 2039 */ P(14, 0xa3b9abf4872b84cdUL, 0x001fec0c7834def4UL) /* 2053 */ P(10, 0x34fca6483895e6efUL, 0x001fc46fae98a1d0UL) /* 2063 */ P( 6, 0x34b5a333988f873dUL, 0x001facda430ff619UL) /* 2069 */ P(12, 0xd9dd4f19b5f17be1UL, 0x001f7e17dd8e15e5UL) /* 2081 */ P( 2, 0xb935b507fd0ce78bUL, 0x001f765a3556a4eeUL) /* 2083 */ P( 4, 0xb450f5540660e797UL, 0x001f66ea49d802f1UL) /* 2087 */ P( 2, 0x63ff82831ffc1419UL, 0x001f5f3800faf9c0UL) /* 2089 */ P(10, 0x8992f718c22a32fbUL, 0x001f38f4e6c0f1f9UL) /* 2099 */ P(12, 0x5f3253ad0d37e7bfUL, 0x001f0b8546752578UL) /* 2111 */ P( 2, 0x007c0ffe0fc007c1UL, 0x001f03ff83f001f0UL) /* 2113 */ P(16, 0x4d8ebadc0c0640b1UL, 0x001ec853b0a3883cUL) /* 2129 */ P( 2, 0xe2729af831037bdbUL, 0x001ec0ee573723ebUL) /* 2131 */ P( 6, 0xb8f64bf30feebfe9UL, 0x001eaad38e6f6894UL) /* 2137 */ P( 4, 0xda93124b544c0bf5UL, 0x001e9c28a765fe53UL) /* 2141 */ P( 2, 0x9cf7ff0b593c539fUL, 0x001e94d8758c2003UL) /* 2143 */ P(10, 0xd6bd8861fa0e07d9UL, 0x001e707ba8f65e68UL) /* 2153 */ P( 8, 0x5cfe75c0bd8ab891UL, 0x001e53a2a68f574eUL) /* 2161 */ P(18, 0x43e808757c2e862bUL, 0x001e1380a56b438dUL) /* 2179 */ P(24, 0x90caa96d595c9d93UL, 0x001dbf9f513a3802UL) /* 2203 */ P( 4, 0x8fd550625d07135fUL, 0x001db1d1d58bc600UL) /* 2207 */ P( 6, 0x76b010a86e209f2dUL, 0x001d9d358f53de38UL) /* 2213 */ P( 8, 0xecc0426447769b25UL, 0x001d81e6df6165c7UL) /* 2221 */ P(16, 0xe381339caabe3295UL, 0x001d4bdf7fd40e30UL) /* 2237 */ P( 2, 0xd1b190a2d0c7673fUL, 0x001d452c7a1c958dUL) /* 2239 */ P( 4, 0xc3bce3cf26b0e7ebUL, 0x001d37cf9b902659UL) /* 2243 */ P( 8, 0x5f87e76f56c61ce3UL, 0x001d1d3a5791e97bUL) /* 2251 */ P(16, 0xc06c6857a124b353UL, 0x001ce89fe6b47416UL) /* 2267 */ P( 2, 0x38c040fcba630f75UL, 0x001ce219f3235071UL) /* 2269 */ P( 4, 0xd078bc4fbd533b21UL, 0x001cd516dcf92139UL) /* 2273 */ P( 8, 0xde8e15c5dd354f59UL, 0x001cbb33bd1c2b8bUL) /* 2281 */ P( 6, 0xca61d53d7414260fUL, 0x001ca7e7d2546688UL) /* 2287 */ P( 6, 0xb56bf5ba8eae635dUL, 0x001c94b5c1b3dbd3UL) /* 2293 */ P( 4, 0x44a72cb0fb6e3949UL, 0x001c87f7f9c241c1UL) /* 2297 */ P(12, 0x879839a714f45bcdUL, 0x001c6202706c35a9UL) /* 2309 */ P( 2, 0x02a8994fde5314b7UL, 0x001c5bb8a9437632UL) /* 2311 */ P(22, 0xb971920cf2b90135UL, 0x001c174343b4111eUL) /* 2333 */ P( 6, 0x8a8fd0b7df9a6e8bUL, 0x001c04d0d3e46b42UL) /* 2339 */ P( 2, 0xb31f9a84c1c6eaadUL, 0x001bfeb00fbf4308UL) /* 2341 */ P( 6, 0x92293b02823c6d83UL, 0x001bec5dce0b202dUL) /* 2347 */ P( 4, 0xeee77ff20fe5ddcfUL, 0x001be03444620037UL) /* 2351 */ P( 6, 0x0e1ea0f6c496c11dUL, 0x001bce09c66f6fc3UL) /* 2357 */ P(14, 0xfdf2d3d6f88ccb6bUL, 0x001ba40228d02b30UL) /* 2371 */ P( 6, 0xfa9d74a3457738f9UL, 0x001b9225b1cf8919UL) /* 2377 */ P( 4, 0xefc3ca3db71a5785UL, 0x001b864a2ff3f53fUL) /* 2381 */ P( 2, 0x8e2071718d0d6dafUL, 0x001b80604150e49bUL) /* 2383 */ P( 6, 0xbc0fdbfeb6cfabfdUL, 0x001b6eb1aaeaacf3UL) /* 2389 */ P( 4, 0x1eeab613e5e5aee9UL, 0x001b62f48da3c8ccUL) /* 2393 */ P( 6, 0x2d2388e90e9e929fUL, 0x001b516babe96092UL) /* 2399 */ P(12, 0x81dbafba588ddb43UL, 0x001b2e9cef1e0c87UL) /* 2411 */ P( 6, 0x52eebc51c4799791UL, 0x001b1d56bedc849bUL) /* 2417 */ P( 6, 0x1c6bc4693b45a047UL, 0x001b0c267546aec0UL) /* 2423 */ P(14, 0x06eee0974498874dUL, 0x001ae45f62024fa0UL) /* 2437 */ P( 4, 0xd85b7377a9953cb9UL, 0x001ad917631b5f54UL) /* 2441 */ P( 6, 0x4b6df412d4caf56fUL, 0x001ac83d18cb608fUL) /* 2447 */ P(12, 0x6b8afbbb4a053493UL, 0x001aa6c7ad8c063fUL) /* 2459 */ P( 8, 0xcc5299c96ac7720bUL, 0x001a90a7b1228e2aUL) /* 2467 */ P( 6, 0xadce84b5c710aa99UL, 0x001a8027c03ba059UL) /* 2473 */ P( 4, 0x9d673f5aa3804225UL, 0x001a7533289deb89UL) /* 2477 */ P(26, 0xe6541268efbce7f7UL, 0x001a2ed7ce16b49fUL) /* 2503 */ P(18, 0xfcf41e76cf5be669UL, 0x0019fefc0a279a73UL) /* 2521 */ P(10, 0x5c3eb5dc31c383cbUL, 0x0019e4b0cd873b5fUL) /* 2531 */ P( 8, 0x301832d11d8ad6c3UL, 0x0019cfcdfd60e514UL) /* 2539 */ P( 4, 0x2e9c0942f1ce450fUL, 0x0019c56932d66c85UL) /* 2543 */ P( 6, 0x97f3f2be37a39a5dUL, 0x0019b5e1ab6fc7c2UL) /* 2549 */ P( 2, 0xe8b7d8a9654187c7UL, 0x0019b0b8a62f2a73UL) /* 2551 */ P( 6, 0xb5d024d7da5b1b55UL, 0x0019a149fc98942cUL) /* 2557 */ P(22, 0xb8ba9d6e7ae3501bUL, 0x001969517ec25b85UL) /* 2579 */ P(12, 0xf50865f71b90f1dfUL, 0x00194b3083360ba8UL) /* 2591 */ P( 2, 0x739c1682847df9e1UL, 0x00194631f4bebdc1UL) /* 2593 */ P(16, 0xc470a4d842b90ed1UL, 0x00191e84127268fdUL) /* 2609 */ P( 8, 0x1fb1be11698cc409UL, 0x00190adbb543984fUL) /* 2617 */ P( 4, 0xd8d5512a7cd35d15UL, 0x001901130bd18200UL) /* 2621 */ P(12, 0xa5496821723e07f9UL, 0x0018e3e6b889ac94UL) /* 2633 */ P(14, 0xbcc8c6d7abaa8167UL, 0x0018c233420e1ec1UL) /* 2647 */ P(10, 0x52c396c95eb619a1UL, 0x0018aa5872d92bd6UL) /* 2657 */ P( 2, 0x6eb7e380878ec74bUL, 0x0018a5989945ccf9UL) /* 2659 */ P( 4, 0x3d5513b504537157UL, 0x00189c1e60b57f60UL) /* 2663 */ P( 8, 0x314391f8862e948fUL, 0x0018893fbc8690b9UL) /* 2671 */ P( 6, 0xdc0b17cfcd81f5ddUL, 0x00187b2bb3e1041cUL) /* 2677 */ P( 6, 0x2f6bea3ec89044b3UL, 0x00186d27c9cdcfb8UL) /* 2683 */ P( 4, 0xce13a05869f1b57fUL, 0x001863d8bf4f2c1cUL) /* 2687 */ P( 2, 0x7593474e8ace3581UL, 0x00185f33e2ad7593UL) /* 2689 */ P( 4, 0x07fc329295a05e4dUL, 0x001855ef75973e13UL) /* 2693 */ P( 6, 0xb05377cba4908d23UL, 0x001848160153f134UL) /* 2699 */ P( 8, 0xe7b2131a628aa39bUL, 0x001835b72e6f0656UL) /* 2707 */ P( 4, 0x9031dbed7de01527UL, 0x00182c922d83eb39UL) /* 2711 */ P( 2, 0x76844b1c670aa9a9UL, 0x0018280243c0365aUL) /* 2713 */ P( 6, 0x6a03f4533b08915fUL, 0x00181a5cd5898e73UL) /* 2719 */ P(10, 0x1dbca579db0a3999UL, 0x001803c0961773aaUL) /* 2729 */ P( 2, 0x002ffe800bffa003UL, 0x0017ff4005ffd001UL) /* 2731 */ P(10, 0x478ab1a3e936139dUL, 0x0017e8d670433edbUL) /* 2741 */ P( 8, 0x66e722bc4c5cc095UL, 0x0017d7066cf4bb5dUL) /* 2749 */ P( 4, 0x7a8f63c717278541UL, 0x0017ce285b806b1fUL) /* 2753 */ P(14, 0xdf6eee24d292bc2fUL, 0x0017af52cdf27e02UL) /* 2767 */ P(10, 0x9fc20d17237dd569UL, 0x0017997d47d01039UL) /* 2777 */ P(12, 0xcdf9932356bda2edUL, 0x00177f7ec2c6d0baUL) /* 2789 */ P( 2, 0x97b5e332e80f68d7UL, 0x00177b2f3cd00756UL) /* 2791 */ P( 6, 0x46eee26fd875e2e5UL, 0x00176e4a22f692a0UL) /* 2797 */ P( 4, 0x3548a8e65157a611UL, 0x001765b94271e11bUL) /* 2801 */ P( 2, 0xc288d03be9b71e3bUL, 0x001761732b044ae4UL) /* 2803 */ P(16, 0x8151186db38937abUL, 0x00173f7a5300a2bcUL) /* 2819 */ P(14, 0x7800b910895a45f1UL, 0x001722112b48be1fUL) /* 2833 */ P( 4, 0xaee0b024182eec3dUL, 0x001719b7a16eb843UL) /* 2837 */ P( 6, 0x96323eda173b5713UL, 0x00170d3c99cc5052UL) /* 2843 */ P( 8, 0x0ed0dbd03ae77c8bUL, 0x0016fcad7aed3bb6UL) /* 2851 */ P( 6, 0xf73800b7828dc119UL, 0x0016f051b8231ffdUL) /* 2857 */ P( 4, 0x1b61715ec22b7ca5UL, 0x0016e81beae20643UL) /* 2861 */ P(18, 0xa8533a991ead64bfUL, 0x0016c3721584c1d8UL) /* 2879 */ P( 8, 0x7f6c7290e46c2e77UL, 0x0016b34c2ba09663UL) /* 2887 */ P(10, 0x6325e8d907b01db1UL, 0x00169f3ce292ddcdUL) /* 2897 */ P( 6, 0x28909f70152a1067UL, 0x00169344b2220a0dUL) /* 2903 */ P( 6, 0xea7077af0997a0f5UL, 0x001687592593c1b1UL) /* 2909 */ P( 8, 0x7e605cad10c32e6dUL, 0x00167787f1418ec9UL) /* 2917 */ P(10, 0x471b33570635b38fUL, 0x001663e190395ff2UL) /* 2927 */ P(12, 0xab559fa997a61bb3UL, 0x00164c7a4b6eb5b3UL) /* 2939 */ P(14, 0xad4bdae562bddab9UL, 0x0016316a061182fdUL) /* 2953 */ P( 4, 0x055e1b2f2ed62f45UL, 0x001629ba914584e4UL) /* 2957 */ P( 6, 0x03cd328b1a2dca9bUL, 0x00161e3d57de21b2UL) /* 2963 */ P( 6, 0xd28f4e08733218a9UL, 0x001612cc01b977f0UL) /* 2969 */ P( 2, 0xb6800b077f186293UL, 0x00160efe30c525ffUL) /* 2971 */ P(28, 0x6fbd138c3fd9c207UL, 0x0015da45249ec5deUL) /* 2999 */ P( 2, 0xb117ccd12ae88a89UL, 0x0015d68ab4acff92UL) /* 3001 */ P(10, 0x2f1a1a044046bcebUL, 0x0015c3f989d1eb15UL) /* 3011 */ P( 8, 0x548aba0b060541e3UL, 0x0015b535ad11b8f0UL) /* 3019 */ P( 4, 0xcf4e808cea111b2fUL, 0x0015addb3f424ec1UL) /* 3023 */ P(14, 0xdbec1b4fa855a475UL, 0x00159445cb91be6bUL) /* 3037 */ P( 4, 0xe3f794eb600d7821UL, 0x00158d0199771e63UL) /* 3041 */ P( 8, 0x34fae0d9a11f7c59UL, 0x00157e87d9b69e04UL) /* 3049 */ P(12, 0xf006b0ccbbac085dUL, 0x001568f58bc01ac3UL) /* 3061 */ P( 6, 0x3f45076dc3114733UL, 0x00155e3c993fda9bUL) /* 3067 */ P(12, 0xeef49bfa58a1a1b7UL, 0x001548eacc5e1e6eUL) /* 3079 */ P( 4, 0x12c4218bea691fa3UL, 0x001541d8f91ba6a7UL) /* 3083 */ P( 6, 0xbc7504e3bd5e64f1UL, 0x00153747060cc340UL) /* 3089 */ P(20, 0x4ee21c292bb92fadUL, 0x001514569f93f7c4UL) /* 3109 */ P(10, 0x34338b7327a4bacfUL, 0x00150309705d3d79UL) /* 3119 */ P( 2, 0x3fe5c0833d6fccd1UL, 0x0014ff97020cf5bfUL) /* 3121 */ P(16, 0xb1e70743535203c1UL, 0x0014e42c114cf47eUL) /* 3137 */ P(26, 0xefbb5dcdfb4e43d3UL, 0x0014b835bdcb6447UL) /* 3163 */ P( 4, 0xca68467ca5394f9fUL, 0x0014b182b53a9ab7UL) /* 3167 */ P( 2, 0x8c51c081408b97a1UL, 0x0014ae2ad094a3d3UL) /* 3169 */ P(12, 0x3275a899dfa5dd65UL, 0x00149a320ea59f96UL) /* 3181 */ P( 6, 0x9e674cb62e1b78bbUL, 0x001490441de1a2fbUL) /* 3187 */ P( 4, 0xa37ff5bb2a998d47UL, 0x001489aacce57200UL) /* 3191 */ P(12, 0x792a999db131a22bUL, 0x001475f82ad6ff99UL) /* 3203 */ P( 6, 0x1b48841bc30d29b9UL, 0x00146c2cfe53204fUL) /* 3209 */ P( 8, 0xf06721d2011d3471UL, 0x00145f2ca490d4a1UL) /* 3217 */ P( 4, 0x93fd2386dff85ebdUL, 0x001458b2aae0ec87UL) /* 3221 */ P( 8, 0x4ce72f54c07ed9b5UL, 0x00144bcb0a3a3150UL) /* 3229 */ P(22, 0xd6d0fd3e71dd827bUL, 0x001428a1e65441d4UL) /* 3251 */ P( 2, 0x856405fb1eed819dUL, 0x00142575a6c210d7UL) /* 3253 */ P( 4, 0x8ea8aceb7c443989UL, 0x00141f2025ba5c46UL) /* 3257 */ P( 2, 0x34a13026f62e5873UL, 0x00141bf6e35420fdUL) /* 3259 */ P(12, 0x1eea0208ec0af4f7UL, 0x001409141d1d313aUL) /* 3271 */ P(28, 0x63679853cea598cbUL, 0x0013dd8bc19c3513UL) /* 3299 */ P( 2, 0xc30b3ebd61f2d0edUL, 0x0013da76f714dc8fUL) /* 3301 */ P( 6, 0x7eb9037bc7f43bc3UL, 0x0013d13e50f8f49eUL) /* 3307 */ P( 6, 0xa583e6f6ce016411UL, 0x0013c80e37ca3819UL) /* 3313 */ P( 6, 0xf1938d895f1a74c7UL, 0x0013bee69fa99ccfUL) /* 3319 */ P( 4, 0x80cf1491c1e81e33UL, 0x0013b8d0ede55835UL) /* 3323 */ P( 6, 0x3c0f12886ba8f301UL, 0x0013afb7680bb054UL) /* 3329 */ P( 2, 0x0e4b786e0dfcc5abUL, 0x0013acb0c3841c96UL) /* 3331 */ P(12, 0x672684c93f2d41efUL, 0x00139a9c5f434fdeUL) /* 3343 */ P( 4, 0xe00757badb35c51bUL, 0x0013949cf33a0d9dUL) /* 3347 */ P(12, 0xd6d84afe66472edfUL, 0x001382b4a00c31b0UL) /* 3359 */ P( 2, 0xfbbc0eedcbbfb6e1UL, 0x00137fbbc0eedcbbUL) /* 3361 */ P(10, 0x250f43aa08a84983UL, 0x001370ecf047b069UL) /* 3371 */ P( 2, 0x04400e927b1acaa5UL, 0x00136df9790e3155UL) /* 3373 */ P(16, 0x56572be34b9d3215UL, 0x0013567dd8defd5bUL) /* 3389 */ P( 2, 0x87964ef7781c62bfUL, 0x0013539261fdbc34UL) /* 3391 */ P(16, 0x29ed84051c06e9afUL, 0x00133c564292d28aUL) /* 3407 */ P( 6, 0xb00acd11ed3f87fdUL, 0x001333ae178d6388UL) /* 3413 */ P(20, 0x06307881744152d9UL, 0x0013170ad00d1fd7UL) /* 3433 */ P(16, 0x7a786459f5c1ccc9UL, 0x0013005f01db0947UL) /* 3449 */ P( 8, 0x1308125d74563281UL, 0x0012f51d40342210UL) /* 3457 */ P( 4, 0x395310a480b3e34dUL, 0x0012ef815e4ed950UL) /* 3461 */ P( 2, 0x35985baa8b202837UL, 0x0012ecb4abccd827UL) /* 3463 */ P( 4, 0x96304a6e052b3223UL, 0x0012e71dc1d3d820UL) /* 3467 */ P( 2, 0xbd8265fc9af8fd45UL, 0x0012e45389a16495UL) /* 3469 */ P(22, 0x1b6d0b383ec58e0bUL, 0x0012c5d9226476ccUL) /* 3491 */ P( 8, 0xc21a7c3b68b28503UL, 0x0012badc391156fdUL) /* 3499 */ P(12, 0x236fa180fbfd6007UL, 0x0012aa78e412f522UL) /* 3511 */ P( 6, 0xc42accd440ed9595UL, 0x0012a251f5f47fd1UL) /* 3517 */ P(10, 0x7acf7128236ba3f7UL, 0x001294cb85c53534UL) /* 3527 */ P( 2, 0xf909367a987b9c79UL, 0x0012921963beb65eUL) /* 3529 */ P( 4, 0xb64efb252bfba705UL, 0x00128cb777c69ca8UL) /* 3533 */ P( 6, 0x980d4f5a7e4cd25bUL, 0x001284aa6cf07294UL) /* 3539 */ P( 2, 0xe1ecc4ef27b0c37dUL, 0x001281fcf6ac7f87UL) /* 3541 */ P( 6, 0x9111aebb81d72653UL, 0x001279f937367db9UL) /* 3547 */ P(10, 0x8951f985cb2c67edUL, 0x00126cad0488be94UL) /* 3557 */ P( 2, 0xc439d4fc54e0b5d7UL, 0x00126a06794646a2UL) /* 3559 */ P(12, 0xe857bf31896d533bUL, 0x00125a2f2bcd3e95UL) /* 3571 */ P(10, 0xb614bb4cb5023755UL, 0x00124d108389e6b1UL) /* 3581 */ P( 2, 0x938a89e5473bf1ffUL, 0x00124a73083771acUL) /* 3583 */ P(10, 0xeac481aca34de039UL, 0x00123d6acda0620aUL) /* 3593 */ P(14, 0x14b961badf4809a7UL, 0x00122b4b2917eafdUL) /* 3607 */ P( 6, 0x76784fecba352435UL, 0x00122391bfce1e2fUL) /* 3613 */ P( 4, 0xefa689bb58aef5e1UL, 0x00121e6f1ea579f2UL) /* 3617 */ P( 6, 0xb2b2c4db9c3a8197UL, 0x001216c09e471568UL) /* 3623 */ P( 8, 0x2503bc992279f8cfUL, 0x00120c8cb9d93909UL) /* 3631 */ P( 6, 0xd2ab9aec5ca1541dUL, 0x001204ed58e64ef9UL) /* 3637 */ P( 6, 0x3e78ba1460f99af3UL, 0x0011fd546578f00cUL) /* 3643 */ P(16, 0x0a01426572cfcb63UL, 0x0011e9310b8b4c9cUL) /* 3659 */ P(12, 0xbea857968f3cbd67UL, 0x0011da3405db9911UL) /* 3671 */ P( 2, 0x78db213eefe659e9UL, 0x0011d7b6f4eb055dUL) /* 3673 */ P( 4, 0x963e8541a74d35f5UL, 0x0011d2bee748c145UL) /* 3677 */ P(14, 0x9e22d152776f2e43UL, 0x0011c1706ddce7a7UL) /* 3691 */ P( 6, 0x05d10d39d1e1f291UL, 0x0011ba0fed2a4f14UL) /* 3697 */ P( 4, 0x374468dccaced1ddUL, 0x0011b528538ed64aUL) /* 3701 */ P( 8, 0x8d145c7d110c5ad5UL, 0x0011ab61404242acUL) /* 3709 */ P(10, 0x3251a39f5acb5737UL, 0x00119f378ce81d2fUL) /* 3719 */ P( 8, 0xa66e50171443506fUL, 0x001195889ece79daUL) /* 3727 */ P( 6, 0x124f69ad91dd4cbdUL, 0x00118e4c65387077UL) /* 3733 */ P( 6, 0xec24f8f2a61a2793UL, 0x001187161d70e725UL) /* 3739 */ P(22, 0xb472148e656b7a51UL, 0x00116cd6d1c85239UL) /* 3761 */ P( 6, 0x0adf9570e1142f07UL, 0x001165bbe7ce86b1UL) /* 3767 */ P( 2, 0x89bf33b065119789UL, 0x0011635ee344ce36UL) /* 3769 */ P(10, 0x8f0149803cb291ebUL, 0x0011579767b6d679UL) /* 3779 */ P(14, 0x8334b63afd190a31UL, 0x00114734711e2b54UL) /* 3793 */ P( 4, 0x920908d50d6aba7dUL, 0x0011428b90147f05UL) /* 3797 */ P( 6, 0x57d8b018c5a33d53UL, 0x00113b92f3021636UL) /* 3803 */ P(18, 0xea1773092dc27ee5UL, 0x001126cabc886884UL) /* 3821 */ P( 2, 0xcae5f38b7bf2e00fUL, 0x0011247eb1b85976UL) /* 3823 */ P(10, 0x2bd02df34f695349UL, 0x0011190bb01efd65UL) /* 3833 */ P(14, 0xddfecd5be62e2eb7UL, 0x0011091de0fd679cUL) /* 3847 */ P( 4, 0xdbf849ebec96c4a3UL, 0x001104963c7e4e0bUL) /* 3851 */ P( 2, 0xda31d4d0187357c5UL, 0x00110253516420b0UL) /* 3853 */ P(10, 0xe34e21cc2d5418a7UL, 0x0010f70db7c41797UL) /* 3863 */ P(14, 0x68ca5137a9e574adUL, 0x0010e75ee2bf9ecdUL) /* 3877 */ P( 4, 0x3eaa0d0f804bfd19UL, 0x0010e2e91c6e0676UL) /* 3881 */ P( 8, 0x554fb753cc20e9d1UL, 0x0010da049b9d428dUL) /* 3889 */ P(18, 0x797afcca1300756bUL, 0x0010c6248fe3b1a2UL) /* 3907 */ P( 4, 0x8b8d950b52eeea77UL, 0x0010c1c03ed690ebUL) /* 3911 */ P( 6, 0xfb6cd166acabc185UL, 0x0010bb2e1379e3a2UL) /* 3917 */ P( 2, 0x4eb6c5ed9437a7afUL, 0x0010b8fe7f61228eUL) /* 3919 */ P( 4, 0xd1eddbd91b790cdbUL, 0x0010b4a10d60a4f7UL) /* 3923 */ P( 6, 0x93d714ea4d8948e9UL, 0x0010ae192681ec0fUL) /* 3929 */ P( 2, 0x3ca13ed8145188d3UL, 0x0010abecfbe5b0aeUL) /* 3931 */ P(12, 0x829086016da89c57UL, 0x00109eefd568b96dUL) /* 3943 */ P( 4, 0xd7da1f432124a543UL, 0x00109a9ff178b40cUL) /* 3947 */ P(20, 0x7ead5581632fb07fUL, 0x00108531e22f9ff9UL) /* 3967 */ P(22, 0x35443837f63ec3bdUL, 0x00106ddec1af4417UL) /* 3989 */ #undef FIRST_OMITTED_PRIME #define FIRST_OMITTED_PRIME 4001 gmp/src/bigintegerR.cc0000644000176200001440000011272414662137434014415 0ustar liggesusers/************************************************************/ /*! \file bigintegerR.cc * \brief C function to interface R and libgmp with big integer values * * \version 1 * * \date Created: 27/10/04 * \date Last modified: $Id: bigintegerR.cc,v 1.37 2014-09-16 07:33:43 mmaechler Exp $ * * \author Immanuel Scholz (help from A. Lucas) * * \note Licence: GPL (>= 2) */ #include #include #include #include "bigintegerR.h" #include "Rgmp.h" // only for ^ -|n| : #include "bigrationalR.h" #include "matrix.h" using namespace std; #include #include "extract_matrix.h" /* Globals variables */ static gmp_randstate_t seed_state; static int seed_init=0; namespace bigintegerR { // \brief create a vector of bigvecs, all without a modulus. bigvec create_vector(const SEXP & param) { lockSexp lock (param); switch (TYPEOF(param)) { case NILSXP: return bigvec(); // = bigz(0) case RAWSXP: { // deserialise the vector. first int is the size. bigvec v; const char* raw = (char*)RAW(param); int pos = sizeof(int); // position in raw[]. Starting after header. int sizevec = ((int*)raw)[0]; //std::cout << "nb element a lire " << sizevec << std::endl; v.resize(sizevec); for (int i = 0; i < sizevec; ++i) { v[i].setValue(make_shared(&raw[pos])); pos += v[i].getValue().raw_size(); // increment number of bytes read. } return v; } case REALSXP: { double* d = REAL(param); //bigvec v(d,d+LENGTH(param)); bigvec v; v.resize(LENGTH(param)); for (int j = 0; j < LENGTH(param); ++j) { /// New: numeric '+- Inf' give +- "Large" instead of NA double dj = d[j]; if(R_FINITE(dj) || ISNAN(dj)) v[j].setValue(make_shared( dj )); else { // dj is +- Inf : use LARGE ( = +- 2 ^ 80000 -- arbitrarily ) mpz_t LARGE; mpz_init(LARGE); // FIXME: Keep 'LARGE' a static const; initialized only once if(dj == R_PosInf){ mpz_ui_pow_ui (LARGE, (unsigned long int) 2, (unsigned long int) 8000); v[j].setValue(make_shared(LARGE)); } else if(dj == R_NegInf) { mpz_t neg_L; mpz_init(neg_L); mpz_neg(neg_L, LARGE); v[j].setValue( make_shared(neg_L)); mpz_clear(neg_L); } else// should never happen v[j].setValue( make_shared(dj)); mpz_clear(LARGE); } } return v; } case INTSXP: case LGLSXP: { int* i = INTEGER(param); //bigvec v(i,i+LENGTH(param)); bigvec v; v.resize(LENGTH(param)); for (int j = 0; j < LENGTH(param); ++j) v[j].setValue( make_shared(i[j])); return v; } case STRSXP: { bigvec v; v.resize(LENGTH(param)); for (int i = 0; i < LENGTH(param); ++i) { if (STRING_ELT(param,i) != NA_STRING) v[i].setValue(make_shared(std::string(CHAR(STRING_ELT(param,i))))); } return v; } default: // no longer: can be fatal later! return bigvec(); throw invalid_argument(_("only logical, numeric or character (atomic) vectors can be coerced to 'bigz'")); } } bigvec create_bignum(const SEXP & param) { lockSexp lock (param); SEXP modAttr = Rf_getAttrib(param, Rf_mkString("mod")), dimAttr = Rf_getAttrib(param, Rf_mkString("nrow")); // try to catch biz-nrow dimension value //std::cout << "import value" << std::endl; bigvec v = bigintegerR::create_vector(param); if (TYPEOF(dimAttr) == INTSXP){ v.nrow = INTEGER(dimAttr)[0]; } else { // catch to get std matrix dimensions value dimAttr = Rf_getAttrib(param, Rf_mkString("dim")); v.nrow = (TYPEOF(dimAttr) == INTSXP) ? INTEGER(dimAttr)[0] : -1;// -1: want support 0-row } if (TYPEOF(modAttr) != NILSXP) { //std::cout << "import value" << std::endl; bigvec vMod = bigintegerR::create_vector(modAttr); for (unsigned int i = 0 ; i < v.size(); i++){ v[i].setModulus(vMod[i % vMod.size()].getValuePtr()); } v.setType(vMod.size() == 1 ? TYPE_MODULUS::MODULUS_GLOBAL : TYPE_MODULUS::MODULUS_BY_CELL); } return v; } std::vector create_int(const SEXP & param) { lockSexp lock (param); switch (TYPEOF(param)) { case REALSXP: { double* d = REAL(param); // copy vector manually to avoid stupid conversion warning in STL-code :-/ vector v; for (int i = 0; i < LENGTH(param); ++i) v.push_back(static_cast(d[i])); return v; //return vector(d, d+LENGTH(param)); } case INTSXP: case LGLSXP: { int* i = INTEGER(param); return std::vector(i, i+LENGTH(param)); } default: return std::vector(); } } SEXP create_SEXP(const bigvec & v , bigmod_accessor_fn fct, unsigned int size) { unsigned int i; int sizeRaw = sizeof(int); // starting with vector-size-header for (i = 0; i < size; ++i) sizeRaw += fct(v[i]).raw_size(); // adding each bigint's needed size SEXP ans = PROTECT(Rf_allocVector(RAWSXP, sizeRaw)); // Rprintf(" o create_SEXP(vect): size=%d, v.size()=%d\n", size, v.size()); char* r = (char*)(RAW(ans)); ((int*)(r))[0] = size; // first int is vector-size-header int pos = sizeof(int); // current position in r[] (starting after vector-size-header) for (i = 0; i < size; ++i) pos += fct(v[i]).as_raw(&r[pos]); UNPROTECT(1); return(ans); } const biginteger & bigModToValue(const bigmod& v){ return v.getValue(); } const biginteger & bigModToModulus(const bigmod& v){ return v.getModulus(); } SEXP create_SEXP(const bigvec& v) { int size = v.size(); SEXP ans = PROTECT(create_SEXP(v, bigModToValue, size)); // set the class attribute to "bigz" Rf_setAttrib(ans, R_ClassSymbol, Rf_mkString("bigz")); // Rprintf(" o create_SEXP(): v.nrow=%d", v.nrow); // set the dim attribute if(v.nrow >= 0) { SEXP nrowAttr = Rf_mkString("nrow"); PROTECT(nrowAttr); SEXP nrowValue = Rf_ScalarInteger((int) v.nrow); PROTECT(nrowValue); Rf_setAttrib(ans, nrowAttr,nrowValue); UNPROTECT(2); } // set the mod attribute if(v.getType() != TYPE_MODULUS::NO_MODULUS && v.size() > 0 ) { int sizeM = v.getType() == TYPE_MODULUS::MODULUS_GLOBAL ? 1 : size; SEXP mod = PROTECT(create_SEXP(v, bigModToModulus, sizeM )); // and set *its* class Rf_setAttrib(mod, R_ClassSymbol, Rf_mkString("bigz")); Rf_setAttrib(ans, Rf_mkString("mod"), mod); UNPROTECT(1); } UNPROTECT(1); return ans; } SEXP biginteger_binary_operation(const bigvec& va,const bigvec& vb, biginteger_binary_fn f) { int size = (va.size() ==0 || vb.size()==0 ) ? 0 : max(va.size(), vb.size()); int nrow = matrixz::checkDims(va.nrow,vb.nrow); if(nrow == -2){ throw invalid_argument(_("Matrix dimensions do not match")); } bigvec result; for (int i = 0; i < size; ++i){ result.push_back(f(va[i%va.size()], vb[i%vb.size()])); } result.nrow = nrow; // Rprintf(" o bigI_b_op(.); size=%d -> nrow=%d\n", size, result.nrow); return bigintegerR::create_SEXP(result); } /** * \brief Main function of doing a binary operation on bigintegers. * It calls a function argument for doing the correct thing. * This could also be written as a class functor (template) * to save one function call, but then code bloat will happen. */ SEXP biginteger_binary_operation(const SEXP& a,const SEXP& b, biginteger_binary_fn f) { try { bigvec va = bigintegerR::create_bignum(a); bigvec vb = bigintegerR::create_bignum(b); return biginteger_binary_operation(va, vb, f); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_logical_binary_operation(const SEXP & a,const SEXP & b, biginteger_logical_binary_fn f) { try{ bigvec va = bigintegerR::create_bignum(a); bigvec vb = bigintegerR::create_bignum(b), result; int nrow = matrixz::checkDims(va.nrow,vb.nrow) ; if(nrow == -2){ va.clear(); vb.clear(); throw invalid_argument (_("Matrix dimensions do not match")); } int size = (va.size()==0 || vb.size() == 0) ? 0 : max(va.size(), vb.size()); // int sizemod = max(va.modulus.size(), vb.modulus.size()); SEXP ans = PROTECT(Rf_allocVector(LGLSXP, size)); int *r = LOGICAL(ans); /* TODO: this kind of situation 5 == (5 %% 17)*/ for (int i = 0; i < size; ++i) { biginteger & am = va[i % va.size()].getValue(); biginteger & bm = vb[i % vb.size()].getValue(); if (am.isNA() || bm.isNA()) r[i] = NA_LOGICAL; else r[i] = f(am, bm) ? 1 : 0; } // Add dimension parameter when available if(nrow >= 0) { SEXP dimVal; PROTECT(dimVal = Rf_allocVector(INTSXP, 2)); INTEGER(dimVal)[0] = (int) nrow; INTEGER(dimVal)[1] = (int) size / nrow; Rf_setAttrib(ans, Rf_mkString("dim"), dimVal); UNPROTECT(1); } UNPROTECT(1); return ans; }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } bool lt(const biginteger& lhs, const biginteger& rhs) {return mpz_cmp(lhs.getValueTemp(), rhs.getValueTemp()) < 0;} bool gt(const biginteger& lhs, const biginteger& rhs) {return mpz_cmp(lhs.getValueTemp(), rhs.getValueTemp()) > 0;} bool lte(const biginteger& lhs, const biginteger& rhs) {return mpz_cmp(lhs.getValueTemp(), rhs.getValueTemp()) <= 0;} bool gte(const biginteger& lhs, const biginteger& rhs) {return mpz_cmp(lhs.getValueTemp(), rhs.getValueTemp()) >= 0;} bool eq(const biginteger& lhs, const biginteger& rhs) {return mpz_cmp(lhs.getValueTemp(), rhs.getValueTemp()) == 0;} bool neq(const biginteger& lhs, const biginteger& rhs) {return mpz_cmp(lhs.getValueTemp(), rhs.getValueTemp()) != 0;} } /* End of namespace bigintegerR*/ SEXP R_gmp_get_version() { return Rf_mkString(gmp_version); } SEXP biginteger_add (SEXP a, SEXP b) {return bigintegerR::biginteger_binary_operation(a,b,operator+);} SEXP biginteger_sub (SEXP a, SEXP b) {return bigintegerR::biginteger_binary_operation(a,b,operator-);} SEXP biginteger_mul (SEXP a, SEXP b) {return bigintegerR::biginteger_binary_operation(a,b,operator*);} SEXP biginteger_divq(SEXP a, SEXP b) {return bigintegerR::biginteger_binary_operation(a,b,operator/);} SEXP biginteger_mod (SEXP a, SEXP b) {return bigintegerR::biginteger_binary_operation(a,b,operator%);} SEXP biginteger_div (SEXP a, SEXP b) { // called from "/.bigz" == div.bigz try{ bigvec A = bigintegerR::create_bignum(a), B = bigintegerR::create_bignum(b); // Note: a or b may be simple numbers (e.g. '1') => work with (A,B) TYPE_MODULUS type_a = A.getType(); TYPE_MODULUS type_b = B.getType(); if(type_a == TYPE_MODULUS::NO_MODULUS && type_b == TYPE_MODULUS::NO_MODULUS) // deal with important case quickly: { return bigrationalR::bigrational_binary_operation(bigrationalR::create_bignum(a), bigrationalR::create_bignum(b), operator/); } else if(type_a == TYPE_MODULUS::NO_MODULUS) { // and len_m_b > 0: // should work directly using b's "mod" --> compute a * b^(-1) } else if(type_b == TYPE_MODULUS::NO_MODULUS) { // and len_m_a > 0: // should use a's "mod" for b: div_via_inv() need's b's modulus if(type_a == TYPE_MODULUS::MODULUS_GLOBAL){ B.setGlobalModulus(A.getGlobalModulus()); } else{ for (unsigned int i = 0 ; i < B.size(); i++){ B[i].setModulus(A[i % A.size()].getModulusPtr()); } } return bigintegerR::biginteger_binary_operation(A, B, div_via_inv); } else { // len_m_a > 0 and len_m_b > 0: bool same_mod = true;// are the two mods the "same" (after recycling)? unsigned int len_m_a = A.getModulusSize(); unsigned int len_m_b = B.getModulusSize(); unsigned int m = (len_m_a < len_m_b) ? len_m_b : len_m_a; // = max(l..a, l..b) for(unsigned int i = 0; i < m; i++) if(A[i % len_m_a].getModulus() != B[i % len_m_b].getModulus()) { same_mod = false; break; } if(same_mod) { // compute a * b^(-1) ... should work w/o more } else { // use *rational* a/b (not considering 'mod' anymore): A.clear(); B.clear(); return bigrationalR::bigrational_binary_operation(bigrationalR::create_bignum(a), bigrationalR::create_bignum(b), operator/); } } return bigintegerR::biginteger_binary_operation(A,B, div_via_inv); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_pow (SEXP a, SEXP b) { try{ bigvec v = bigintegerR::create_bignum(a), exp = bigintegerR::create_bignum(b); if(v.getType() == TYPE_MODULUS::NO_MODULUS) { /* has no modulus: now, if any b < 0, the result must be (non-integer) bigrational */ bool use_rat = FALSE; for (unsigned int i = 0; i < exp.size(); ++i) { if(mpz_sgn(exp[i].getValue().getValueTemp()) < 0) { use_rat = TRUE; break; } } if (use_rat) { // a ^ b with some b negative --> rational result // 1) a := as.bigq(a, 1) SEXP one = Rf_ScalarInteger(1); PROTECT(one); SEXP aq = bigrational_as(a, one); PROTECT(aq); // 2) result = ^ b: SEXP ans = bigrational_pow(aq, b); UNPROTECT(2); return ans; } } // else, either, a has a modulus, or (no modulus *and* exp >= 0) : return bigintegerR::biginteger_binary_operation(a,b, pow); // -> pow() in ./bigmod.cc }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_inv (SEXP a, SEXP b) {return bigintegerR::biginteger_binary_operation(a,b,inv);} SEXP biginteger_gcd (SEXP a, SEXP b) {return bigintegerR::biginteger_binary_operation(a,b,gcd);} SEXP biginteger_lcm (SEXP a, SEXP b) {return bigintegerR::biginteger_binary_operation(a,b,lcm);} SEXP biginteger_as (SEXP a, SEXP mod){return bigintegerR::biginteger_binary_operation(a,mod,set_modulus);} // set_modulus : -> ./bigmod.cc SEXP biginteger_lt (SEXP a, SEXP b) {return bigintegerR::biginteger_logical_binary_operation(a,b,bigintegerR::lt);} SEXP biginteger_gt (SEXP a, SEXP b) {return bigintegerR::biginteger_logical_binary_operation(a,b,bigintegerR::gt);} SEXP biginteger_lte (SEXP a, SEXP b) {return bigintegerR::biginteger_logical_binary_operation(a,b,bigintegerR::lte);} SEXP biginteger_gte (SEXP a, SEXP b) {return bigintegerR::biginteger_logical_binary_operation(a,b,bigintegerR::gte);} SEXP biginteger_eq (SEXP a, SEXP b) {return bigintegerR::biginteger_logical_binary_operation(a,b,bigintegerR::eq);} SEXP biginteger_neq (SEXP a, SEXP b) {return bigintegerR::biginteger_logical_binary_operation(a,b,bigintegerR::neq);} SEXP biginteger_as_character(SEXP a, SEXP b) { try{ bigvec v = bigintegerR::create_bignum(a); SEXP ans; int base = Rf_asInteger(b); if (base < 2 || base > 36){ v.clear(); throw invalid_argument(_("select a base between 2 and 36")); } PROTECT(ans = Rf_allocVector(STRSXP, v.size())); for (unsigned int i = 0; i < v.size(); ++i) SET_STRING_ELT(ans, i, Rf_mkChar(v.str(i,base).c_str())); // matrix part if(v.nrow >= 0) { SEXP dim = PROTECT(Rf_allocVector(INTSXP, 2)); INTEGER(dim)[0] = v.nrow; INTEGER(dim)[1] = v.size() / v.nrow; Rf_setAttrib(ans, Rf_mkString("dim"), dim); UNPROTECT(1); } UNPROTECT(1); return ans; }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_as_numeric(SEXP a) { try{ bigvec v = bigintegerR::create_bignum(a); SEXP ans = PROTECT(Rf_allocVector(REALSXP,v.size())); double *r = REAL(ans); for (unsigned int i = 0; i < v.size(); ++i) r[i] = v[i].isNA() ? NA_REAL : v[i].getValue().as_double(); UNPROTECT(1); return ans; }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_as_integer(SEXP a) { try{ bigvec v = bigintegerR::create_bignum(a); SEXP ans = PROTECT(Rf_allocVector(INTSXP,v.size())); int *r = INTEGER(ans); for (unsigned int i = 0; i < v.size(); ++i) { if(v[i].isNA()) { r[i] = NA_INTEGER; } else if(!mpz_fits_slong_p(v[i].getValue().getValueTemp())) { Rf_warning("NAs introduced by coercion from big integer"); r[i] = NA_INTEGER; } else { r[i] = mpz_get_si(v[i].getValue().getValueTemp()); } } UNPROTECT(1); return ans; }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_get_at(SEXP a, SEXP i) { //result = a [i] try{ bigvec va = bigintegerR::create_bignum(a); return(bigintegerR::create_SEXP(bigintegerR::biginteger_get_at_C(va,i))); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // also called from matrix_get_at_z(.) in ./extract_matrix.cc : bigvec bigintegerR::biginteger_get_at_C(bigvec va, SEXP ind) { bigvec result; vector v_ind = extract_gmp_R::indice_get_at(va.size(),ind); for(unsigned int i = 0 ; i < v_ind.size(); i++){ int indice = v_ind[i]; if(indice < (int) va.size()){ result.push_back(va[indice]); } else { result.push_back(bigmod()); } } return (result); } SEXP biginteger_set_at(SEXP src, SEXP idx, SEXP value) { // return = ( src[idx] <- value ) try{ bigvec vvalue = bigintegerR::create_bignum(value); bigvec result = bigintegerR::create_bignum(src); vector vidx = extract_gmp_R::indice_get_at(result.size(),idx); if(vidx.size() == 0) { return bigintegerR::create_SEXP(result); } if(vvalue.size() == 0) { vvalue.clear(); result.clear(); throw invalid_argument(_("replacement has length zero")); } int pos = 0; for(unsigned int i = 0 ; i < vidx.size(); i++){ while(result.size() <=(unsigned int) (vidx[i] )) { result.push_back(bigmod()); } result.set(vidx[i],vvalue[pos++ % vvalue.size()]); } return bigintegerR::create_SEXP(result); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_length(SEXP a) { try{ return Rf_ScalarInteger(bigintegerR::create_bignum(a).size()); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_setlength(SEXP vec, SEXP value) { try{ int len = 0; switch (TYPEOF(value)) { case INTSXP: case LGLSXP: if (LENGTH(value) != 1) Rf_error("%s",_("invalid second argument")); len = Rf_asInteger(value); if (len < 0) Rf_error("%s",_("vector size cannot be negative")); else if (len == NA_INTEGER) Rf_error("%s",_("vector size cannot be NA")); break; case REALSXP: if (LENGTH(value) != 1) Rf_error("%s",_("invalid second argument")); len = (int)*REAL(value); if (len < 0) Rf_error("%s",_("vector size cannot be negative")); else if (! (R_FINITE (len ) )) Rf_error("%s",_("vector size cannot be NA, NaN of Inf")); break; case STRSXP: // dunno why R spits out this strange error on "length(foo) <- -1" // but I always follow the holy standard ;-) Rf_error("%s",_("negative length vectors are not allowed")); default: Rf_error("%s",_("invalid second argument")); } bigvec v =bigintegerR::create_bignum(vec); v.resize(len); return bigintegerR::create_SEXP(v); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_is_na(SEXP a) { try{ bigvec v = bigintegerR::create_bignum(a); SEXP ans = PROTECT(Rf_allocVector(LGLSXP, v.size())); for (unsigned int i = 0; i < v.size(); ++i) LOGICAL(ans)[i] = v[i].getValue().isNA(); UNPROTECT(1); return ans; }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_sgn(SEXP a) { try{ bigvec v = bigintegerR::create_bignum(a); SEXP ans = PROTECT(Rf_allocVector(INTSXP, v.size())); int *r = INTEGER(ans); for (unsigned int i = 0; i < v.size(); ++i) r[i] = mpz_sgn(v[i].getValue().getValueTemp()); UNPROTECT(1); return ans; }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_c(SEXP args) { try{ // if(TYPEOF(args) != VECSXP) Rf_error("%s","%s",_("should be a list")); bigvec result; for(int i=0; i < LENGTH(args); i++) { bigvec v = bigintegerR::create_bignum(VECTOR_ELT(args,i)); for(unsigned int j=0; j < v.size(); j++){ result.push_back(v[j]); } v.clear(); } return bigintegerR::create_SEXP(result); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_rep(SEXP x, SEXP times) { try{ bigvec v = bigintegerR::create_bignum(x), result; int rep = Rf_asInteger(times); for(int i = 0 ; i < rep ; i++) for(unsigned int j = 0 ; j < v.size() ; j++) result.push_back(v[j]); return bigintegerR::create_SEXP(result); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_is_prime(SEXP a, SEXP reps) { try{ bigvec v = bigintegerR::create_bignum(a); vector vb = bigintegerR::create_int(reps); unsigned int i; SEXP ans = PROTECT(Rf_allocVector(INTSXP, v.size())); int *r = INTEGER(ans); if(v.size() == vb.size()) for (i = 0; i < v.size(); ++i) r[i] = v[i].getValue().isprime(vb[i]); else for (i = 0; i < v.size(); ++i) r[i] = v[i].getValue().isprime(vb[0]); UNPROTECT(1); return ans; }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_nextprime(SEXP a) { try{ bigvec v = bigintegerR::create_bignum(a), result; mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); // result.reserve(v.size()); for (unsigned int i = 0; i < v.size(); ++i) { mpz_nextprime(val,v[i].getValue().getValueTemp()); result.push_back(bigmod(val)); } return bigintegerR::create_SEXP(result); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_abs(SEXP a) { try{ bigvec v = bigintegerR::create_bignum(a), result; mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); for (unsigned int i = 0; i < v.size(); ++i) { mpz_abs(val,v[i].getValue().getValueTemp()); result.push_back(bigmod(make_shared(val),v[i].getModulusPtr())); } return bigintegerR::create_SEXP(result); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } /** @brief Bezoult coefficients: compute g,s and t as as + bt = g * @param a BigInteger * @param b BigInteger */ SEXP biginteger_gcdex(SEXP a, SEXP b) { try{ bigvec va = bigintegerR::create_bignum(a), vb = bigintegerR::create_bignum(b), result; if(va.size() != vb.size()) return bigintegerR::create_SEXP(bigvec()); mpz_t g; mpz_t s; mpz_t t; mpz_init(g); mpz_init(s); mpz_init(t); mpz_t_sentry val_g(g); mpz_t_sentry val_s(s); mpz_t_sentry val_t(t); shared_ptr mod = make_shared(); // NA for(unsigned int i=0; i < va.size(); i++) { mpz_gcdext (g,s,t,va[i].getValue().getValueTemp(),vb[i].getValue().getValueTemp()); result.push_back(bigmod(make_shared(g))); result.push_back(bigmod(make_shared(s))); result.push_back(bigmod(make_shared(t))); } return bigintegerR::create_SEXP(result); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } /** @brief Random number generation \note If seed is not initialised: generation of a new seed @param nb Integer: number of number to generate @param length Integer number will be of length 2^length @param newseed Integer, seed initialisation (if exists) @param ok Integer 1: seed generation 0 not */ SEXP biginteger_rand_u (SEXP nb, SEXP length, SEXP newseed, SEXP ok) { try{ mpz_t bz; int i,flag,len,size; bigvec result; //extern int seed_init; //extern gmp_randstate_t seed_state; /* store input data into appropriate mode */ bigvec va = bigintegerR::create_bignum(newseed); PROTECT (ok = AS_INTEGER(ok)); PROTECT (length = AS_INTEGER(length)); PROTECT (nb = AS_INTEGER(nb)); flag = Rf_asInteger(ok); len = Rf_asInteger(length); size = Rf_asInteger(nb); UNPROTECT(3); /* Random seed initialisation */ if(seed_init==0) { gmp_randinit_default(seed_state); Rprintf("Seed default initialisation\n"); } if(flag == 1) { gmp_randseed(seed_state,va[0].getValue().getValueTemp()); Rprintf("Seed initialisation\n"); } seed_init = 1; mpz_init (bz); mpz_t_sentry val_s(bz); for(i= 0; i= 0) { mpz_fac_ui(result[i].getValue().getValue(), (unsigned long int)nn[i]); } } return bigintegerR::create_SEXP(result); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // bigI_factorial /** @brief bigI_choose(n, k) returns binomial coefficient (n \choose k) * @param n integer, either R "integer" (non-negative), or a "bigz" * @param k non-negative integer */ SEXP bigI_choose(SEXP n, SEXP k) { try{ bigvec result, n_ = bigintegerR::create_bignum(n); int *kk = INTEGER(AS_INTEGER(k)), n_k = Rf_length(k); int size = (n_.size() == 0 || n_k == 0) ? 0 : // else: max(n_.value.size(), n_k) (((int)n_.size() <= n_k) ? n_k : n_.size()); result.resize(size); // if(n_.getType() == MODULUS_GLOBAL){ // result.setGlobalModulus(n_.getGlobalModulus()); //} for (int i = 0; i < size; ++i) { result[i].getValue().NA(false); int ik_i = kk[i % n_k]; // check if k in range: if(ik_i != NA_INTEGER && ik_i >= 0) { unsigned long int k_i = (unsigned long int)ik_i; /* void mpz_bin_ui (mpz_t ROP, mpz_t N, unsigned long int K) */ mpz_bin_ui(result[i].getMpValue(), n_[i % n_.size()].getValueTemp(), k_i); } } return bigintegerR::create_SEXP(result); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } /** @brief fibnum return nth Fibonacci number * @param n integer */ SEXP bigI_fibnum(SEXP n) { try{ bigvec result; if(Rf_length(n) > 0) { int nn = Rf_asInteger(n); unsigned long int num = nn; if(nn < 0 || nn == NA_INTEGER) throw invalid_argument (_("argument must be non-negative")); mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); mpz_fib_ui(val,num); result.push_back(bigmod(val)); // result[0].value.setValue(val); } // else // Rf_error("%s","%s",_("argument must not be an empty list")); return bigintegerR::create_SEXP(result); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); } return Rf_mkString(0); } /** @brief fibnum2 return nth and n-1th Fibonacci number * @param n integer */ SEXP bigI_fibnum2(SEXP n) { try{ bigvec result; if(Rf_length(n) > 0) { int nn = Rf_asInteger(n); unsigned long int num = nn; if(nn < 0 || nn == NA_INTEGER) throw invalid_argument(_("argument must be non-negative")); mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); mpz_t val2; mpz_init(val2); mpz_t_sentry val_s2(val2); mpz_fib2_ui(val,val2, num); result.push_back(bigmod(val2)); result.push_back(bigmod(val)); } else throw invalid_argument(_("argument must not be an empty list")); return bigintegerR::create_SEXP(result); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } /** @brief lucnum return nth lucas number * @param n integer */ SEXP bigI_lucnum(SEXP n) { try{ bigvec result; if(Rf_length(n) > 0) { int nn = Rf_asInteger(n); unsigned long int num = nn; if(nn < 0 || nn == NA_INTEGER) throw invalid_argument(_("argument must be non-negative")); mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); mpz_lucnum_ui(val,num); result.push_back(bigmod(val)); } // else // Rf_error("%s","%s",_("argument must not be an empty list")); return bigintegerR::create_SEXP(result); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } /** @brief lucnum2 return nth and n-1th lucas number * @param n integer */ SEXP bigI_lucnum2(SEXP n) { try{ bigvec result; if(Rf_length(n) > 0) { int nn = Rf_asInteger(n); unsigned long int num = nn; if(nn < 0 || nn == NA_INTEGER) throw invalid_argument(_("argument must be non-negative")); mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); mpz_t val2; mpz_init(val2); mpz_t_sentry val_s2(val2); mpz_lucnum2_ui(val,val2,num); result.push_back(bigmod(val2)); result.push_back(bigmod(val)); } else throw invalid_argument(_("argument must not be an empty list")); return bigintegerR::create_SEXP(result); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } //Return max SEXP biginteger_max(SEXP a, SEXP narm) { try{ bigvec result; bigvec va = bigintegerR::create_bignum(a); if( ! va.size()) return bigintegerR::create_SEXP(result); unsigned int maximum = 0; int na_remove = Rf_asInteger(narm); for(unsigned int i = 1 ; i < va.size(); ++i) { if(va[i].isNA() && !na_remove) return(bigintegerR::create_SEXP(result)); else if(va[i].getValue() > va[maximum].getValue() ) maximum = i; // if va.value[maximum = 0] is NA => false for the "<" => maximum changed = good } result.push_back(va[maximum]); if(va.getType() == TYPE_MODULUS::MODULUS_BY_CELL) result[0].getModulus().NA(TRUE); return(bigintegerR::create_SEXP(result)); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // Return min SEXP biginteger_min(SEXP a, SEXP narm) { try{ bigvec result; bigvec va = bigintegerR::create_bignum(a); if( ! va.size()) return bigintegerR::create_SEXP(result); unsigned int minimum = 0; int na_remove = Rf_asInteger(narm); for(unsigned int i = 1 ; i < va.size(); ++i) { if(va[i].isNA() && !na_remove) return bigintegerR::create_SEXP(result); else if(va[i].getValue() < va[minimum].getValue() ) minimum = i; } result.push_back(va[minimum]); // now the modulus ! if(va.getType() == TYPE_MODULUS::MODULUS_BY_CELL) result[0].getModulus().NA(TRUE); return bigintegerR::create_SEXP(result); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_cumsum(SEXP a) { try{ bigvec result, va = bigintegerR::create_bignum(a); result.resize(va.size()); mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); bool hasmodulus = va.getType() == TYPE_MODULUS::MODULUS_GLOBAL; for(unsigned int i = 0 ; i < va.size(); ++i) { { if(va[i].isNA() ) { break; // all last values are NA. } mpz_add(val,val,va[i].getValue().getValueTemp()); if(hasmodulus){ mpz_mod(val,val,va.getGlobalModulus()->getValueTemp() ); result[i].setModulus(va.getGlobalModulus()); } result[i].getValue().setValue(val); } } return(bigintegerR::create_SEXP(result)); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_sum(SEXP a) { try{ bigvec result, va = bigintegerR::create_bignum(a); result.resize(1); mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); bool hasmodulus = va.getType() == TYPE_MODULUS::MODULUS_GLOBAL; for(unsigned int i = 0 ; i < va.size(); ++i) { { if(va[i].isNA() ) { break; // all last values are NA. } mpz_add(val,val,va[i].getValueTemp()); if(hasmodulus) mpz_mod(val,val,va.getGlobalModulus()->getValueTemp() ); } } result[0].setValue(val); if(hasmodulus) result[0].setModulus(va.getGlobalModulus()); return(bigintegerR::create_SEXP(result)); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP biginteger_prod(SEXP a) { try{ bigvec result; bigvec va = bigintegerR::create_bignum(a); result.resize(1); mpz_t val; mpz_init(val); mpz_set_ui(val,1); mpz_t_sentry val_s(val); bool hasmodulus = va.getType() == TYPE_MODULUS::MODULUS_GLOBAL; for(unsigned int i = 0 ; i < va.size(); ++i) { if(va[i].isNA() ) { return (bigintegerR::create_SEXP(result)); } mpz_mul(val,val,va[i].getValue().getValueTemp()); if(hasmodulus) mpz_mod(val,val,va.getGlobalModulus()->getValueTemp() ); } result[0].setValue(val); if(hasmodulus) result[0].setModulus(va.getGlobalModulus()); return(bigintegerR::create_SEXP(result)); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // return x ^ y [n] SEXP biginteger_powm(SEXP x, SEXP y, SEXP n) { try{ bigvec result; bigvec vx = bigintegerR::create_bignum(x); bigvec vy = bigintegerR::create_bignum(y); bigvec vn = bigintegerR::create_bignum(n); result.resize(vx.size()); // this cause pb to package // homeomopheR result.setGlobalModulus(vn[0].getValuePtr()); // ... for (unsigned int i = 0 ; i < vx.size(); i++) { result[i].getValue().NA(false); // check if n != 0 if(mpz_sgn(vn[i % vn.size()].getValueTemp()) != 0) mpz_powm(result[i].getMpValue(), vx[i].getValue().getValueTemp(), vy[i % vy.size()].getValueTemp(), vn[i % vn.size()].getValueTemp()); } return bigintegerR::create_SEXP(result); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // ..._powm() // TODO: A version that only returns 'ex' {i.e. the binary precision} // ---- GMP manual suggests that size_t mpz_sizeinbase (mpz_t OP, int BASE) // i.e., mpz_sizeinbase (OP, 2) would give that // (d, ex) where x = d * 2^ex, and 0.5 <= |d| < 1 SEXP bigI_frexp(SEXP x) { // double mpz_get_d_2exp (signed long int *exp, mpz t op ) // Convert op to a double, truncating if necessary (ie. rounding towards zero), and returning // the exponent separately. // The return value is in the range 0.5 ≤ |d| < 1 and the exponent is stored to *exp . d ∗ 2exp is // the (truncated) op value. If op is zero, the return is 0.0 and 0 is stored to *exp . // This is similar to the standard C frexp function. bigvec vx; try{ vx = bigintegerR::create_bignum(x); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); } const char *nms[] = {"d", "exp", ""}; SEXP ans, d_R, exp_R; int n = vx.size(); PROTECT(ans = Rf_mkNamed(VECSXP, nms)); // =~= R list(d = . , exp= .) d_R = Rf_allocVector(REALSXP, n); SET_VECTOR_ELT(ans, 0, d_R); exp_R = Rf_allocVector(INTSXP, n); SET_VECTOR_ELT(ans, 1, exp_R); double *d_ = REAL(d_R); int *exp_ = INTEGER(exp_R); try{ for (int i = 0 ; i < n; i++) { signed long int ex; d_[i] = mpz_get_d_2exp(&ex, vx[i].getValueTemp()); if(abs(ex) < INT_MAX){ exp_[i] = (int) ex; } else{ vx.clear(); throw invalid_argument(_("exponent too large to fit into an integer")); } } }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); } UNPROTECT(1); return ans; } // bigI_frexp() SEXP biginteger_log2(SEXP x) { bigvec v; try{ v = bigintegerR::create_bignum(x); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); } SEXP ans = PROTECT(Rf_allocVector(REALSXP,v.size())); double *r = REAL(ans); for (unsigned int i = 0; i < v.size(); ++i) { signed long int ex; double di = mpz_get_d_2exp(&ex, v[i].getValueTemp()); // xi = di * 2 ^ ex ==> log2(xi) = log2(di) + ex : r[i] = log(di) / M_LN2 + (double)ex; } UNPROTECT(1); return ans; } SEXP biginteger_log(SEXP x) { bigvec v ; try{ v = bigintegerR::create_bignum(x); }catch(std::invalid_argument & e){ Rf_error("%s",e.what()); } SEXP ans = PROTECT(Rf_allocVector(REALSXP,v.size())); double *r = REAL(ans); for (unsigned int i = 0; i < v.size(); ++i) { signed long int ex; double di = mpz_get_d_2exp(&ex, v[i].getValueTemp()); // xi = di * 2 ^ ex ==> log(xi) = log(di) + ex*log(2) : r[i] = log(di) + M_LN2*(double)ex; } UNPROTECT(1); return ans; } gmp/src/factorize.h0000644000176200001440000000044314444267421013774 0ustar liggesusers#ifndef FACTORIZE_GMP_R #define FACTORIZE_GMP_R 1 #include "bigvec.h" /** * Factorize a prime number * t: number to factorize * factors [out]: the list of factors * * Note: this is adapted from demo "factorize.c" file from gmplib */ void factor (mpz_t t, bigvec & factors); #endif gmp/src/bigmod.h0000644000176200001440000001563514444267421013260 0ustar liggesusers/*! \file bigmod.h * \brief Description of class bigmod * * \date Created: 22/05/06 * \date Last modified: Time-stamp: <2023-01-24 19:36:06 (antoine)> * * \author Immanuel Scholz * * \note Licence: GPL (>= 2) */ #ifndef BIGMOD_HEADER_ #define BIGMOD_HEADER_ 1 #include #include "biginteger.h" typedef void (*gmp_binary)(mpz_t, const mpz_t, const mpz_t); extern "C" { /** * division * result = a / b */ void integer_div(mpz_t result,const mpz_t a, const mpz_t b); } /** * \brief class for bigmod values. Represent any integer in Z/nZ * * Represents two biginteger: a value and a modulus. These both are used * to operate arithmetic functions on it. If the modulus is NA, no modulus * to the operation result is applied. If the value is NA, the result is always NA. */ class bigmod { private: /** \brief Value of our bigmod */ std::shared_ptr value; /** \brief modulus of our bigmod representation: value %% modulus */ std::shared_ptr modulus; public: /** keep both pointers value / modulus */ bigmod(biginteger * value_, biginteger * modulus_) : value(value_), modulus(modulus_) {}; /** keep references value / modulus is new object. */ bigmod(biginteger* value_) : value(value_), modulus(std::make_shared()) {}; /** * create 2 new objects valus / modulus. */ bigmod(const biginteger& value_, const biginteger& modulus_) : value(std::make_shared(value_)), modulus(std::make_shared(modulus_)) {}; bigmod(const biginteger& value_) : value(std::make_shared(value_)), modulus(std::make_shared()) {}; bigmod() : value(std::make_shared()), modulus(std::make_shared()) {}; bigmod(std::shared_ptr value_, std::shared_ptr modulus_ ) : value(), modulus() { value = value_; modulus = modulus_; }; bigmod(std::shared_ptr value_ ) : value(), modulus(std::make_shared()) { value = value_; }; /** \brief copy operator */ bigmod(const bigmod & rhs) : value(), modulus() { value = rhs.value; modulus = rhs.modulus; }; virtual ~bigmod(){ }; /** * \brief Return as a human readible string */ std::string str(int b) const; /** \brief assignement operator */ bigmod & operator= (const bigmod& rhs); /** \brief return sign (-1 if negative, 0 if 0; +1 if positive) */ inline int sgn() const { return(mpz_sgn(getValue().getValueTemp())); } bigmod inv () const; inline biginteger & getValue() { return *value; } inline mpz_t & getMpValue() { return value->getValue(); } inline const mpz_t& getValueTemp() const { return value->getValueTemp(); } biginteger & getModulus() { return *modulus; } inline bool isNA(){ return value->isNA(); } std::shared_ptr & getValuePtr() { return value; } const std::shared_ptr & getModulusPtr() const { return modulus; } inline void setValue(const std::shared_ptr & v){ value = v; } inline void setValue(const bigmod & v){ value = std::make_shared(v.getValue()); modulus = std::make_shared(v.getModulus()); } inline void setValue( bigmod & v){ value = v.getValuePtr(); modulus = v.getModulusPtr(); } inline void setValue(const mpz_t & v){ value->setValue(v); } inline void setValue(int v){ value->setValue(v); } inline void setValue(double v){ value->setValue(v); } inline void setValue(){ value->setValue(); modulus->setValue(); } inline void setModulus(const std::shared_ptr & v){ modulus = v; } const biginteger & getValue() const{ return *value; } const biginteger & getModulus() const { return *modulus; } }; /** \brief comparison operator */ bool operator!= (const bigmod& rhs, const bigmod& lhs); /** \brief comparison operator */ bool operator== (const bigmod& rhs, const bigmod& lhs); /** * \brief Add two bigmods together. * * If only one has a modulus set, the result will have this * modulus. If both bigmods disagree with the modulus, the result will not have * a modulus set. If none modulus for either bigmod is set, the result will not * have a modulus as well. */ bigmod operator+(const bigmod& rhs, const bigmod& lhs); /** * \brief Subtract two bigmods. * * For modulus description, see operator+(bigmod, bigmod) */ bigmod operator-(const bigmod& rhs, const bigmod& lhs); /** * \brief Multiply two bigmods. * * For modulus description, see operator+(bigmod, bigmod) */ bigmod operator*(const bigmod& rhs, const bigmod& lhs); /** * \brief Divide two bigmods a / b := a * b^(-1) */ bigmod div_via_inv(const bigmod& a, const bigmod& b); /** * \brief Divide two bigmods. * * For modulus description, see operator+(bigmod, bigmod) */ bigmod operator/(const bigmod& rhs, const bigmod& lhs); /** * \brief Calculate the modulus (remainder) of two bigmods. * * The resulting bigmod will have set the intern modulus to * the value of lhs, no matter what rhs.modulus or lhs.modulus * was before, except if rhs and lhs has both no modulus set, * in which case the resulting modulus will be unset too. */ bigmod operator%(const bigmod& rhs, const bigmod& lhs); /** * \brief Return the power of "exp" to the base of "base" (return = base^exp). * * If both moduli are unset or unequal, this may EAT your memory alive, * since then the infinite "pow" is used instead of the modulus "powm". * You may not try to pow a value this way with an exponent that does * not fit into a long value. * * For other modulus description, see operator+(bigmod, bigmod) */ bigmod pow(const bigmod& base, const bigmod& exp); /** * \brief Return the modulo inverse to x mod m. (return = x^-1 % m) * * For modulus description, see operator+(bigmod, bigmod) */ bigmod inv(const bigmod& x, const bigmod& m); /** * \brief Return a bigmod with value (x % m) and the intern modulus set to m. * Intern modulus settings of x and m are ignored. * * Do not confuse this with operator%(bigmod, bigmod). */ bigmod set_modulus(const bigmod& x, const bigmod& m); biginteger get_modulus(const bigmod& b1, const bigmod& b2); /** * \brief Return the greatest common divisor of both parameters * * For modulus description, see operator+(bigmod, bigmod) */ bigmod gcd(const bigmod& rhs, const bigmod& lhs); /** * \brief Return the least common multiply of both parameter. * * For modulus description, see operator+(bigmod, bigmod) */ bigmod lcm(const bigmod& rhs, const bigmod& lhs); /** * \brief function used to make any binary operation between * two bigmod that return a bigmod (addition substraction... ) */ bigmod create_bigmod(const bigmod& lhs, const bigmod& rhs, gmp_binary f, bool zeroRhsAllowed = true) ; #endif gmp/src/biginteger.cc0000644000176200001440000001450314444267422014266 0ustar liggesusers/*! \file biginteger.cc * \brief C function for class biginteger & bigmod * * \version 1 * * \date Created: 27/10/04 * \date Last modified: Time-stamp: <2023-01-28 15:51:50 (antoine)> * * \author Immanuel Scholz * * \note Licence: GPL (>= 2) */ #include #include #include "biginteger.h" using std::string; static int count=0; static int countALL=0; biginteger::biginteger() : na(true) { count++; countALL++; mpz_init(value);} /** * Construct a biginteger from a int value. */ biginteger::biginteger(const int value_) : na(false) { count++; countALL++; if(value_ == NA_INTEGER) {mpz_init(value); na = true ;} else mpz_init_set_si(value, value_);} /** * Construct a biginteger from a long value. */ biginteger::biginteger(const long int value_) : na(false) { count++; countALL++; if(value_ == NA_INTEGER) {mpz_init(value); na = true ;} else mpz_init_set_si(value, value_);} /** * Construct a biginteger from a unsigned long value. */ biginteger:: biginteger(const unsigned long int value_) : na(false) { count++; countALL++; if(value_ == (unsigned long int) NA_INTEGER) {mpz_init(value); na = true ;} else mpz_init_set_ui(value, value_);} /** * Construct a biginteger from a double value. */ biginteger::biginteger(const double value_) : na(false) { count++; countALL++; if( R_FINITE(value_) ) mpz_init_set_d(value, value_); else {mpz_init(value); na = true ;} } /** * Construct a biginteger from a string value. */ biginteger::biginteger(const std::string& value_) : na(false) { count++; countALL++; /* mpz_init.. return -1 when error, 0: ok */ if(mpz_init_set_str(value, value_.c_str(), 0)) { mpz_set_si(value, 0); na=true; } /* if(mpz_init_set_str(value, value_.c_str(), 0) == -1) Rf_error("Not a valid number"); */ } /** * Copy constructor (mpz_t aren't standard-copyable) */ biginteger::biginteger(const biginteger& rhs) : na(rhs.na) { count++; countALL++; mpz_init_set(value, rhs.getValueTemp()); } /** * Free the owned mpz_t structs */ biginteger::~biginteger() { count--; // printf("nb : %d %d \n",count,countALL); mpz_clear(value); } int biginteger::getCount(){ return count; } biginteger::biginteger(const char* raw) { count++; countALL++; mpz_init(value); na = true; const int* r = (int*)(raw); if (r[0]>0) { mpz_import(value, r[0], 1, sizeof(int) , 0, 0, (void*)&(r[2] )); if(r[1]==-1) mpz_neg(value,value); na = false; } else mpz_set_si(value, 0); //std::cout << "lu: "<< this->str(10) << std::endl; } /** * Create a biginteger from a value. Remember to free the * parameter's mpz_t if you allocated them by yourself - * biginteger will copy the value. */ biginteger::biginteger(const mpz_t value_) : na(false) { count++; countALL++; mpz_init_set(value, value_); } /* * Convert to string in base b; b from 2 to 36 */ string biginteger::str(int b) const { if (isNA()) return "NA"; // possible minus sign, size of number + '\0' char* buf = new char[mpz_sizeinbase(value, b)+2]; mpz_get_str(buf, b, value); string s = buf; delete [] buf; return s; } /** * \brief export mpz to R raw value */ int biginteger::as_raw(char* raw) const { int totals = raw_size() ; memset(raw, 0, totals ); int* r = (int*)raw; r[0] = totals/sizeof(int) - 2; if (!isNA()) { r[1] = (int) mpz_sgn(value); mpz_export(&r[2], 0, 1, sizeof(int), 0, 0, value); } return totals; } /** * \brief export mpz to R raw value * * return number of byte used (if na => 2*sizeofint, else * the two int + size of the big integer) * * \note IF size of big integer exceed value of one int => cannot store value */ int as_raw(char* raw,mpz_t value, bool na) { int numb = 8*sizeof(int); int totals = sizeof(int); if(!na) totals = sizeof(int) * (2 + (mpz_sizeinbase(value,2)+numb-1) / numb); memset(raw, 0, totals ); int* r = (int*)raw; r[0] = totals/sizeof(int) - 2; if (!na) { r[1] = (int) mpz_sgn(value); mpz_export(&r[2], 0, 1, sizeof(int), 0, 0, value); } return totals; } // number of int used in R by on biginteger size_t biginteger::raw_size() const { if (isNA()) return sizeof(int); int numb = 8*sizeof(int); return sizeof(int) * (2 + (mpz_sizeinbase(value,2)+numb-1) / numb); // return (sizeof(int) * ( 2 + (mpz_sizeinbase(value,2)/(8*sizeof(int))) ) ); } void biginteger::swap(biginteger& other) { mpz_swap(value, other.value); bool n = na; na = other.na; other.na = n; } biginteger & biginteger::operator= (const biginteger& rhs) { if(this != &rhs) { mpz_set(value,rhs.getValueTemp()); na = rhs.na; } return(*this); } // comparison bool operator!=(const biginteger& rhs, const biginteger& lhs) { if(rhs.isNA() || lhs.isNA()) return(false); // SHOULD RETURN NA return(mpz_cmp(rhs.getValueTemp(),lhs.getValueTemp())!=0); } // comparison bool operator<(const biginteger& rhs, const biginteger& lhs) { if(rhs.isNA() || lhs.isNA()) return(false); // SHOULD RETURN NA return(mpz_cmp(rhs.getValueTemp(),lhs.getValueTemp())<0); } // comparison bool operator>(const biginteger& rhs, const biginteger& lhs) { if(rhs.isNA() || lhs.isNA()) return(false); // SHOULD RETURN NA return(mpz_cmp(rhs.getValueTemp(),lhs.getValueTemp())>0); } // addition biginteger operator* (const biginteger& rhs, const biginteger& lhs) { // one of them NA: return NA if(rhs.isNA() || lhs.isNA()) return(biginteger()); mpz_t result; mpz_init(result); mpz_t_sentry val_s(result); mpz_mul(result,rhs.getValueTemp(),lhs.getValueTemp()); return(biginteger(result)); } // substraction biginteger operator- (const biginteger& rhs, const biginteger& lhs) { // one of them NA: return NA if(rhs.isNA() || lhs.isNA()) return(biginteger()); mpz_t result; mpz_init(result); mpz_t_sentry val_s(result); mpz_sub(result,rhs.getValueTemp(),lhs.getValueTemp()); return(biginteger(result)); } // modulus biginteger operator% (const biginteger& rhs, const biginteger& lhs) { // one of them NA: return NA if(rhs.isNA() || lhs.isNA()) return(biginteger()); mpz_t result; mpz_init(result); mpz_t_sentry val_s(result); mpz_mod(result,rhs.getValueTemp(),lhs.getValueTemp()); return(biginteger(result)); } gmp/src/matrixq.h0000644000176200001440000000172314444267421013475 0ustar liggesusers/*! \file matrixq.h * \brief header for rational matrix functions set * * \date Created: 2005 * \date Last modified: Time-stamp: <2022-12-09 15:15:01 (antoine)> * * * \note Licence: GPL (>= 2) */ #include "bigvec_q.h" extern "C" { /** * \brief build a matrix x with dimensions p&q byrow: 0 or 1 */ SEXP as_matrixq(SEXP x, SEXP p, SEXP q, SEXP byrow, SEXP mod); /** * \brief transpose a "matrix" n x p into the transpose p x n */ SEXP bigq_transposeR(SEXP x); /** \brief matrix cross product */ SEXP matrix_crossp_q (SEXP a, SEXP trans); /** \brief matrix multiplication */ SEXP matrix_mul_q (SEXP a, SEXP b, SEXP op); /** \brief for function rbind */ SEXP bigrational_rbind(SEXP args) ; SEXP bigrational_cbind(SEXP args) ; } /** * \brief Function designed for bigrational matrix */ namespace matrixq { /** * \brief C++ function use to transpose matrix */ bigvec_q bigq_transpose (const bigvec_q & mat); } gmp/src/extract_matrix.h0000644000176200001440000002567014444267421015055 0ustar liggesusers/*! \file extract_matrix.h * \brief functions to extract parts of matrix * * \version 1 * * \date Created: 25/06/11 * \date Modifications: see cvs log * * \author A. Lucas * * \note * as usually, matrix x[i,j] (n x p) is represented by a vector * x[i + j x n] (i=0..n-1 ; j=0..p-1) * * \note Licence: GPL (>= 2) */ #ifndef EXTRACT_MATRIX_HEADER_GMP_R_ #define EXTRACT_MATRIX_HEADER_GMP_R_ 1 #include #include #include "bigvec_q.h" #include "bigintegerR.h" #include #include extern "C" { /** \brief get subsets of a matrix */ SEXP matrix_get_at_z(SEXP A,SEXP INDI, SEXP INDJ); /** \brief set subsets of a matrix */ SEXP matrix_set_at_z(SEXP A,SEXP VAL ,SEXP INDI, SEXP INDJ); /** \brief get subsets of a matrix */ SEXP matrix_get_at_q(SEXP A, SEXP INDI, SEXP INDJ); /** \brief set subsets of a matrix */ SEXP matrix_set_at_q(SEXP A,SEXP VAL, SEXP INDI, SEXP INDJ); } namespace extract_gmp_R { /** \brief Change R indices (in function like A[IND]) from * R (it can be logical/positive/negative) to a vector of size n * containing boolean: true: we update line/row, flase : we do not * change anything * * \return a vector of n boolean corresponding to values that must be affected. * */ std::vector indice_get_at (unsigned int n , SEXP & IND); /** * \brief tranform a matrix from bigvec or bigvec_q format to * vector > (a vector of columns) * * \note for bigvec: it does not take into account modulus. * */ template< class T> void toVecVec(T& A, std::vector & retour ) { //typename std::vector retour; unsigned int i; // case: vector if(A.nrow < 0) A.nrow = A.size(); else // check that size is a multiple of row { if((A.size() / A.nrow) != static_cast(A.size()) / static_cast(A.nrow)){ A.clear(); Rf_error("malformed matrix"); } } retour.resize(A.size() / A.nrow); for(i = 0; i < retour.size(); ++i) { retour[i] = new T(); retour[i]->resize(A.nrow); } // go ! for(i= 0 ; i < A.size(); ++i) // retour[col ] [row ] (*retour[i / A.nrow ])[ i % A.nrow].setValue(A[i]); //return(retour); } template< class T> void clearVec(typename std::vector & vec ) { for (typename std::vector::const_iterator it = vec.begin(); it != vec.end(); ++it) delete *it; } /** * \brief extract parts of a matrix * * \param A matrix (class bigvec or bigvec_q) * \param INDI,INDJ indices: either "LOGICAL" (true/false) or * numbers: * - positives: we return row/col in INDI/INDJ * - negatives: we retun all except row/col in INDI/INJ */ template T get_at (T & A, SEXP& INDI, SEXP& INDJ) { //DEBUG //return A; // result = A[indi,indj] int oldnrow = A.nrow; std::vector indJ; typename std::vector matricetmp ; typename std::vector matricetmp2; toVecVec(A,matricetmp); typename std::vector copyAdress(matricetmp); // only pointers typename std::vector * matrice = &matricetmp; typename std::vector * matricework = &matricetmp2; T retour; unsigned int i,j, newnrow; std::vector::iterator it; // -------------------------- // PART 1: COLUMNS // -------------------------- if(A.size()==0) { clearVec(copyAdress); return(retour); } if(TYPEOF(INDJ) != NILSXP) { indJ = bigintegerR::create_int(INDJ); if (TYPEOF(INDJ) == LGLSXP) // LOGICAL { // for all columns unsigned int delta=0; for (i = 0; i < (*matrice)[0]->size(); ++i) { if (! indJ[i+delta% indJ.size()]) { // remove columns i matrice->erase(i+ matrice->begin()); --i; // indice in modified matrix ++delta; // i+delta: old indice } } } else //INDJ: numbers { indJ.erase(std::remove(indJ.begin(), indJ.end(), 0L), indJ.end()); // remove all zeroes if (indJ.empty()) { clearVec(copyAdress); return retour; } // case: a[-b] // negatives... if(indJ[0] < 0) { // sort in reverse order std::sort(indJ.begin(),indJ.end(),std::greater() ); // we should have indJ like -1 -3 -7 -7 -12 ... // remove consecutive duplicates it = std::unique(indJ.begin(),indJ.end()); indJ.erase(it,indJ.end()); if ( indJ.back() > 0){ clearVec(copyAdress); A.clear(); Rf_error("only 0's may mix with negative subscripts"); } it=indJ.begin(); unsigned int delta=0; // for all columns for (j = 0; j < matrice->size(); ++j) { if(it == indJ.end()) break; if (*it == - static_cast(j+1+delta) ) { matrice->erase(j+ matrice->begin()); ++it; ++delta; --j; } } } else // case: positive values: 1;5;7;7;9;10... { // note : can have duplicates and indices are not sorted // allocate new matrix (all will be copied) // number of columns matricework->reserve(indJ.size()); // for all [new] rows for( it=indJ.begin(); it != indJ.end(); it++) { if (*it < 0){ clearVec(copyAdress); A.clear(); Rf_error("only 0's may mix with negative subscripts"); } if( static_cast(*it-1) < matrice->size() ) { //printf("on sort %s",(*matrice)[(*it)-1][0].str(10).c_str()); matricework->push_back( (*matrice)[*it-1] ); } else { clearVec(copyAdress); A.clear(); Rf_error("column subscript out of bounds"); } } // change addresses matrice = &matricetmp2; matricework = &matricetmp; }//end of case: int+positive values } } // INDJ "exists" if(matrice->size()==0) { clearVec(copyAdress); return(retour); } // -------------------------- // PART 2: ROWS // -------------------------- std::vector indI = bigintegerR::create_int(INDI); if(TYPEOF(INDI) != NILSXP) { if (TYPEOF(INDI) == LGLSXP) { // LOGICAL // for all rows unsigned int delta = 0; for (i = 0; i < (*matrice)[0]->size(); ++i) { if (! indI[(i+delta)% indI.size()]) { // for all columns j delete row i for (j = 0; j < matrice->size(); ++j) (*matrice)[j]->erase(i); //++newnrow; --i; // i: new indice in modified matrix ++delta; // i+delta = old indices } } } else { // INDI : numbers // remove zeros: indI.erase(std::remove(indI.begin(), indI.end(), 0L), indI.end()); if (indI.empty()) { clearVec(copyAdress); return retour; } // case: a[-b] // negatives... if(indI[0] < 0) { std::sort(indI.begin(),indI.end(),std::greater() ); // we should have indI like -1 -3 -7 -7 -12 ... // remove duplicates it= std::unique(indI.begin(),indI.end()); indI.erase(it,indI.end()); if ( indI.back() > 0){ clearVec(copyAdress); A.clear(); Rf_error("only 0's may mix with negative subscripts"); } //newnrow = A.nrow; it=indI.begin(); // for all rows unsigned int delta = 0; for (i = 0; i < (*matrice)[0]->size(); ++i) { if(it != indI.end() ) if (*it == - static_cast(i+1+delta) ) { // for all columns j remove row i for (j = 0; j < matrice->size(); ++j) { (*matrice)[j]->erase(i); } //--newnrow; --i; // i: new indice in modified matrix ++delta; // i+delta = old indices ++it; } } } else { // case: positive values: 1;5;7;7;9;10... // delete too large values or give error iff INDJ is non-NULL for(it = indI.begin(); it != indI.end(); ++it) { if(*it > static_cast((*matrice)[0]->size())) { if(oldnrow < 0) { // vector case: out-of-bound --> NA /* it = indI.erase(it); */ /* --it; */ } else { // matrix case: clearVec(copyAdress); A.clear(); Rf_error("subscript out of bounds"); } } } // note : can have duplicates and indices are not sorted //newnrow = indI.size(); // allocate new matrix (all will be copied) // number of columns matricework->resize( matrice->size()); for (typename std::vector::iterator it = matricework->begin(); it != matricework->end(); ++it) { *it = new T(); copyAdress.push_back(*it); } // number of row for (j = 0; j < matricework->size(); ++j) (*matricework)[j]->resize( indI.size() ); // for all [new] rows for( i=0; i < indI.size(); ++i) { if (indI[i] < 0){ clearVec(copyAdress); A.clear(); Rf_error("only 0's may mix with negative subscripts"); } if( static_cast(indI[i]-1) < (*matrice)[0]->size() ) { // for all columns for (j = 0; j < matricework->size(); ++j) //newmat[i,j] = oldmat[ind[i],j] ( *(*matricework)[j])[i] = (*(*matrice)[j])[indI[i]-1]; } else for (j = 0; j < matricework->size(); ++j) ( *(*matricework)[j])[i].setValue(); } matrice = matricework; // change addresses }//end of case: int+positive values } } // -------------------------- // PART 3: COPY RESULT // -------------------------- newnrow = (*matrice)[0]->size(); retour.resize(matrice->size() * newnrow); for(i=0; i< newnrow ; ++i) for(j=0; j < matrice->size() ; ++j) retour[i + j* newnrow ] = (*(*matrice)[j])[i] ; retour.nrow = (oldnrow < 0) ? -1 : newnrow; clearVec(copyAdress); return(retour); } // end get_at /** \brief set a matrix: for R function src[idx,jdx] <- value * */ template void set_at(T & src ,const T & value, SEXP & IDX, SEXP & JDX) { // case: vector if(src.nrow < 0) src.nrow = src.size(); // check that size is a multiple of row if((src.size() / src.nrow) != static_cast(src.size()) / static_cast(src.nrow)){ src.clear(); T & vval = const_cast(value); vval.clear(); throw std::invalid_argument("malformed matrix"); //Rf_error("malformed matrix"); } unsigned int ncol = src.size() / src.nrow; // number of col std::vector vidx = indice_get_at ( src.nrow, IDX); std::vector vjdx = indice_get_at ( ncol, JDX); unsigned int k=0; for(unsigned int j = 0 ; j < vjdx.size() ; ++j) { for(unsigned int i = 0 ; i < vidx.size(); ++i) { unsigned int index = vidx[i] + vjdx[j] * src.nrow; if(index >= src.size()) { src.clear(); T & vval = const_cast(value); vval.clear(); throw std::invalid_argument("indice out of bounds"); // Rf_error("indice out of bounds"); } src.set(index, value[k % value.size()] ); ++k; } } return; }//end set_at }// end namespace #endif gmp/src/bigrational.cc0000644000176200001440000001417414444267421014445 0ustar liggesusers/*! \file bigrational.cc * \brief Implementation of class bigrational * * \version 1 * * \date Created: 12/12/04 * \date Last modified: Time-stamp: <2023-01-24 19:01:08 (antoine)> * * \author Antoine Lucas (adapted from biginteger class made by * Immanuel Scholz) * * \note Licence: GPL (>= 2) */ #include #include "bigrational.h" #include "bigrationalR.h" using std::string; static int count=0; /** * Construct a "NA" bigrational. */ bigrational::bigrational() : value(), na(true) { count++; mpq_init(value); } // set numerator bigrational::bigrational(void* raw): value(), na(true) { count++; mpz_t tmpVal; mpz_init(tmpVal); mpz_t_sentry val_s(tmpVal); mpq_init(value); int* r = (int*)raw; if (r[0]>0) { mpz_import(tmpVal, r[0], 1, sizeof(int), 0, 0, &r[2]); if(r[1]==-1) mpz_neg(tmpVal,tmpVal); na = false; mpq_set_z(value,tmpVal); } } /** * Create a bigrational from a value. Remember to free the * parameter's mpz_t if you allocated them by yourself - * biginteger will copy the value. */ bigrational::bigrational(const mpq_t& value_) : value(), na(false) { count++; mpq_init(value); mpq_set(value, value_); } /** * \brief create a rational from an [big] integer */ bigrational::bigrational(const mpz_t& value_) : value(), na(false) { count++; mpq_init(value); mpq_set_z(value, value_); } /** * Construct a bigrational from a long value. */ bigrational::bigrational(int value_) : value(), na(false) { count++; mpq_init(value); if(value_ == NA_INTEGER) na = true ; else mpq_set_si(value, value_,1); } /** * Construct a bigrational from a long value. */ bigrational::bigrational(int num_, int den_) : value(), na(false) { count++; mpq_init(value); if((num_ == NA_INTEGER) || (den_ == NA_INTEGER) ) na = true ; else mpq_set_si(value, num_,den_);} /** * Construct a bigrational from a double value. */ bigrational::bigrational(double value_) : value(), na(false) { count++; mpq_init(value); if(R_FINITE( value_ ) ) mpq_set_d(value, value_); else // FIXME: consider "1/0" and "(-1)/0" for +- Inf na = true ; } /** * Construct a bigrational from a string value. it can be "4343" or "2322/4343" */ bigrational:: bigrational(const std::string& value_) : value(), na(false) { count++; mpq_init(value); /* mpz_init.. return -1 when error, 0: ok */ if(mpq_set_str(value, value_.c_str(), 0)) na=true; /* if(mpz_init_set_str(value, value_.c_str(), 0) == -1) Rf_error("Not a valid number"); */ } /** * Copy constructor (mpz_t aren't standard-copyable) */ bigrational::bigrational(const biginteger & rhs) : value(), na(rhs.isNA()) { count++; mpq_init(value); mpq_set_z(value, rhs.getValueTemp()); } /** * Copy constructor (mpz_t aren't standard-copyable) */ bigrational::bigrational(const bigrational & rhs) : value(), na(rhs.na) { count++; mpq_init(value); mpq_set(value, rhs.value); } /** * Free the owned mpz_t structs */ bigrational::~bigrational() { count--; //printf("bigq count %d \n",count); mpq_clear(value);} bigrational & bigrational::operator= (const bigrational& rhs) { if(this != &rhs) { mpq_set(value, rhs.getValueTemp()); na= rhs.na; } return(*this); } /** * \brief Print value */ std::string bigrational::str(int b) const { if (isNA()) return "NA"; unsigned int totSize = mpz_sizeinbase(mpq_numref(value),b) + \ mpz_sizeinbase(mpq_denref(value),b) + 3 ; char* buf = new char[totSize]; mpq_get_str(buf, b, value); std::string s = buf; delete [] buf; return s; } /* \brief simplify n/d (use of mpq_canonical) * */ void bigrational::simplify () { mpq_canonicalize(value); } // size of numerator !! size_t bigrational::raw_size() const { if (isNA()) return sizeof(int); int numb = 8*sizeof(int); return sizeof(int) * (2 + (mpz_sizeinbase(mpq_numref(value),2)+numb-1) / numb); } bigrational operator+(const bigrational& lhs, const bigrational& rhs) { return bigrationalR::create_bigrational(lhs, rhs, mpq_add); } /** * \brief Return a - b */ bigrational operator-(const bigrational& lhs, const bigrational& rhs) { return bigrationalR::create_bigrational(lhs, rhs, mpq_sub); } /** * \brief Return a * b */ bigrational operator*(const bigrational& lhs, const bigrational& rhs) { return bigrationalR::create_bigrational(lhs, rhs, mpq_mul); } /** * \brief Return a / b */ bigrational operator/(const bigrational& lhs, const bigrational& rhs) { return bigrationalR::create_bigrational(lhs, rhs, mpq_div, false); } /** * \brief Return a ^ b */ bigrational operator^(const bigrational& lhs, const biginteger& rhs) { // if (base == 1 or exp == 0) return 1 if((!lhs.isNA() && !mpq_cmp_si(lhs.getValueTemp(), 1,1)) || (!rhs.isNA() && !mpz_cmp_si(rhs.getValueTemp(), 0))) return bigrational(1); if (lhs.isNA() || rhs.isNA()) return bigrational(); return bigrationalR::create_bigrational_z(lhs, rhs, bigrationalR::mpqz_pow); } // bool operator!=(const bigrational& lhs, const bigrational& rhs) { if(rhs.isNA() || lhs.isNA()) return(false); // SHOULD RETURN NA return(mpq_cmp(lhs.getValueTemp(),rhs.getValueTemp()) != 0); } bool operator>(const bigrational& lhs, const bigrational& rhs) { if(rhs.isNA() || lhs.isNA()) return(false); // SHOULD RETURN NA return(mpq_cmp(lhs.getValueTemp(),rhs.getValueTemp()) > 0); } bool operator<(const bigrational& lhs, const bigrational& rhs) { if(rhs.isNA() || lhs.isNA()) return(false); // SHOULD RETURN NA return(mpq_cmp(lhs.getValueTemp(),rhs.getValueTemp()) < 0); } /** * \brief Well... an heritage from biginteger class, this should be * integrated earlier... put denominator & simplify if there is not. */ // R as.bigq() : bigrational set_denominator(const bigrational& lhs, const bigrational& rhs) { return bigrationalR::create_bigrational(lhs, rhs, mpq_div, false); } // return 1/x bigrational bigrational::inv() { if(isNA()) return(bigrational()); mpq_t tmpVal; mpq_init(tmpVal); mpq_t_sentry val_s(tmpVal); mpq_inv(tmpVal,value); return(bigrational(tmpVal)); } gmp/src/extract_matrix.cc0000644000176200001440000001021214662140460015170 0ustar liggesusers#include "extract_matrix.h" #include "bigrationalR.h" #include using namespace std; // for something like x = A[indi, indj], but also simply A[ind] SEXP matrix_get_at_q(SEXP A,SEXP INDI, SEXP INDJ) { try{ bigvec_q mat = bigrationalR::create_bignum(A); return(bigrationalR::create_SEXP(extract_gmp_R::get_at( mat,INDI,INDJ))); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // for something like x = A[indi, indj], but also simply A[ind] SEXP matrix_get_at_z(SEXP A,SEXP INDI, SEXP INDJ) { // printf("ici\n"); try { bigvec mat = bigintegerR::create_bignum(A); bigvec mat2 = extract_gmp_R::get_at( mat,INDI,INDJ); /* // now modulus ! // cell based modulus if(mat.getType() == TYPE_MODULUS:: MODULUS_BY_CELL) { for(unsigned int i = 0; i< mat.size(); ++i) mat.value[i] = mat.modulus[i]; mat = extract_gmp_R::get_at( mat,INDI,INDJ); mat2.modulus.resize(mat.size()); for(unsigned int i = 0; i< mat.size(); ++i) mat2.modulus[i] = mat.value[i]; } // row base modulus else if((int)mat.modulus.size() == mat.nrow) { for(unsigned int i = 0; i< mat.size(); ++i) mat.value[i] = mat.modulus[i]; mat.modulus.clear(); mat = bigintegerR::biginteger_get_at_C(mat,INDI); mat2.modulus.resize(mat.size()); for(unsigned int i = 0; i< mat.size(); ++i) mat2.modulus[i] = mat.value[i]; } //global modulus else if(mat.modulus.size() == 1) { mat2.modulus.resize(1); mat2.modulus[0] = mat.modulus[0]; }*/ return(bigintegerR::create_SEXP(mat2) ); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // for something like A[indi, indj] <- val SEXP matrix_set_at_z(SEXP A, SEXP VAL, SEXP INDI, SEXP INDJ) { try{ bigvec mat = bigintegerR::create_bignum(A); bigvec val = bigintegerR::create_bignum(VAL); extract_gmp_R::set_at( mat,val,INDI,INDJ); return(bigintegerR::create_SEXP(mat)); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // for something like A[indi, indj] <- val SEXP matrix_set_at_q(SEXP A,SEXP VAL ,SEXP INDI, SEXP INDJ) { try{ bigvec_q mat = bigrationalR::create_bignum(A); bigvec_q val = bigrationalR::create_bignum(VAL); extract_gmp_R::set_at( mat,val,INDI,INDJ); return(bigrationalR::create_SEXP(mat)); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // // return a vector of integers corresponding to values that must be affected. // std::vector extract_gmp_R::indice_get_at (unsigned int n , SEXP & IND) { std::vector vidx = bigintegerR::create_int(IND); std::vector result; if(TYPEOF(IND) == NILSXP){ //LOCICAL: return true for (unsigned int i = 0; i< n ; i++){ result.push_back(i); } } else if (TYPEOF(IND) == LGLSXP) { // boolean for(unsigned int i = 0; i< n; ++i) if (vidx[i % vidx.size() ] ) result.push_back(i); } else //INTEGERS { vidx.erase(std::remove(vidx.begin(), vidx.end(), 0L), vidx.end()); // remove all zeroes if(vidx.size() == 0) return result; //negatives integers: all except indices will be modified if (vidx[0] < 0) { std::vector tempo(n,true); for (std::vector::const_iterator jt = vidx.begin(); jt != vidx.end(); ++jt) { if(*jt > 0) throw invalid_argument("only 0's may mix with negative subscripts"); //error(_("only 0's may mix with negative subscripts")); if( (*jt != 0) && (*jt >= - static_cast(n))) tempo[-(*jt)-1] = false; } for (unsigned int i =0 ; i < n ; i++){ if(tempo[i]) result.push_back(i); } } else { //INTEGERS (and positive) for (std::vector::const_iterator jt = vidx.begin(); jt != vidx.end(); ++jt) { int i = *jt; if(i < 0) throw invalid_argument("only 0's may mix with negative subscripts"); //error(_("only 0's may mix with negative subscripts")); result.push_back(i-1); } } } return(result); }//end of indice_set_at gmp/src/bigrationalR.cc0000644000176200001440000006253514662137652014577 0ustar liggesusers/************************************************************/ /*! \file bigrationalR.cc * \brief C function to interface R and libgmp with big rational values * * \version 1 * * \date Created: 12/12/04 * \date Last modified: $Id: bigrationalR.cc,v 1.22 2013-03-25 10:57:04 mmaechler Exp $ * * \author Antoine Lucas (adapted from biginteger class made by * Immanuel Scholz) * * \note Licence: GPL (>= 2) */ #include #include #include #include "bigintegerR.h" #include "Rgmp.h" #include "bigvec_q.h" using namespace std; #include "bigrationalR.h" #include "matrix.h" #include "extract_matrix.h" namespace bigrationalR { /** \brief create a vector of bigrationals, all without a denominator. */ bigvec_q create_vector(SEXP param) { lockSexp lock (param); switch (TYPEOF(param)) { case NILSXP: return bigvec_q(); // = bigq(0) case RAWSXP: { // deserialise the vector. first int is the size. bigvec_q v; char* raw = (char*)RAW(param); int pos = sizeof(int); // position in raw[]. Starting after header. for (int i = 0; i < ((int*)raw)[0]; ++i) { v.push_back(bigrational(bigrational((void*)&raw[pos]))); pos += v.value.back().raw_size(); // increment number of bytes read. } return v; } case REALSXP: { double* d = REAL(param); bigvec_q v(d,d+LENGTH(param)); for (unsigned int j = 0; j < v.size(); ++j) if ( R_FINITE ( d[j]) ) v.value[j].setValue(d[j]); else v.value[j].setValue(); return v; } case INTSXP: case LGLSXP: { int* i = INTEGER(param); bigvec_q v(i,i+LENGTH(param)); for (unsigned int j = 0; j < v.size(); ++j) if (i[j] == NA_INTEGER) v.value[j].setValue(); return v; } case STRSXP: { bigvec_q v; v.value.reserve(LENGTH(param)); for (int i = 0; i < LENGTH(param); ++i) { if (STRING_ELT(param,i) == NA_STRING) v.value.push_back(bigrational()); else v.value.push_back(bigrational(std::string(CHAR(STRING_ELT(param,i))))); } return v; } default: { // no longer: can be fatal later! /* vector of size 0 */ return bigvec_q(); throw invalid_argument(_("only logical, numeric or character (atomic) vectors can be coerced to 'bigq'")); } } } bigvec_q create_bignum(SEXP param) { /* // First check if it is a bigz class // This should occur very rarely except if force // a bigq operator like add.bigq(z1,z2)... // this should be decommented when // biqg will not be exported in mpz format SEXP className; PROTECT(className = Rf_allocVector(STRSXP,1)); SET_STRING_ELT(className, 0, Rf_mkChar("class")); SEXP classAttr = Rf_getAttrib(param, className); UNPROTECT(1); if (TYPEOF(classAttr) == STRSXP) if( CHAR(STRING_ELT(param,0)) == "bigz") return(bigvec_q(bigintegerR::create_bignum(param)) ); */ PROTECT (param); bigvec_q v = bigrationalR::create_vector(param); SEXP denKey = Rf_mkString("denominator"); PROTECT(denKey); SEXP denAttr = Rf_getAttrib(param, denKey); PROTECT(denAttr); SEXP dimKey = Rf_mkString("nrow"); PROTECT(dimKey); SEXP dimAttr = Rf_getAttrib(param,dimKey ); PROTECT(dimAttr); if (TYPEOF(dimAttr) == INTSXP) v.nrow = INTEGER(dimAttr)[0]; else { // catch to get std matrix dimensions value dimAttr = Rf_getAttrib(param,R_DimSymbol ); v.nrow = (TYPEOF(dimAttr) == INTSXP) ? INTEGER(dimAttr)[0] : -1; } if (TYPEOF(denAttr) != NILSXP) { bigvec_q attrib = bigrationalR::create_vector(denAttr); if (attrib.size() != 0) // sanity check for (unsigned int i = 0; i < v.size(); ++i) { if( attrib[i%attrib.size()].sgn() != 0) v.value[i].setDenValue (attrib.value[i%attrib.size()].getValueTemp()) ; } } UNPROTECT(5); return v; } SEXP create_SEXP(const math::Matrix & v) { SEXP ans, R_denom; int sizenum = sizeof(int), // starting with vector-size-header sizedenum = sizenum; unsigned int i; mpz_t num, den; mpz_init(num); mpz_init(den); mpz_t_sentry val_n(num); mpz_t_sentry val_d(den); int numb = 8*sizeof(int); //return sizeof(int) * (2 + (mpz_sizeinbase(value,2)+numb-1) / numb); for (i = 0; i < v.size(); ++i) { if(v[i].isNA()) { sizenum += sizeof(int); sizedenum += sizeof(int); } else { // *num = mpq_numref(v.value[i].getValueTemp()); // *den = mpq_denref(v.value[i].getValueTemp()); mpq_get_num(num,v[i].getValueTemp()); mpq_get_den(den,v[i].getValueTemp()); sizenum += sizeof(int) * (2 + (mpz_sizeinbase(num,2)+numb-1) / numb); // adding each bigint's needed size sizedenum += sizeof(int) * (2 + (mpz_sizeinbase(den,2)+numb-1) / numb); } } PROTECT(ans = Rf_allocVector(RAWSXP, sizenum)); PROTECT(R_denom = Rf_allocVector(RAWSXP, sizedenum)); char* r = (char*)RAW(ans); char* rdenom = (char*)RAW(R_denom); ((int*)r)[0] =((int*)rdenom)[0] = v.size(); // first int is vector-size-header int posnum = sizeof(int); // current position in r[] (starting after vector-size-header) int posdenum = sizeof(int); // current position in r[] (starting after vector-size-header) for (i = 0; i < v.size(); ++i) { mpq_get_num(num,v[i].getValueTemp()); mpq_get_den(den,v[i].getValueTemp()); posnum += as_raw(&r[posnum],num,v[i].isNA()); posdenum += as_raw(&rdenom[posdenum],den,v[i].isNA()); } // set the class attribute to "bigrational" Rf_setAttrib(ans, R_ClassSymbol, Rf_mkString("bigq")); Rf_setAttrib(ans, Rf_mkString("denominator"), R_denom); // set the dim attribute to "bigq" if(! v.isVector()) Rf_setAttrib(ans, Rf_mkString("nrow"), Rf_ScalarInteger((int) v.nRows())); UNPROTECT(2); return ans; } SEXP bigrational_binary_operation(const bigvec_q & va,const bigvec_q & vb, bigrational_binary_fn f) { bigvec_q result; int nrow = matrixz::checkDims(va.nrow,vb.nrow) ; if(nrow == -2){ throw invalid_argument(_("Matrix dimensions do not match")); } // MM: I think, 0 length vector operations should work too! // if (va.value.empty() || vb.value.empty()) // error(_("argument must not be an empty list")); int size = (va.size() ==0 || vb.size() == 0) ? 0 : max(va.size(), vb.size()); result.value.reserve(size); for (int i = 0; i < size; ++i) result.push_back(f(va.value[i%va.size()], vb.value[i%vb.size()])); result.nrow = nrow; return bigrationalR::create_SEXP(result); } /** * \brief Main function of doing a binary operation on bigrationals. * It calls a function argument for doing the correct thing. * This could also be written as a class functor (template) * to save one function call, but then code bloat will happen. */ SEXP bigrational_binary_operation(SEXP a, SEXP b, bigrational_binary_fn f) { try { bigvec_q va = bigrationalR::create_bignum(a); bigvec_q vb = bigrationalR::create_bignum(b), result; return bigrational_binary_operation(va,vb,f); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP bigrational_bigz_binary_operation(SEXP a, SEXP b, bigrational_bigz_binary_fn f) { try { bigvec_q va = bigrationalR::create_bignum(a), result; bigvec vb = bigintegerR::create_bignum(b); int size = (va.size()==0 || vb.size()==0) ? 0 : max(va.size(), vb.size()); int nrow = matrixz::checkDims(va.nrow,vb.nrow) ; if(nrow == -2){ throw invalid_argument(_("Matrix dimensions do not match")); } for (int i = 0; i < size; ++i) result.push_back(f(va.value[i%va.size()], vb[i%vb.size()].getValue())); result.nrow = nrow; return bigrationalR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP bigrational_logical_binary_operation(SEXP a, SEXP b, bigrational_logical_binary_fn f) { try { bigvec_q va = bigrationalR::create_bignum(a); bigvec_q vb = bigrationalR::create_bignum(b), result; // MM: I think, 0 length vector operations should work too! // if (va.size() == 0 || vb.size() == 0) // error(_("argument must not be an empty list")); int nrow = matrixz::checkDims(va.nrow,vb.nrow) ; if(nrow == -2){ va.clear(); vb.clear(); throw invalid_argument(_("Matrix dimensions do not match")); } int size = (va.size() == 0 || vb.size() == 0) ? 0 : max(va.size(), vb.size()); SEXP ans = PROTECT(Rf_allocVector(LGLSXP, size)); for (int i = 0; i < size; ++i) { bigrational am = va.value[i % va.size()]; bigrational bm = vb.value[i % vb.size()]; if (am.isNA() || bm.isNA()) LOGICAL(ans)[i] = NA_LOGICAL; else LOGICAL(ans)[i] = f(va[i%va.size()], vb[i%vb.size()]) ? 1 : 0; } // Add dimension parameter when available if(nrow >= 0) { SEXP dimVal; PROTECT(dimVal = Rf_allocVector(INTSXP, 2)); INTEGER(dimVal)[0] = (int) nrow; INTEGER(dimVal)[1] = (int) size / nrow; Rf_setAttrib(ans, Rf_mkString("dim"), dimVal); UNPROTECT(1); } UNPROTECT(1); return ans; } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } bool lt(const bigrational& lhs, const bigrational& rhs) { return mpq_cmp(lhs.getValueTemp(), rhs.getValueTemp()) < 0; } bool gt(const bigrational& lhs, const bigrational& rhs) { return mpq_cmp(lhs.getValueTemp(), rhs.getValueTemp()) > 0; } bool lte(const bigrational& lhs, const bigrational& rhs) { return mpq_cmp(lhs.getValueTemp(), rhs.getValueTemp()) <= 0; } bool gte(const bigrational& lhs, const bigrational& rhs) { return mpq_cmp(lhs.getValueTemp(), rhs.getValueTemp()) >= 0; } bool eq(const bigrational& lhs, const bigrational& rhs) { return mpq_cmp(lhs.getValueTemp(), rhs.getValueTemp()) == 0; } bool neq(const bigrational& lhs, const bigrational& rhs) { return mpq_cmp(lhs.getValueTemp(), rhs.getValueTemp()) != 0; } // Create a bigrational from a binary combination of two other bigrationals bigrational create_bigrational(const bigrational& lhs, const bigrational& rhs, gmpq_binary f, bool zeroRhsAllowed ) { if (lhs.isNA() || rhs.isNA()) return bigrational(); if (!zeroRhsAllowed && ( mpq_sgn(rhs.getValueTemp()) == 0)) throw invalid_argument(_("division by zero")); mpq_t val; mpq_init(val); mpq_t_sentry val_s(val); f(val,lhs.getValueTemp(),rhs.getValueTemp()); /* Simplify numerator and denominator */ mpq_canonicalize(val); return bigrational(val); } // Create a bigrational from a binary combination of (bigrational , biginteger) bigrational create_bigrational_z(const bigrational& lhs, const biginteger& rhs, gmp_qz_binary f, bool zeroRhsAllowed) { if (lhs.isNA() || rhs.isNA()) return bigrational(); if (!zeroRhsAllowed && ( mpz_sgn(rhs.getValueTemp()) == 0)) throw invalid_argument(_("division by zero")); mpq_t val; mpq_init(val); mpq_t_sentry val_s(val); f(val,lhs.getValueTemp(),rhs.getValueTemp()); /* Simplify numerator and denominator and return */ mpq_canonicalize(val); return bigrational(val); } // x ^ y (for biginteger y): void mpqz_pow(mpq_t result, const mpq_t x, const mpz_t y) { if(!mpz_fits_slong_p(y)) throw invalid_argument(_("exponent 'y' too large in 'x^y'")); mpz_t num, den; mpz_init(num); mpz_init(den); mpz_t_sentry val_n(num); mpz_t_sentry val_d(den); int yi = mpz_get_si(y); bool neg =(yi < 0); // *num = mpq_numref(x); // *den = mpq_denref(y); mpq_get_num(num, x); mpq_get_den(den, x); if(neg) { if(mpz_sgn(num) == 0) throw invalid_argument(_("0 ^ is a division by zero")); yi = -yi; } mpz_pow_ui(num, num, yi); // num := num ^ |y| mpz_pow_ui(den, den, yi); // den := den ^ |y| if(neg) { // Q^{-n} = 1 / Q^|n| --> result := den / num = as.bigq(den, num) : mpz_set(mpq_numref(result), den); mpz_set(mpq_denref(result), num); } else { // result := num / den = as.bigq(num, den) : mpz_set(mpq_numref(result), num); mpz_set(mpq_denref(result), den); } /* Simplify numerator and denominator */ mpq_canonicalize(result); } } // End of namespace bigrationalR ---------------------------------------------- SEXP bigrational_add (SEXP a, SEXP b) {return bigrationalR::bigrational_binary_operation(a,b,operator+);} SEXP bigrational_sub (SEXP a, SEXP b) {return bigrationalR::bigrational_binary_operation(a,b,operator-);} SEXP bigrational_mul (SEXP a, SEXP b) {return bigrationalR::bigrational_binary_operation(a,b,operator*);} SEXP bigrational_div (SEXP a, SEXP b) {return bigrationalR::bigrational_binary_operation(a,b,operator/);} SEXP bigrational_pow (SEXP a, SEXP b) { return bigrationalR::bigrational_bigz_binary_operation(a,b,operator^); //-> mpqz_pow() above } SEXP bigrational_as (SEXP n, SEXP d) {return bigrationalR::bigrational_binary_operation(n,d,set_denominator);} //-> mpq_div() SEXP bigrational_lt (SEXP a, SEXP b) {return bigrationalR::bigrational_logical_binary_operation(a,b,bigrationalR::lt);} SEXP bigrational_gt (SEXP a, SEXP b) {return bigrationalR::bigrational_logical_binary_operation(a,b,bigrationalR::gt);} SEXP bigrational_lte (SEXP a, SEXP b) {return bigrationalR::bigrational_logical_binary_operation(a,b,bigrationalR::lte);} SEXP bigrational_gte (SEXP a, SEXP b) {return bigrationalR::bigrational_logical_binary_operation(a,b,bigrationalR::gte);} SEXP bigrational_eq (SEXP a, SEXP b) {return bigrationalR::bigrational_logical_binary_operation(a,b,bigrationalR::eq);} SEXP bigrational_neq (SEXP a, SEXP b) {return bigrationalR::bigrational_logical_binary_operation(a,b,bigrationalR::neq);} SEXP bigrational_as_character(SEXP a, SEXP b) { try { bigvec_q v = bigrationalR::create_bignum(a); int base = Rf_asInteger(b); SEXP ans = PROTECT(Rf_allocVector(STRSXP, v.size())); for (unsigned int i = 0; i < v.size(); ++i) SET_STRING_ELT(ans, i, Rf_mkChar(v.value[i].str(base).c_str())); // matrix part if(v.nrow >= 0) { SEXP nRow = PROTECT(Rf_allocVector(INTSXP, 2)); INTEGER(nRow)[0] = v.nrow; INTEGER(nRow)[1] = v.value.size() / v.nrow; Rf_setAttrib(ans, Rf_mkString("dim"), nRow); UNPROTECT(1); } UNPROTECT(1); return ans; } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP bigrational_as_numeric(SEXP a) { try { bigvec_q v = bigrationalR::create_bignum(a); SEXP ans = PROTECT(Rf_allocVector(REALSXP,v.size())); double *r = REAL(ans); for (unsigned int i = 0; i < v.size(); ++i) r[i] = v.value[i].isNA() ? NA_REAL : v.value[i].as_double(); UNPROTECT(1); return ans; } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP bigrational_get_at(SEXP a, SEXP b) { try{ bigvec_q va = bigrationalR::create_bignum(a); vector v_ind; try{ v_ind = extract_gmp_R::indice_get_at(va.size(),b); } catch(std::invalid_argument & e){ va.clear(); v_ind.clear(); Rf_error("%s",e.what()); } bigvec_q result; for(unsigned int i = 0 ; i < v_ind.size(); i++){ int indice = v_ind[i]; if(indice < (int) va.size()){ result.push_back(va[indice]); } else { result.push_back(bigrational()); } } return bigrationalR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP bigrational_set_at(SEXP src, SEXP idx, SEXP value) { try { bigvec_q result = bigrationalR::create_bignum(src); vector vidx = extract_gmp_R::indice_get_at(result.size(),idx); bigvec_q vvalue = bigrationalR::create_bignum(value); if(vidx.size() == 0) { return bigrationalR::create_SEXP(result); } if(vvalue.size() == 0) { throw invalid_argument(_("replacement has length zero")); } int pos = 0; for(unsigned int i = 0 ; i < vidx.size(); i++){ while(result.size() <= (unsigned int ) (vidx[i] )) { result.push_back(bigrational()); } result.set(vidx[i],vvalue[pos++ % vvalue.size()]); } return bigrationalR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP bigrational_length(SEXP a) { try { return Rf_ScalarInteger(bigrationalR::create_bignum(a).size()); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP bigrational_den(SEXP a) { try { mpz_t z_tmp; mpz_init(z_tmp); bigvec_q v =bigrationalR::create_bignum(a); bigvec result; result.resize(v.size()); for (unsigned int i = 0; i < v.size(); ++i) { mpq_get_den(z_tmp,v[i].getValueTemp()); result[i].setValue(z_tmp); } mpz_clear(z_tmp); return bigintegerR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP bigrational_num(SEXP a) { try { mpz_t z_tmp; mpz_init(z_tmp); bigvec_q v =bigrationalR::create_bignum(a); bigvec result; result.resize(v.size()); for (unsigned int i = 0; i < v.size(); ++i) { if(!v[i].isNA()) { mpq_get_num(z_tmp,v[i].getValueTemp()); result[i].setValue(z_tmp); } // else: uninitialized, i.e., NA } mpz_clear(z_tmp); return bigintegerR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP bigrational_setlength(SEXP vec, SEXP value) { try { int len = 0; switch (TYPEOF(value)) { case INTSXP: case LGLSXP: if (LENGTH(value) != 1) Rf_error("%s",_("invalid second argument")); len = *INTEGER(value); if (len < 0) Rf_error("%s",_("vector size cannot be negative")); else if (len == NA_INTEGER) Rf_error("%s",_("vector size cannot be NA")); break; case REALSXP: if (LENGTH(value) != 1) Rf_error("%s",_("invalid second argument")); len = (int)*REAL(value); if (len < 0) Rf_error("%s",_("vector size cannot be negative")); else if (! (R_FINITE (len ) ) ) Rf_error("%s",_("vector size cannot be NA, NaN, or Inf")); break; case STRSXP: // dunno why R spits out this strange error on "Length(foo) <- -1" // but I always follow the holy standard ;-) Rf_error("%s",_("negative length vectors are not allowed")); default: Rf_error("%s",_("invalid second argument")); } bigvec_q v =bigrationalR::create_bignum(vec); v.resize(len); return bigrationalR::create_SEXP(v); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP bigrational_is_na(SEXP a) { bigvec_q v = bigrationalR::create_bignum(a); SEXP ans = PROTECT(Rf_allocVector(LGLSXP, v.size())); int *a_ = LOGICAL(ans); for (unsigned int i = 0; i < v.size(); ++i) a_[i] = v[i].isNA(); UNPROTECT(1); return ans; } SEXP bigrational_is_int(SEXP a) { try { bigvec_q v = bigrationalR::create_bignum(a); SEXP ans = PROTECT(Rf_allocVector(LGLSXP, v.size())); int *a_ = LOGICAL(ans); mpz_t z_tmp; mpz_init(z_tmp); for (unsigned int i = 0; i < v.size(); ++i) { mpq_get_den(z_tmp,v[i].getValueTemp()); a_[i] = mpz_cmp_ui (z_tmp, 1) == 0; // <==> numerator == 1 } mpz_clear(z_tmp); UNPROTECT(1); return ans; } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP bigrational_c(SEXP args) { try { // if(TYPEOF( args ) != LISTSXP) // Rf_error("%s",_("should be a list")); bigvec_q result; for(int i = 0; i < Rf_length(args); i++) { bigvec_q v = bigrationalR::create_bignum(VECTOR_ELT(args,i)); for(unsigned int j=0; j < v.size(); j++) result.push_back(v[j]); v.value.clear(); } return bigrationalR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP bigrational_rep(SEXP x, SEXP times) { try { bigvec_q v = bigrationalR::create_bignum(x), result; unsigned int i,j, rep = (unsigned int )INTEGER(AS_INTEGER(times))[0]; result.value.reserve(v.size()*rep); for(i = 0 ; i< rep ; i++) for(j = 0 ; j < v.size() ; j++) result.push_back(v[j]); return bigrationalR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // Return max SEXP bigrational_max(SEXP a, SEXP narm) { try { bigvec_q va = bigrationalR::create_bignum(a), result; if(! va.size()) return bigrationalR::create_SEXP(result); unsigned int maximum = 0; int na_remove = Rf_asInteger(narm); for(unsigned int i = 1 ; i < va.size(); ++i) { if(va[i].isNA() && ! na_remove) return(bigrationalR::create_SEXP(result)); else if(!(va[i] < va[maximum] )) maximum = i; // if va.value[maximum = 0] is NA => false for the "<" => maximum changed = good } result.push_back(va[maximum]); return bigrationalR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // Return min SEXP bigrational_min(SEXP a, SEXP narm) { try { bigvec_q result, va = bigrationalR::create_bignum(a); if (! va.size()) return bigrationalR::create_SEXP(result); unsigned int minimum = 0; int na_remove = Rf_asInteger(narm); for(unsigned int i = 1 ; i < va.size(); ++i) { if(va[i].isNA() && !na_remove) return(bigrationalR::create_SEXP(result)); else if(!(va[i] > va[minimum] )) minimum = i; // if va.value[maximum = 0] is NA => false for the "<" => maximum changed = good } result.push_back(va[minimum]); return bigrationalR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // Return cumsum SEXP bigrational_cumsum(SEXP a) { try { bigvec_q result, va = bigrationalR::create_bignum(a); result.resize(va.size()); mpq_t val; mpq_init(val); mpq_t_sentry val_s(val); for(unsigned int i = 0 ; i < va.size(); ++i) { if(va[i].isNA() ) { break; // all last values are NA. } mpq_add(val,val,va[i].getValueTemp()); result[i].setValue(val); } return(bigrationalR::create_SEXP(result)); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // Return sum SEXP bigrational_sum(SEXP a) { try { bigvec_q result, va = bigrationalR::create_bignum(a); result.resize(1); mpq_t val; mpq_init(val); mpq_t_sentry val_s(val); for(unsigned int i = 0 ; i < va.size(); ++i) { if(va[i].isNA()) { break; // all last values are NA. } mpq_add(val,val,va[i].getValueTemp()); } result[0].setValue(val); return(bigrationalR::create_SEXP(result)); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // Return prod SEXP bigrational_prod(SEXP a) { try { bigvec_q result, va = bigrationalR::create_bignum(a); result.resize(1); mpq_t val; mpq_init(val); mpq_set_ui(val,1,1); mpq_t_sentry val_s(val); for(unsigned int i = 0 ; i < va.size(); ++i) { if(va[i].isNA() ) { return (bigrationalR::create_SEXP(result)); } mpq_mul(val,val,va[i].getValueTemp()); } result[0].setValue(val); return(bigrationalR::create_SEXP(result)); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } /* ================================ UNUSED ============================*/ // return x ^ y x: "bigq" y: "bigz" (or INTSXP, REALSXP -- TODO ?) SEXP bigrational_R_pow(SEXP x, SEXP y) { try { bigvec_q result, vx = bigrationalR::create_bignum(x); bigvec vy = bigintegerR::create_bignum(y); int size = (vx.size() ==0 || vy.size() == 0) ? 0 : max(vx.size(), vy.size()); mpq_t val; mpq_init(val); mpq_t_sentry val_s(val); mpz_t num, den; mpz_init(num); mpz_init(den); mpz_t_sentry val_n(num); mpz_t_sentry val_d(den); result.resize(size); for (int i = 0 ; i < size; i++) { int i_x = i % vx.size(), i_y = i % vy.size(); //fails: val.NA(false); if(vx[i_x].isNA() || vy[i_y].isNA()) break; // else -- res[i] := x[i] ^ y[i] = (num ^ y_i) / (den ^ y_i) ---- if(mpz_sgn(vy[i_y].getValueTemp()) < 0){ char msg[100]; snprintf(msg,100,"Negative powers not yet implemented [i = %d]", i_y +1); throw invalid_argument(msg); } if (!mpz_fits_ulong_p(vy[i_y].getValueTemp())){ char msg[100]; snprintf(msg,100,"exponent too large for pow [i = %d]", i_y +1); throw invalid_argument(msg); } int y_i = mpz_get_ui(vy[i_y].getValueTemp()); // *num = mpq_numref(vx[i].getValueTemp()); // *den = mpq_denref(vx[i].getValueTemp()); mpq_get_num(num, vx[i_x].getValueTemp()); mpq_get_den(den, vx[i_x].getValueTemp()); mpz_pow_ui(num, num, y_i); // num := num ^ y_i mpz_pow_ui(den, den, y_i); // den := den ^ y_i // val := as.bigq(num, den) : mpz_set(mpq_numref(val), num); mpz_set(mpq_denref(val), den); /* Simplify numerator and denominator */ mpq_canonicalize(val); result[i].setValue(val); } return bigrationalR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // ..._pow() gmp/src/matrixq.cc0000644000176200001440000003175014662140130013623 0ustar liggesusers/************************************************************/ /*! \file matrixq.cc * \brief C++ function to add matrix support * * \version 1 * * \date Created: 19/02/06 * \date Last modified: Time-stamp: <2023-01-28 15:51:42 (antoine)> * * \author A. Lucas * * \note * as usually, matrix x[i,j] (n x p) is represented by a vector * x[i + j x n] (i=0..n-1 ; j=0..p-1) * * \note Licence: GPL (>= 2) */ //#include #include using namespace std; #include "Rgmp.h" #include "bigrational.h" #include "bigrationalR.h" #include "matrixq.h" #include // function called by matrix.bigz() SEXP as_matrixq (SEXP x, SEXP nrR, SEXP ncR, SEXP byrowR, SEXP den) { try { /* get "bigz" vector, this makes all conversion int to bigz etc...*/ bigvec_q mat = bigrationalR::create_bignum(x), denominator = bigrationalR::create_bignum(den); int nc= INTEGER(ncR)[0]; int nr= INTEGER(nrR)[0]; int byrow= INTEGER(byrowR)[0]; int lendat = mat.size(); if(denominator.value.size()>0) // should be allways the case if(!denominator.value[0].isNA()) { for (unsigned int i = 0; i < mat.size(); i++) if(mat.value[i].isNA() && (denominator.value[i%denominator.size()].sgn() != 0) ) mat.value[i].setDenValue (denominator.value[i%denominator.size()].getValueTemp()); } /* A copy from R project to get correct dimension * all warnings... */ if (nr == NA_INTEGER){ /* This is < 0 */ throw invalid_argument(_("matrix: invalid 'nrow' value (too large or NA)")); } if (nr < 0) throw invalid_argument(_("matrix: invalid 'nrow' value (< 0)")); if (nc < 0) throw invalid_argument(_("matrix: invalid 'ncol' value (< 0)")); if (nc == NA_INTEGER) throw invalid_argument(_("matrix: invalid 'ncol' value (too large or NA)")); if(lendat > 0 ) { if (lendat > 1 && (nr * nc) % lendat != 0) { if (((lendat > nr) && (lendat / nr) * nr != lendat) || ((lendat < nr) && (nr / lendat) * lendat != nr)) Rf_warning("data length [%d] is not a sub-multiple or multiple of the number of rows [%d] in matrix", lendat, nr); else if (((lendat > nc) && (lendat / nc) * nc != lendat) || ((lendat < nc) && (nc / lendat) * lendat != nc)) Rf_warning("data length [%d] is not a sub-multiple or multiple of the number of columns [%d] in matrix", lendat, nc); } else if ((lendat > 1) && (nr * nc == 0)){ Rf_warning("data length exceeds size of matrix"); } } /* update dimension parameters */ if(nr == 1) nr = (int)ceil(lendat / (double) nc); if(nc == 1) nc = (int)ceil(lendat / (double)nr); /* when we extend "x" */ if(nc*nr > lendat) { mat.value.resize(nr*nc); for(int i = lendat; i < nr*nc; i++) mat.value[i] = mat.value[i % lendat]; } mat.nrow = nr; if(byrow) { bigvec_q mat2 = matrixq::bigq_transpose (mat); mat2.nrow = nr; return( bigrationalR::create_SEXP (mat2)); } return( bigrationalR::create_SEXP (mat)); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // function called by t(m) when m is a bigrational SEXP bigq_transposeR(SEXP x) { try{ SEXP strAttr = Rf_mkString("nrow"); PROTECT(strAttr); SEXP dimAttr = Rf_getAttrib(x, strAttr); PROTECT(dimAttr); bigvec_q mat = bigrationalR::create_bignum(x); int nr, n = mat.size(); if (dimAttr == R_NilValue) { // vector nr = n; } else if (TYPEOF(dimAttr) == INTSXP) { nr = INTEGER(dimAttr)[0]; } else { mat.clear(); throw invalid_argument(_("argument must be a matrix of class \"bigq\"")); nr = -1;// -Wall } mat.nrow = nr; int nc = (int) n / nr; bigvec_q mat_transp = matrixq::bigq_transpose(mat); mat_transp.nrow = nc; // FIXME - needed ? UNPROTECT(2); return( bigrationalR::create_SEXP( mat_transp)); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } /* \brief matrix cross product * * returns crossprod(a) := t(a) %*% a [p x p] or * tcrossprod(a) := a %*% t(a) [n x n] * \param a matrix (n x p) * \param trans if(trans), compute tcrossprod(), else crossprod() */ SEXP matrix_crossp_q (SEXP a, SEXP trans) { try { bool tr = (bool)Rf_asLogical(trans); bigvec_q mat_a = bigrationalR::create_bignum(a); int a_nrow = mat_a.nrow, a_len = mat_a.size(); // in case of a vector; crossprod() returns scalar product, // whereas tcrossprod() gives n x n matrix. if(a_nrow < 0) a_nrow = a_len; int a_ncol = a_len / a_nrow; // Result R is R[1..m, 1..m] -- and R_{ij} = sum_{k=1}^p A.. B.. unsigned int m, p; if(tr) { // tcrossprod() m= a_nrow; p= a_ncol; } else { // crossprod() m= a_ncol; p= a_nrow; } bigvec_q res(m*m); res.nrow= m; mpq_t R_ij, tt; mpq_init(R_ij); mpq_init(tt); // here the computation: for(unsigned int i=0; i < m; i++) for(unsigned int j=0; j < m; j++) { mpq_set_ui(R_ij, 0,1); bool isna = false; #define K_LOOP \ for(unsigned int k=0; k < p; k++) { \ /* R_ij = \sum_{k=1}^p a_{ik} b_{kj} */ \ if( !(A_I_K.isNA() || B_K_J.isNA())) { \ mpq_mul(tt, A_I_K.getValueTemp(), B_K_J.getValueTemp()); \ mpq_add(R_ij, tt,R_ij); \ } \ else { \ isna = true; break; \ } \ } if(tr) {//------------- tcrossprod --------------------------- #define A_I_K mat_a[ i + k *a_nrow] #define B_K_J mat_a[ j + k *a_nrow] K_LOOP #undef A_I_K #undef B_K_J } else {//------------- crossprod --------------------------- #define A_I_K mat_a[ k + i *a_nrow] #define B_K_J mat_a[ k + j *a_nrow] K_LOOP #undef A_I_K #undef B_K_J } if(isna) { res.value[i + j*m].setValue(0); res.value[i + j*m].NA(true); } else res.value[i + j*m].setValue(R_ij); } mpq_clear(R_ij); mpq_clear(tt); #undef K_LOOP return( bigrationalR::create_SEXP (res)); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // matrix_crossp_q() /** \brief matrix multiplication * * returns matrix multiplication T(a) %*% b or b %*% T(a) * \param a is of dimension n x p * \param b is of dimension p x m * \param op operation code: 0: %*%, 1: crossprod, 2: tcrossprod * (same codes as in R's do_matprod() in src/main/array.c ) */ SEXP matrix_mul_q (SEXP a, SEXP b, SEXP op) { try { int o_ = Rf_asInteger(op); // INTEGER(op)[0] bigvec_q mat_a = bigrationalR::create_bignum(a), mat_b = bigrationalR::create_bignum(b); int a_nrow = mat_a.nrow, a_len = mat_a.size(), b_nrow = mat_b.nrow, b_len = mat_b.size(), a_ncol = -1, b_ncol = -1;// -Wall // distinguish cases of vectors / matrices --------------------- if(a_nrow < 0) { if(b_nrow < 0) { // *both* are vectors if(o_ == 0) { a_nrow = 1; a_ncol = a_len; } else { a_nrow = a_len; a_ncol = 1; } b_nrow = b_len; b_ncol = 1; } else { // a : vector, b : matrix b_ncol = b_len / b_nrow; if(o_ == 0) { if (a_len == b_nrow) { /* x as row vector */ a_nrow = 1; a_ncol = b_nrow; /* == a_len */ } else if (b_nrow == 1) { /* x as col vector */ a_nrow = a_len; a_ncol = 1; } } else if(o_ == 1) { /* crossprod() */ if (a_len == b_nrow) { /* x is a col vector */ a_nrow = b_nrow; /* == a_len */ a_ncol = 1; } /* else if (b_nrow == 1) ... not being too tolerant to treat x as row vector, as t(x) *is* row vector */ } else { // o_ == 2 -- tcrossprod() if (a_len == b_ncol) { /* x as row vector */ a_nrow = 1; a_ncol = b_ncol; /* == a_len */ } else if (b_ncol == 1) { /* x as col vector */ a_nrow = a_len; a_ncol = 1; } } } } else if (b_nrow < 0) { // a : matrix, b : vector a_ncol = a_len / a_nrow; if (o_ == 0) { if (b_len == a_ncol) { /* y as col vector */ b_nrow = a_ncol; b_ncol = 1; } else if (a_ncol == 1) { /* y as row vector */ b_nrow = 1; b_ncol = b_len; } } else if (o_ == 1) { /* crossprod() */ if (b_len == a_nrow) { /* y is a col vector */ b_nrow = a_nrow; b_ncol = 1; } } else { /* tcrossprod -- y is a col vector */ b_nrow = b_len; b_ncol = 1; } } else { // a, b *both* matrices a_ncol = a_len / a_nrow; b_ncol = b_len / b_nrow; } if(((o_ == 0) && (a_ncol != b_nrow)) || ((o_ == 1) && (a_nrow != b_nrow)) || // crossprod() ((o_ == 2) && (a_ncol != b_ncol)) // tcrossprod() ){ mat_a.clear(); mat_b.clear(); throw invalid_argument(_("Matrix dimensions do not match")); } // Result R is R[1..n, 1..m] -- and R_{ij} = sum_{k=1} ^ p A.. B.. int n,m, p; if(o_ == 0) { n= a_nrow; m= b_ncol; p= a_ncol;// = b_nrow }else if (o_ == 1) { n= a_ncol; m= b_ncol; p= a_nrow;// = b_nrow }else if (o_ == 2) { n= a_nrow; m= b_nrow; p= a_ncol;// = b_ncol }else { mat_a.clear(); mat_b.clear(); throw invalid_argument(_("invalid 'op' code in matrix_mul_z()")); n = m = p = -1;// -Wall } bigvec_q res(n*m); res.nrow=n; mpq_t tt, R_ij; mpq_init(R_ij); mpq_init(tt); // here the computation: for(int i=0; i < n; i++) for(int j=0; j < m; j++) { mpq_set_ui(R_ij, 0,1); bool isna = false; #define K_LOOP \ for(int k=0; k < p; k++) { \ /* R_ij = \sum_{k=1}^p a_{ik} b_{kj} */ \ if( !(A_I_K.isNA() || B_K_J.isNA())) { \ mpq_mul(tt, A_I_K.getValueTemp(), B_K_J.getValueTemp()); \ mpq_add(R_ij, tt,R_ij); \ } \ else { \ isna = true; break; \ } \ } if(o_ == 0) { //------------- %*% -------------------------------------- #define A_I_K mat_a[ i + k *a_nrow] #define B_K_J mat_b[ k + j *b_nrow] K_LOOP #undef A_I_K #undef B_K_J } else if(o_ == 1){//------------- crossprod --------------------------- #define A_I_K mat_a[ k + i *a_nrow] #define B_K_J mat_b[ k + j *b_nrow] K_LOOP #undef A_I_K #undef B_K_J } else {//(o_ == 2) ------------- tcrossprod --------------------------- #define A_I_K mat_a[ i + k *a_nrow] #define B_K_J mat_b[ j + k *b_nrow] K_LOOP #undef A_I_K #undef B_K_J } if(isna) { res.value[i + j*n].setValue(0); res.value[i + j*n].NA(true); } else res.value[i + j*n].setValue(R_ij); } mpq_clear(R_ij); mpq_clear(tt); return( bigrationalR::create_SEXP (res)); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // matrix_mul_q() #undef K_LOOP SEXP bigrational_rbind(SEXP args) { try { bigvec_q result; bigvec_q v; vector source; unsigned int maxSize=0; for( int i = 0 ; i < LENGTH(args) ; i++){ v = bigrationalR::create_bignum(VECTOR_ELT(args,i)); if(v.size() == 0) continue; for (unsigned int row = 0 ; row < v.nRows(); row++){ bigvec_q line ; for(unsigned int col = 0 ; col < v.nCols(); col++){ line.push_back(v.get(row,col)); } source.push_back(line); maxSize = std::max(maxSize,line.size()); } } for (unsigned int j = 0 ; j < maxSize; j++){ for(unsigned int i = 0 ; i < source.size() ; i++){ bigvec_q u = source[i]; if(u.size() == 0) result.push_back(bigrational()); else result.push_back(u[j % u.size()]); } } result.nrow = source.size(); return bigrationalR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP bigrational_cbind(SEXP args){ try { bigvec_q result; bigvec_q v; vector source; unsigned int maxSize=0; for( int i = 0 ; i < LENGTH(args) ; i++){ v = bigrationalR::create_bignum(VECTOR_ELT(args,i)); if(v.size() == 0) continue; if(v.nrow <0) v.nrow = v.size(); for(unsigned int col = 0 ; col < v.nCols(); col++){ bigvec_q column ; for (unsigned int row = 0 ; row < v.nRows(); row++){ column.push_back(v.get(row,col)); } source.push_back(column); maxSize = std::max(maxSize,column.size()); } } for(unsigned int i = 0 ; i < source.size() ; i++){ bigvec_q u = source[i]; for (unsigned int j = 0 ; j < maxSize; j++){ if(u.size() == 0) result.push_back(bigrational()); else result.push_back(u[j % u.size()]); } } result.nrow = result.size() / source.size(); return bigrationalR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } bigvec_q matrixq::bigq_transpose (const bigvec_q & mat) { bigvec_q matbis ( mat.size()); matbis.nrow = mat.nCols(); /* we compute transpose */ for(unsigned int i=0; i < mat.nRows(); i++) for(unsigned int j=0; j < mat.nCols(); j++) matbis.value[j+i*mat.nCols()].setValue(mat.value[i+j*mat.nRows()]); return(matbis); } gmp/src/matrix.cc0000644000176200001440000003661714662140037013457 0ustar liggesusers/************************************************************/ /*! \file matrix.cc * \brief C++ function to add matrix support * * \version 1 * * \date Created: 19/02/06 * \date Last modified: Time-stamp: <2023-02-03 12:03:33 (antoine)> * * \author A. Lucas * * \note * as usually, matrix x[i,j] (n x p) is represented by a vector * x[i + j x n] (i=0..n-1 ; j=0..p-1) * * \note Licence: GPL (>= 2) */ #include #include using namespace std; #include "bigintegerR.h" #include "matrix.h" // need to call matrix_mul_q() #include "matrixq.h" // given that x is "bigz" or "bigq", // return TRUE if x is a bigz/q *matrix*: R's is.matrixZQ(.) SEXP is_matrix_zq(SEXP x) { SEXP nrowSexp = Rf_mkString("nrow"); PROTECT(nrowSexp); SEXP attributeRow = Rf_getAttrib(x,nrowSexp ); PROTECT(attributeRow); SEXP ans = Rf_ScalarLogical(attributeRow != R_NilValue); UNPROTECT(2); return ans; } // C++ side of R function matrix.bigz() SEXP as_matrixz (SEXP x, SEXP nrR, SEXP ncR, SEXP byrowR, SEXP mod) { try{ int nc=INTEGER(ncR)[0], nr=INTEGER(nrR)[0], byrow=INTEGER(byrowR)[0]; // get "bigz" vector, this makes all conversion int to bigz etc... bigvec mat = bigintegerR::create_bignum(x); int lendat = mat.size(); // int sizemod = mat.modulus.size(); // when modulus specified bigvec modulus = bigintegerR::create_bignum(mod); // A copy from R project to get correct dimension // all warnings... // if (nr == NA_INTEGER){ // This is < 0 throw invalid_argument(_("matrix: invalid 'nrow' value (too large or NA)")); } if (nr < 0){ throw invalid_argument(_("matrix: invalid 'nrow' value (< 0)")); } if (nc < 0){ throw invalid_argument(_("matrix: invalid 'ncol' value (< 0)")); } if (nc == NA_INTEGER){ throw invalid_argument(_("matrix: invalid 'ncol' value (too large or NA)")); } if(lendat > 0 ) { if (lendat > 1 && (nr * nc) % lendat != 0) { if (((lendat > nr) && (lendat / nr) * nr != lendat) || ((lendat < nr) && (nr / lendat) * lendat != nr)) Rf_warning("data length [%d] is not a sub-multiple or multiple of the number of rows [%d] in matrix", lendat, nr); else if (((lendat > nc) && (lendat / nc) * nc != lendat) || ((lendat < nc) && (nc / lendat) * lendat != nc)) Rf_warning("data length [%d] is not a sub-multiple or multiple of the number of columns [%d] in matrix", lendat, nc); } else if ((lendat > 1) && (nr * nc == 0)){ Rf_warning("data length exceeds size of matrix"); } } // update dimension parameters if(nr == 1) nr = (int)ceil(lendat / (double) nc); if(nc == 1) nc = (int)ceil(lendat / (double)nr); // when we extend "x" if(nc*nr > lendat) { mat.resize(nr*nc); for(int i = lendat; i < nr*nc; i++) mat[i] = mat[i % lendat]; } mat.nrow = nr; if(modulus.size()>0) {// should be allways the case if(modulus[0].isNA()) { // nothing but mat could have already a modulus } else { for (unsigned int i = 0; i < mat.size(); i++){ mat[i].setModulus(modulus[i % modulus.size()].getValuePtr()); } if(modulus.size() == 1){ mat.setGlobalModulus(modulus[0].getValuePtr()); } mat.setType( modulus.size() == 1 ? TYPE_MODULUS::MODULUS_GLOBAL : TYPE_MODULUS::MODULUS_BY_CELL); // sizemod = modulus.size(); } } if(byrow) { bigvec mat2 = matrixz::bigint_transpose (mat); return( bigintegerR::create_SEXP (mat2)); } return( bigintegerR::create_SEXP (mat)); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } /* * Transposition */ SEXP bigint_transposeR(SEXP x) { try{ SEXP dimKey =Rf_mkString("nrow"); PROTECT(dimKey); SEXP dimAttr = Rf_getAttrib(x,dimKey ); PROTECT(dimAttr); bigvec mat = bigintegerR::create_bignum(x); int nr, n = mat.size(); if (dimAttr == R_NilValue) { // vector nr = n; } else if (TYPEOF(dimAttr) == INTSXP) { nr = INTEGER(dimAttr)[0]; } else { nr = -1;// -Wall mat.clear(); throw invalid_argument(_("argument must be a matrix of class \"bigz\"")); } UNPROTECT(2); mat.nrow = nr; // Rprintf(" o bigI_tr(<%d x %d>) ..\n", nr,nc); return( bigintegerR::create_SEXP(matrixz::bigint_transpose(mat))); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } /* \brief matrix cross product * * \param a matrix (n x p) * \param trans if(trans), compute tcrossprod(), else crossprod() * \return crossprod(a) := t(a) %*% a [p x p] or * tcrossprod(a) := a %*% t(a) [n x n] */ SEXP matrix_crossp_z (SEXP a, SEXP trans) { try{ bool useMod = FALSE, tr = (bool)Rf_asLogical(trans); bigvec mat_a = bigintegerR::create_bignum(a); int sizemod = mat_a.getModulusSize(), a_nrow = mat_a.nrow, a_len = mat_a.size(); // in case of a vector; crossprod() returns scalar product, // whereas tcrossprod() gives n x n matrix. if(a_nrow < 0) a_nrow = a_len; int a_ncol = a_len / a_nrow; // Result R is R[1..m, 1..m] -- and R_{ij} = sum_{k=1}^p A.. B.. int m, p; if(tr) { // tcrossprod() m= a_nrow; p= a_ncol; } else { // crossprod() m= a_ncol; p= a_nrow; } bigvec res(m*m); res.nrow= m; mpz_t R_ij, tt; mpz_init(R_ij); mpz_init(tt); mpz_t common_modulus; mpz_init(common_modulus); if(sizemod == 1) { mpz_set(common_modulus, mat_a.getGlobalModulus()->getValueTemp()); useMod = TRUE; } // here the computation: for(int i=0; i < m; i++) for(int j=0; j < m; j++) { mpz_set_ui(R_ij, 0); bool isna = false; #define K_LOOP \ for(int k=0; k < p; k++) { \ /* R_ij = \sum_{k=1}^p a_{ik} b_{kj} */ \ if( !(A_I_K.isNA() || B_K_J.isNA())) { \ mpz_mul(tt, A_I_K.getValueTemp(), B_K_J.getValueTemp()); \ mpz_add(R_ij, tt,R_ij); \ } \ else { \ isna = true; break; \ } \ } if(tr) {//------------- tcrossprod --------------------------- #define A_I_K mat_a [ i + k *a_nrow] #define B_K_J mat_a [ j + k *a_nrow] K_LOOP #undef A_I_K #undef B_K_J } else {//------------- crossprod --------------------------- #define A_I_K mat_a [ k + i *a_nrow] #define B_K_J mat_a [ k + j *a_nrow] K_LOOP #undef A_I_K #undef B_K_J } if(isna) { res[i + j*m].setValue(0); res[i + j*m].getValue().NA(true); } else res[i + j*m].setValue(R_ij); } // for(i ..) for(j ..) if(useMod) { std::shared_ptr ptr = std::make_shared(common_modulus); res.setGlobalModulus(ptr); } mpz_clear(R_ij); mpz_clear(tt); mpz_clear(common_modulus); return( bigintegerR::create_SEXP (res)); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // matrix_crossp_z() #undef K_LOOP /* \brief matrix multiplication * * returns matrix multiplication T(a) %*% b or b %*% T(a) * \param a matrix * \param b matrix * \param op operation code: 0: %*%, 1: crossprod, 2: tcrossprod * (same codes as in R's do_matprod() in src/main/array.c ) */ SEXP matrix_mul_z (SEXP a, SEXP b, SEXP op) { try{ if(!strcmp(class_P(b), "bigq")) { // b "bigq", --> use q arithm: return(matrix_mul_q(a, b, op)); } // FIXME: we may know that a is 'bigz' - but we don't know at all about b !! // ----- create_bignum(.) should be much more careful (better: have a careful option!) bool useMod = FALSE;// if(useMod) use a *common* modulus int o_ = Rf_asInteger(op); // INTEGER(op)[0] bigvec mat_a = bigintegerR::create_bignum(a), mat_b = bigintegerR::create_bignum(b); int a_nrow = mat_a.nrow, a_len = mat_a.size(), b_nrow = mat_b.nrow, b_len = mat_b.size(), a_ncol = -1, b_ncol = -1;// -Wall // distinguish cases of vectors / matrices --------------------- if(a_nrow < 0) { if(b_nrow < 0) { // *both* are vectors if(o_ == 0) { a_nrow = 1; a_ncol = a_len; } else { a_nrow = a_len; a_ncol = 1; } b_nrow = b_len; b_ncol = 1; } else { // a : vector, b : matrix b_ncol = b_len / b_nrow; if(o_ == 0) { if (a_len == b_nrow) { /* x as row vector */ a_nrow = 1; a_ncol = b_nrow; /* == a_len */ } else if (b_nrow == 1) { /* x as col vector */ a_nrow = a_len; a_ncol = 1; } } else if(o_ == 1) { /* crossprod() */ if (a_len == b_nrow) { /* x is a col vector */ a_nrow = b_nrow; /* == a_len */ a_ncol = 1; } /* else if (b_nrow == 1) ... not being too tolerant to treat x as row vector, as t(x) *is* row vector */ } else { // o_ == 2 -- tcrossprod() if (a_len == b_ncol) { /* x as row vector */ a_nrow = 1; a_ncol = b_ncol; /* == a_len */ } else if (b_ncol == 1) { /* x as col vector */ a_nrow = a_len; a_ncol = 1; } } } } else if (b_nrow < 0) { // a : matrix, b : vector a_ncol = a_len / a_nrow; if (o_ == 0) { if (b_len == a_ncol) { /* y as col vector */ b_nrow = a_ncol; b_ncol = 1; } else if (a_ncol == 1) { /* y as row vector */ b_nrow = 1; b_ncol = b_len; } } else if (o_ == 1) { /* crossprod() */ if (b_len == a_nrow) { /* y is a col vector */ b_nrow = a_nrow; b_ncol = 1; } } else { /* tcrossprod -- y is a col vector */ b_nrow = b_len; b_ncol = 1; } } else { // a, b *both* matrices a_ncol = a_len / a_nrow; b_ncol = b_len / b_nrow; } if(((o_ == 0) && (a_ncol != b_nrow)) || ((o_ == 1) && (a_nrow != b_nrow)) || // crossprod() ((o_ == 2) && (a_ncol != b_ncol)) // tcrossprod() ){ mat_a.clear(); mat_b.clear(); throw invalid_argument(_("Matrix dimensions do not match")); } // Result R is R[1..n, 1..m] -- and R_{ij} = sum_{k=1} ^ p A.. B.. int n,m, p; if(o_ == 0) { n= a_nrow; m= b_ncol; p= a_ncol;// = b_nrow }else if (o_ == 1) { n= a_ncol; m= b_ncol; p= a_nrow;// = b_nrow }else if (o_ == 2) { n= a_nrow; m= b_nrow; p= a_ncol;// = b_ncol }else { mat_a.clear(); mat_b.clear(); throw invalid_argument(_("invalid 'op' code in matrix_mul_z()")); n = m = p = -1;// -Wall } bigvec res(n*m); res.nrow=n; mpz_t common_modulus, tt; mpz_init(tt); mpz_init(common_modulus); /* modulus when modulus are "global" (i.e. of size 1) and * either are the same, or only one of a or b is specified */ std::shared_ptr globalMod = bigvec::getGlobalModulus(mat_a,mat_b); useMod = globalMod.get() != nullptr; if(useMod){ mpz_init_set(common_modulus,globalMod->getValueTemp()); } // bigmod tmp; // here the computation: for(int i=0; i < n; i++) for(int j=0; j < m; j++) { #define R_IJ res[ i + j*n] #define K_LOOP \ for(int k=0; k < p; k++) \ { \ if(A_I_K.isNA() || B_K_J.isNA()) { \ R_IJ.setValue(0); R_IJ.getValue().NA(true); \ break; \ } \ /* Z = A_I_K * B_K_J */ \ mpz_mul(tt, A_I_K.getValueTemp(), B_K_J.getValueTemp()); \ /* R_IJ = R_IJ + A_I_K * B_K_J */ \ mpz_add(tt, tt, R_IJ.getValueTemp()); \ if(useMod) \ mpz_mod(tt,tt,common_modulus); \ R_IJ.setValue(tt); \ } R_IJ.setValue(0); if(o_ == 0) { //------------- %*% --------------------------- #define A_I_K mat_a [ i + k *a_nrow] #define B_K_J mat_b [ k + j *b_nrow] K_LOOP #undef A_I_K #undef B_K_J } else if(o_ == 1){//------------- crossprod --------------------------- #define A_I_K mat_a [ k + i *a_nrow] #define B_K_J mat_b [ k + j *b_nrow] K_LOOP #undef A_I_K #undef B_K_J } else {//(o_ == 2) ------------- tcrossprod --------------------------- #define A_I_K mat_a [ i + k *a_nrow] #define B_K_J mat_b [ j + k *b_nrow] K_LOOP #undef A_I_K #undef B_K_J } } if(useMod){ std::shared_ptr ptr = std::make_shared(common_modulus); res.setGlobalModulus(ptr); } mpz_clear(tt); mpz_clear(common_modulus); return( bigintegerR::create_SEXP (res)); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } // matrix_mul_z() #undef R_IJ #undef K_LOOP /** * arg = v1, v2, v3.... lines * return matrix * out =[ v1 v2 v3 ] */ SEXP biginteger_rbind(SEXP args) { try{ bigvec result; vector source; unsigned int maxSize=0; for(int i = 0 ; i < LENGTH(args) ; i++){ bigvec v = bigintegerR::create_bignum(VECTOR_ELT(args,i)); if(v.size() == 0) continue; for (unsigned int row = 0 ; row < v.nRows(); row++){ bigvec * line = new bigvec(); for(unsigned int col = 0 ; col < v.nCols(); col++){ line->push_back(v.get(row,col)); } source.push_back(line); maxSize = std::max(maxSize,line->size()); } } for (unsigned int j = 0 ; j < maxSize; j++){ for(unsigned int i = 0 ; i < source.size() ; i++){ bigvec * u = source[i]; if(u->size() == 0) result.push_back(bigmod()); else result.push_back((*u)[j % u->size()]); } } result.nrow = source.size(); for (unsigned int i = 0 ; i < source.size() ; i++){ if(source[i] != nullptr) delete source[i]; source[i] = nullptr; } return bigintegerR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } /** * arg = v1, v2, v3.... row * return matrix * out =[ v1 v2 v3 ] */ SEXP biginteger_cbind(SEXP args) { try{ bigvec result; vector source; unsigned int maxSize=0; for(int i = 0 ; i < LENGTH(args) ; i++){ bigvec v = bigintegerR::create_bignum(VECTOR_ELT(args,i)); if(v.size() == 0) continue; if(v.nrow <0) v.nrow = v.size(); for(unsigned int col = 0 ; col < v.nCols(); col++){ bigvec * column = new bigvec(); for (unsigned int row = 0 ; row < v.nRows(); row++){ column->push_back(v.get(row,col)); } source.push_back(column); maxSize = std::max(maxSize,column->size()); } } for(unsigned int i = 0 ; i < source.size() ; i++){ bigvec * u = source[i]; for (unsigned int j = 0 ; j < maxSize; j++){ if(u->size() == 0) result.push_back(bigmod()); else result.push_back((*u)[j % u->size()]); } } result.nrow = result.size() / source.size(); for (unsigned int i = 0 ; i < source.size() ; i++){ if(source[i] != nullptr) delete source[i]; source[i] = nullptr; } return bigintegerR::create_SEXP(result); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } namespace matrixz { bigvec bigint_transpose ( bigvec & mat) { bigvec matbis (mat.size()); matbis.nrow = mat.nCols(); if(mat.getType() == MODULUS_GLOBAL){ matbis.setGlobalModulus(mat.getGlobalModulus()); } /* we compute transpose */ for(unsigned int i =0; i 0 && dimb > 0) { if (dimb != dima) return -2; //error(_("Matrix dimensions do not match")); } else { /* either a or b is a matrix */ if(dima == -1) return(dimb); } return(dima); } } gmp/src/apply.cc0000644000176200001440000000542714662051766013305 0ustar liggesusers#include #include "bigintegerR.h" #include #include // and one thing from Rdefines.h : #define NEW_LIST(n) Rf_allocVector(VECSXP,n) #include "apply.h" #include "bigrationalR.h" // X a matrix, or a bigz integer // line: true = we return a list of all lines // SEXP gmpMatToListZ(SEXP X, SEXP line) { SEXP ans; // dangerous... no check => use with care in R int lines = INTEGER(line)[0]; bigvec matrix = bigintegerR::create_bignum(X); unsigned int ncol = matrix.size() / matrix.nrow; unsigned int nrow = matrix.nrow; if(lines == 1) { // RETURN a list of all lines PROTECT (ans = NEW_LIST(matrix.nrow) ); try{ for(unsigned int i = 0; i < nrow; ++i) { bigvec oneLine ; for(unsigned int j = 0; j < ncol; ++j) { oneLine.push_back(matrix[i+j*nrow]); } SET_VECTOR_ELT(ans, i,bigintegerR::create_SEXP(oneLine)); } } catch(std::invalid_argument & e){ perror(e.what()); } UNPROTECT(1); } else { // RETURN a list of all rows ! PROTECT (ans = NEW_LIST(ncol) ); try{ for(unsigned int j = 0; j < ncol; ++j) { bigvec oneLine ; for(unsigned int i = 0; i < nrow; ++i) { oneLine.push_back(matrix[i+j*nrow]); } SET_VECTOR_ELT(ans, j,bigintegerR::create_SEXP(oneLine)); } } catch(std::invalid_argument & e){ perror(e.what()); } UNPROTECT(1); } return(ans); } // X a matrix, or a bigq rational // line: true = we return a list of all lines // SEXP gmpMatToListQ(SEXP X, SEXP line) { SEXP ans; // dangerous... no check => use with care in R int lines = INTEGER(line)[0]; bigvec_q matrix = bigrationalR::create_bignum(X); unsigned int ncol = matrix.size() / matrix.nrow; unsigned int nrow = matrix.nrow; if(lines == 1) { // RETURN a list of all lines PROTECT (ans = NEW_LIST(matrix.nrow) ); try { for(unsigned int i = 0; i < nrow; ++i) { bigvec_q oneLine ; for(unsigned int j = 0; j < ncol; ++j) { oneLine.value.push_back(matrix.value[i+j*nrow]); } SET_VECTOR_ELT(ans, i,bigrationalR::create_SEXP(oneLine)); } } catch(std::invalid_argument & e){ perror(e.what()); } UNPROTECT(1); } else { // RETURN a list of all rows ! PROTECT (ans = NEW_LIST(ncol) ); try { for(unsigned int j = 0; j < ncol; ++j) { bigvec_q oneLine ; for(unsigned int i = 0; i < nrow; ++i) { oneLine.value.push_back(matrix.value[i+j*nrow]); } SET_VECTOR_ELT(ans, j,bigrationalR::create_SEXP(oneLine)); } } catch(std::invalid_argument & e){ perror(e.what()); } UNPROTECT(1); } return(ans); } gmp/src/bigrationalR.h0000644000176200001440000001145014444267421014423 0ustar liggesusers/*! \file bigrationalR.h * \brief header for C++ functions that deals with both bigrational and R * * \version 1 * * \date Created: 2005 * \date Last modified: Time-stamp: <2023-01-24 16:31:53 (antoine)> * * * \note Licence: GPL (>= 2) */ #ifndef BIG_RATIONALRRRR_ #define BIG_RATIONALRRRR_ 1 #include "bigvec_q.h" typedef bigrational (*bigrational_binary_fn) (const bigrational&, const bigrational&); typedef bigrational (*bigrational_bigz_binary_fn)(const bigrational&, const biginteger&); typedef bool (*bigrational_logical_binary_fn)(const bigrational&, const bigrational&); extern "C" { /** * \brief Addition of a and b */ SEXP bigrational_add(SEXP a, SEXP b); /** * \brief Subtraction of a and b */ SEXP bigrational_sub(SEXP a, SEXP b); /** * \brief Multiplication of a and b */ SEXP bigrational_mul(SEXP a, SEXP b); /** * \brief Quotient of a / b */ SEXP bigrational_div(SEXP a, SEXP b); /** * \brief Power a ^ b */ SEXP bigrational_pow(SEXP a, SEXP b); /** * \brief Return Numerator of a */ SEXP bigrational_num(SEXP a); /** * \brief Return Denominator of a */ SEXP bigrational_den(SEXP a); /** * \brief Return from vector a all elements specified in vector b */ SEXP bigrational_get_at(SEXP a, SEXP b); /** * \brief Return a vector with the values from src specified by * idx to sequentiell values from "value". */ SEXP bigrational_set_at(SEXP src, SEXP idx, SEXP value); /** * \brief Convert from one or 2 long value or a string or * bigz into bigrational. * */ SEXP bigrational_as(SEXP n, SEXP d); /** * \brief Convert from a bigrational vector to a character string vector. */ SEXP bigrational_as_character(SEXP a, SEXP b); /** * \brief Convert from a bigrational vector to a real vector. */ SEXP bigrational_as_numeric(SEXP a); /** * \brief Return the length of the vector */ SEXP bigrational_length(SEXP a); /** * \brief Returns a resized vector cut at end or filled with NA. */ SEXP bigrational_setlength(SEXP vec, SEXP value); /** * \brief Return whether the parameter is NA */ SEXP bigrational_is_na(SEXP a); /** * \brief ans[i] := a[i] is integer valued, i.e., has denom == 1 */ SEXP bigrational_is_int(SEXP a); /** * \brief Return whether a < b */ SEXP bigrational_lt(SEXP a, SEXP b); /** * \brief Return whether a > b */ SEXP bigrational_gt(SEXP a, SEXP b); /** * \brief Return whether a <= b */ SEXP bigrational_lte(SEXP a, SEXP b); /** * \brief Return whether a >= b */ SEXP bigrational_gte(SEXP a, SEXP b); /** * \brief Return whether a == b */ SEXP bigrational_eq(SEXP a, SEXP b); /** * \brief Return whether a != b */ SEXP bigrational_neq(SEXP a, SEXP b); /** * \brief For function c() */ SEXP bigrational_c(SEXP args) ; /** * \brief Create vector as n times x */ SEXP bigrational_rep(SEXP x, SEXP times) ; /** * \brief Return max */ SEXP bigrational_max(SEXP a, SEXP narm); /** * \brief Return min */ SEXP bigrational_min(SEXP a, SEXP narm); /** * \brief Return cumsum */ SEXP bigrational_cumsum(SEXP a); /** * \brief Return cumsum */ SEXP bigrational_sum(SEXP a); /** * \brief Return prod */ SEXP bigrational_prod(SEXP a); } /** * \brief set of function useful for manipulation of SEXP and bigvec_q * */ namespace bigrationalR{ bigvec_q create_vector(SEXP param); bigvec_q create_bignum(SEXP param); SEXP create_SEXP(const math::Matrix & v); SEXP bigrational_binary_operation (SEXP a, SEXP b, bigrational_binary_fn f); SEXP bigrational_binary_operation (const bigvec_q & a,const bigvec_q & b, bigrational_binary_fn f); SEXP bigrational_bigz_binary_operation (SEXP a, SEXP b, bigrational_bigz_binary_fn f); SEXP bigrational_logical_binary_operation(SEXP a, SEXP b, bigrational_logical_binary_fn f); typedef void (*gmpq_binary)(mpq_t, const mpq_t, const mpq_t); typedef void (*gmp_qz_binary)(mpq_t, const mpq_t, const mpz_t); bigrational create_bigrational(const bigrational& lhs, const bigrational& rhs, gmpq_binary f, bool zeroRhsAllowed = true); bigrational create_bigrational_z(const bigrational& lhs, const biginteger& rhs, gmp_qz_binary f, bool zeroRhsAllowed = true); bool lt(const bigrational& lhs, const bigrational& rhs); bool gt(const bigrational& lhs, const bigrational& rhs) ; bool lte(const bigrational& lhs, const bigrational& rhs) ; bool gte(const bigrational& lhs, const bigrational& rhs) ; bool eq(const bigrational& lhs, const bigrational& rhs); bool neq(const bigrational& lhs, const bigrational& rhs); // x ^ y (for biginteger y): void mpqz_pow(mpq_t result, const mpq_t x, const mpz_t y); } #endif gmp/src/bigvec.cc0000644000176200001440000001035014444267422013402 0ustar liggesusers #include "bigvec.h" static int count = 0; static int countAll = 0; /** \brief constructor * */ bigvec::bigvec(unsigned int size) : math::Matrix(), values(), type(NO_MODULUS), modulus(), nrow(-1) { count++; countAll++; for (unsigned int i=0 ; i < size; i++){ values.push_back(bigmod()); } } bigvec::bigvec(const bigvec & vecteur) : math::Matrix(), values(), type(vecteur.type), modulus(vecteur.modulus), nrow(vecteur.nrow) { count++; countAll++; // *this = vecteur; values.reserve(vecteur.size()); for(std::vector::const_iterator it= vecteur.values.begin(); it != vecteur.values.end(); ++it) { values.push_back(*it); } } bigvec::~bigvec(){ count--; // printf("bv %d %d \n",count, countAll); clear(); } // std::string bigvec::str(int i,int b) const { return values[i].str(b); } bigmod & bigvec::get(unsigned int row, unsigned int col) { return (*this)[row + col*nRows() % size()]; } bigmod & bigvec::operator[] (unsigned int i) { return values[i]; } const bigmod & bigvec::operator[] (unsigned int i) const { return values[i]; } void bigvec::set(unsigned int row, unsigned int col, const bigmod & val) { set( row + col*nRows(),val); } void bigvec::set(unsigned int i,const bigmod & val) { values[i] = val; if(type == NO_MODULUS){ if(val.getModulus().isNA()) return; if(i == 0 && values.size() == 1) { type = MODULUS_GLOBAL; modulus = val.getModulusPtr(); } else { type = MODULUS_BY_CELL; } } if(type == MODULUS_GLOBAL){ if(values.size() == 1){ modulus = val.getModulusPtr(); } else if(val.getModulus() != *modulus ){ type = MODULUS_BY_CELL; } } } void bigvec::push_back(const bigmod & number) { values.push_back(bigmod()); set(values.size()-1, number); } /** * insert int value */ void bigvec::push_back(int value_p) { push_back(biginteger(value_p)); } /** * insert int value */ void bigvec::push_back(biginteger & value_p) { push_back(bigmod(value_p)); } /** * Insert Big Integer value */ void bigvec::push_back(const __mpz_struct * value_p) { push_back(biginteger(value_p)); } // return size of value unsigned int bigvec::size() const { return(values.size()); } unsigned int bigvec::nRows() const { return abs(nrow); } // hummm. to avoid ! void bigvec::resize(unsigned int i) { values.resize(i); } // clear all void bigvec::clear() { values.clear(); type=NO_MODULUS; modulus=nullptr; nrow = -1; } // assignment operator bigvec & bigvec::operator= (const bigvec & rhs) { if(this != &rhs) { values.resize(0); modulus = rhs.modulus; type=rhs.type; for (unsigned int i = 0 ; i < rhs.size(); i++){ values.push_back(rhs[i]); } nrow = rhs.nrow; } return(*this); } // Comparison operator bool operator!=(const bigvec & rhs, const bigvec& lhs) { if( (rhs.size() != lhs.size()) || \ (rhs.nrow != lhs.nrow ) ) return(false); // check value for (unsigned int i = 0 ; i < rhs.size(); i++) { if(rhs[i] != lhs[i]) return(false); } return(true); } // never used void bigvec::print() { if(nrow > 0) { for(int i=0; i < nrow; ++i) { for(unsigned int j=0; j < (values.size() / nrow); ++j) Rprintf("%s\t", values[i+j* nrow].str(10).c_str() ); Rprintf("\n"); } } else { for(unsigned int i=0; i < values.size(); ++i) Rprintf("%s\t", values[i].str(10).c_str() ); Rprintf("\n"); } } void bigvec::setGlobalModulus(std::shared_ptr & val){ modulus = val; type = MODULUS_GLOBAL; for (unsigned int i = 0 ; i < values.size(); i++){ values[i].setModulus(val); } } std::shared_ptr bigvec::getGlobalModulus(bigvec & first, bigvec & second){ std::shared_ptr empty(nullptr); if(first.getType() == MODULUS_GLOBAL && second.getType() == NO_MODULUS) return first.getGlobalModulus(); if(first.getType() == NO_MODULUS && second.getType() == MODULUS_GLOBAL) return second.getGlobalModulus(); if(first.getType() == MODULUS_GLOBAL && second.getType() == MODULUS_GLOBAL) { return (*first.getGlobalModulus()) == (*second.getGlobalModulus()) ? first.getGlobalModulus() : empty; } return empty; } gmp/src/solve.cc0000644000176200001440000000676014662140222013273 0ustar liggesusers/*! \file solve.cc * \brief functions to solve matrix * * \version 1 * * \date Created: 25/05/06 * \date Last modified: Time-stamp: <2023-01-28 15:47:35 (antoine)> * * \author A. Lucas * * \note Licence: GPL (>= 2) */ #include "bigintegerR.h" #include "solve.h" #include "bigrationalR.h" using namespace std; // inverse a rational matrix SEXP inverse_q(SEXP A) { try{ bigvec_q a = bigrationalR::create_bignum(A); return(solve_gmp_R::inverse_q(a)); } catch(std::invalid_argument & e){ Rf_error("%s",e.what()); return Rf_mkString(0); } } SEXP solve_gmp_R::inverse_q(bigvec_q a) { if(a.nrow * a.nrow != (int) a.size()){ a.clear(); throw invalid_argument(_("Argument 1 must be a square matrix")); } bigvec_q b (a.size()); b.nrow = a.nrow; // initialize b to identity for(int i=0; i * R/biginteger.R (all.equal.bigz): fixed, notably for 'NA'. 2022-02-23 Antoine Lucas rework on operator[]. Fix bugs. 2021-03-29 Martin Maechler * R/Stirling-n-etc.R (dbinomQ): new; providing *exact* binomial probabilities. * DESCRIPTION (Version): 0.6-3 (not yet released) 2021-01-07 Martin Maechler * configure.ac: add definitions of CFLAGS etc as from R, from a suggestion by Kaspar Daniel Hansen. * DESCRIPTION (Version) : 0.6-2, released to CRAN 2020-07-30 Martin Maechler * R/bigq.R (roundQ): use simpler *vectorized* version, always returning 'bigq' (as documented). * tests/arith-ex.R: check it works. 2020-07-23 Martin Maechler * R/bigq.R (round, round0, roundQ): round0(): "round to even"; make 'round0()' the default argument to 'round(x, digits)'. 2020-06-12 Martin Maechler * R/biginteger.R (c_bigz): export, to be used, e.g., * R/bigq.R (c_bigq): on lapply(, Fn) to give a result, see * man/bigrational.Rd: the sapplyQ() utility in the examples. 2020-06-09 Martin Maechler * DESCRIPTION (Version): 0.6-1 (not yet released) * R/Stirling-n-etc.R (BernoulliQ): Bernoulli numbers as exact fractions. * R/zzz.R (NA_bigz_, NA_bigq_): analogous to `NA_integer_` etc 2020-06-06 Martin Maechler * NAMESPACE: use *same* S3method(, , ) for bigz and bigq, * R/bigq.R (add.big): so now "mixed" arithmetic and comparisons work 2020-06-06 Martin Maechler * DESCRIPTION (Version): 0.6-0 (not yet released) * R/biginteger.R (as.bigz): now as.bigz() keeps a modulus 2020-05-11 Martin Maechler * R/AllClasses-etc.R (.diff.big): diff.big[zq]() methods 2020-03-30 Martin Maechler * R/matrixz.R[.dimZQ, .ncolZQ]: use `%/%` to get integer dim() and ncol() * R/matrix-prods.R: must crossprod() / tcrossprod() generics with the `...` extra argument, compatibly with "R base" `implicitGeneric("crossprod")` 2020-03-02 Martin Mächler * DESCRIPTION (Version): 0.5-14 * R/biginteger.R (floor.bigz, round.bigz, ..): implement (c.bigz, max.bigz, sum.bigz, ..): also work when args contain "bigq" * R/bigq.R (floor.bigq, round.bigq, ..): implement 2016-01-07 ** Some fix **Indexing/Subassignment: *** Seg.faults in Z <- as.bigz(1:7); Z[1] <- list(1) # --> seg.fault Q <- as.bigq(1:7, 7); Q[1] <- list(1) # --> seg.fault Z <- as.bigz(1:7); Z[1] <- NULL # --> seg.fault Q <- as.bigq(1:7, 7); Q[1] <- NULL # --> seg.fault ** Not working Arithmetic *** qq <- as.bigq(c(0:5, NA, 7:8), 12) # shows NA fine, is.na(qq), too, but numerator( qq ) gives 0 instead of NA !! ** Miscellaneous *** unique() silently gives nonsense ! *** duplicated() ditto ** Matrix stuff *** as.matrix(as.bigq(1:4)), as.matrix(as.bigz(1:4)) now (~ 2012) work **** NB: to go "back", now have asNumeric() {instead of expecting as.matrix() to give numeric} 2014-07-28 * Fix %/% operator * Remove doxygen auto-generated files. 2013-12-03 * Fix c++ code to work with new gcc. 2013-10-29 * Fix c++ code to work with new gcc. 2013-09-12 Antoine Lucas. * Fix Warn / Note. 2013-09-10 Antoine Lucas. * fix man page. 2013-06-09 Antoine Lucas. * fix factorize('33162879029270137') 2013-06-07 Martin Maechler big changes related to "a/b" and "b^(-1)"; also: now give [NA + warning()} rather than an error when there is no inverse, a division to 0, or a modulus mismatch 2013-02-14 Martin Maechler * R/biginteger.R (duplicated.bigz, unique.bigz, all.equal.bigz): new (cheap imp.). * R/bigq.R (duplicated.bigq, unique.bigq, all.equal.bigq, mean.bigq): new (cheap imp.) * R/biginteger.R (rep.bigz): and * R/bigq.R (rep.bigq): allow ('length.out' and 'each') arguments 2013-02-13 Martin Maechler * src/bigrationalR.cc (bigrational_num): numerator() * R/matrixz.R (.dimsetZQ): dim(.) <- NULL now works 2013-02-04 Martin Maechler * DESCRIPTION (Version): 0.5-4 (0.5-3 failed in R 2.14.2) 2013-02-03 Antoine Lucas + Martin Maechler * man/sizeinbase.Rd updated * new function asNumeric() 2012-05-07 Martin Maechler * src/bigrational.cc (^): Q^n and Z^n now also work for negative 'n' and with NA's. * R/bigq.R (as.bigz.bigq): as.bigz(as.bigq(NA)) now works 2012-05-02 Martin Maechler * src/bigrationalR.cc (bigrational_pow, mpqz_pow): * src/bigrational.cc (operator^): add ^ n functionality. * TODO: (one less :-) 2012-05-01 Martin Maechler * DESCRIPTION (Version): 0.5-2 * src/bigintegerR.cc (bigI_choose, bigI_factorial): now vectorized. * man/factorialZ.Rd: updated, including examples 2012-01-20 Antoine Lucas * tests/gmp-test.R: update 2012-01-12 Martin Maechler * NAMESPACE, * src/init.cc: new file, providing proper registration * R/zzz.R: new gmpVersion() [to get GMP C library version]. 2012-01-09 Martin Maechler * R/biginteger.R (as.bigz): mod=NULL now is equivalent to NA; important for 'modulus(x) <- NULL' to work. 2012-01-07 Martin Maechler * man/modulus.Rd: example, (and FIXME) * TODO: as.bigz(integer()) and as.bigq(integer()) now both work and give a 0-length object; analogously, the basic functions now work with the 0-length big[qz] vectors and return 0-length. * src/bigintegerR.cc (create_SEXP): ensure the modulus also has class "bigz". 2012-01-06 Martin Maechler * R/matrix-prods.R: new file, containing all %*%, and new crossprod, tcrossprod methods. %*% now works, too. 2011-12-31 Martin Maechler * src/bigintegerR.cc (biginteger_as_integer): new (biginteger_log, biginteger_log2): new --> allowing proper log(). * R/biginteger.R (as.integer.bigz): new -- gave nonsense! * R/biginteger.R (log.bigz): now work correctly also for large numbers. 2011-12-29 Martin Maechler * src/bigintegerR.cc (bigI_frexp): new, with R interface * man/frexpZ.Rd: * R/bigq.R (Math.bigq): define a "fall-back" group method * R/biginteger.R (Math.bigz): ditto * R/biginteger.R (print.bigz, print.bigq): Mention class and length, and then do *not* quote, by default. 2011-12-28 Martin Maechler * DESCRIPTION (Version): 0.5-0 * src/bigintegerR.cc (biginteger_max): na_remove now correct from R code * src/bigrationalR.cc (bigrational_max): ditto * R/biginteger.R (factorialZ, chooseZ): new 2010-04-10 Antoine Lucas * ./Changes : see for 0.4-12 and everything older. gmp/NAMESPACE0000644000176200001440000001641214444267421012270 0ustar liggesusersuseDynLib(gmp, .registration=TRUE) importMethodsFrom("methods", coerce) importFrom("methods", setOldClass, setGeneric, setMethod) ## instead of exportPattern() : ## MM: but *really* should export considerably less !! (i.e. use S3method(.) more ! export( "%*%", # unfortunately need to make it into an S3 generic "crossprod", "tcrossprod",#<- *STILL* needed .. unless S4 and we exportMethods() for them ## "abs.bigq", "abs.bigz", "add.bigq", "add.bigz", "apply", "apply.bigq", "apply.bigz", "apply.default", "as.bigq", "as.bigz", "as.bigz.bigq", ## "as.character.bigq", "as.character.bigz", ## "as.double.bigq", "as.double.bigz", ## "as.matrix.bigq", "as.matrix.bigz", ## this should be a deprecated use: "as.vector.bigq", "as.vector.bigz", c_bigq, c_bigz, ## "c.bigq", "c.bigz", "cbind.bigq", "cbind.bigz", "rbind.bigq", "rbind.bigz", ## "cumsum.bigq", "cumsum.bigz", "denominator", "denominator<-", ## "dim<-.bigq", "dim.bigq", "dim<-.bigz", "dim.bigz", "div.bigq", "div.bigz", "divq.bigz", dbinomQ, # dbinom() with exact rationals ## TODO: pbinomQ, BernoulliQ, # Rmpfr has 'Bernoulli'; want different name "Eulerian", "Eulerian.all", "Stirling1", "Stirling1.all", "Stirling2", "Stirling2.all", "factorize", "factorialZ", "chooseZ", "frexpZ", "fibnum", "fibnum2", "formatN", "gcd", "gcd.bigz", "gcd.default", "gcdex", "gmpVersion", "inv.bigz", ## "inv", ## "is.na.bigq", "is.na.bigz", "is.bigz", "is.bigq", "is.matrixZQ", "isprime", "is.whole", "lcm.bigz", "lcm.default", ## "length<-.bigq", "length.bigq", "length<-.bigz", "length.bigz", "log10.bigz", "log2.bigz", "log.bigz", "lucnum", "lucnum2", "matrix", "matrix.bigq", "matrix.bigz", "matrix.default", "max.bigq", "max.bigz", "min.bigq", "min.bigz", "mod.bigz", "modulus", "modulus<-", # "modulus<-.bigz", "modulus.bigz", "mul.bigq", "mul.bigz", NA_bigz_, NA_bigq_, "ncol.bigq", "ncol.bigz", "nrow.bigq", "nrow.bigz", "nextprime", "numerator", "numerator<-", outer, # our own (= base's, but with our env.!) ## "pow", "pow.bigz", "powm", "pow.bigq", ## "print.bigq", "print.bigz", ## "prod", "prod.default", "prod.bigq", "prod.bigz", "rep.bigq", "rep.bigz", round0, roundQ, # (x, digits, round0) ## "sign.bigq", "sign.bigz", "sizeinbase", "solve.bigq", "solve.bigz", .sub.bigq, "sub.bigq", "sub.bigz", "sum.bigq", "sum.bigz", ## "t.bigq", "t.bigz", "urand.bigz") ## For Rmpfr (and possibly similar packages) export(.as.bigz, ..as.bigz, .as.char.bigz) ## C routines for other packages to .Call(..) .. hmm, convenient ## but then also needs mention on a help page: ## FIXME (2013-09-11): drop these after a while {when dependent packages ## ----- all use the .as.* and ..as.* substitutes: export(biginteger_as, biginteger_as_character) S3method(gcd,default) #S3method(lcm,default) S3method(is.whole,default) ### S3methods : NB use the *same* method for the 'Arith' and 'Compare' group # --------- -- only then, group method dispatch will work for op ## Arith -- S3method("+",bigz, add.big) S3method("-",bigz, sub.big) S3method("*",bigz, mul.big) S3method("/",bigz, div.big) S3method("^",bigz, pow.big) ## bigz only: S3method("%%", bigz) S3method("%/%",bigz) ## Compare S3method("<", bigz, lt.big) S3method("<=",bigz, lte.big) S3method("==",bigz, eq.big) S3method(">=",bigz, gte.big) S3method(">", bigz, gt.big) S3method("!=",bigz, neq.big) S3method("!",bigz) S3method("|",bigz) S3method("&",bigz) S3method("xor",bigz) ## S3method("[<-",bigz) S3method("[",bigz) S3method("[[<-",bigz) S3method("[[",bigz) ##S3method(add,bigz) S3method(sum,bigz) S3method(sum,bigq) #S3method(pow,bigz) S3method(gcd,bigz) #S3method(lcm,bigz) #S3method(inv,bigz) S3method(log,bigz) S3method(log10,bigz) S3method(log2,bigz) S3method(c,bigz) S3method(cbind,bigz) S3method(rbind,bigz) S3method(dim,bigz) S3method("dim<-", bigz) S3method(is.finite,bigz) S3method(is.infinite,bigz) S3method(is.na,bigz) S3method(is.whole,bigz) S3method(length,bigz) S3method("length<-", bigz) S3method(max,bigz) S3method(min,bigz) S3method(rep,bigz) S3method(print,bigz) ##S3method(urand,bigz) S3method(duplicated,bigz) S3method(unique,bigz) S3method(all.equal,bigz) S3method(modulus, bigz) S3method("modulus<-", bigz) ## Arith : S3method("+",bigq, add.big) S3method("-",bigq, sub.big) S3method("*",bigq, mul.big) S3method("/",bigq, div.big) S3method("^",bigq, pow.big) ## Compare : S3method("<", bigq, lt.big) S3method("<=",bigq, lte.big) S3method("==",bigq, eq.big) S3method(">=",bigq, gte.big) S3method(">", bigq, gt.big) S3method("!=",bigq, neq.big) ## Logical S3method("!",bigq) S3method("|",bigq) S3method("&",bigq) S3method("xor",bigq) ## S3method("[<-", bigq) S3method("[", bigq) S3method("[[<-",bigq) S3method("[[", bigq) ##S3method(add,bigq) S3method(c,bigq) S3method(cbind,bigq) S3method(rbind,bigq) S3method(dim,bigq) S3method("dim<-", bigq) S3method(is.finite,bigq) S3method(is.infinite,bigq) S3method(is.na,bigq) S3method(is.whole,bigq) S3method(length,bigq) S3method("length<-", bigq) S3method(max,bigq) S3method(min,bigq) S3method(rep,bigq) S3method(print,bigq) S3method(duplicated,bigq) S3method(unique,bigq) S3method(mean,bigq) S3method(all.equal,bigq) S3method(matrix, default) S3method(matrix, bigq) S3method(matrix, bigz) ## unfortunately, using S4 methods and setOldClass("bigz") is not enough ## and so we need S3 methods and mask base (see also R/matrix-prods.R): S3method("%*%",default) S3method("%*%",bigq) S3method("%*%",bigz) S3method("crossprod",default) S3method("crossprod",bigq) S3method("crossprod",bigz) S3method("tcrossprod",default) S3method("tcrossprod",bigq) S3method("tcrossprod",bigz) S3method(apply,default) S3method(apply,bigq) S3method(apply,bigz) #S3method(as,bigq) #S3method(as,bigz) S3method(as.character,bigq) S3method(as.character,bigz) S3method(as.double,bigq) S3method(as.double,bigz) S3method(as.integer,bigq) S3method(as.integer,bigz) S3method(as.matrix,bigq) S3method(as.matrix,bigz) S3method(as.vector,bigz) S3method(as.vector,bigq) S3method(formatN,default) S3method(formatN,integer) S3method(formatN,double) S3method(formatN,bigq) S3method(formatN,bigz) ##----'Math'--------most give "not yet implemented": S3method(Math,bigq) S3method(Math,bigz) S3method(abs,bigz) S3method(abs,bigq) S3method(sign,bigq) S3method(sign,bigz) S3method(floor,bigq) S3method(floor,bigz) S3method(round,bigq) S3method(round,bigz) S3method(trunc,bigq) S3method(trunc,bigz) S3method(gamma,bigz) S3method(cumsum,bigz) S3method(cumsum,bigq) S3method(prod,bigz) S3method(prod,bigq) ##-- end{'Math'}------------------- S3method(solve,bigq) 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) exportMethods(which.max, which.min) exportClasses("bigz", "bigq")# setOldClass()'ed, needed in Rmpfr ## unfortunately, using S4 methods and setOldClass("bigz") is not enough, ## see R/matrix-prods.R : ## exportMethods("%*%", "crossprod", "tcrossprod")#-> also exports S4 generics gmp/TODO0000644000176200001440000001350214444267422011537 0ustar liggesusers* Remove full path in `configure.ac` script, with example of Rmpfr configure. -*-org-*- * Bug Fixes ** DONE Logical ops should work: 0=FALSE NA=NA, =TRUE *** DONE !as.bigz(0:3) crashes R badly (!!), but should return !(0:3) (logical vector). *** DONE as.bigz(0:3) | as.bigz(0) etc should return logical as with regular numbers in R ** TODO `format()` currently works via as.character(.), particularly unsatisfying for bigz. ** DONE Not working column assignment : A[,j] <- vec does nothing, not warn, nothing -- but A[i,] <- val works ?? ** DONE m <- matrix(1:6, 2); Z <- as.bigz(m); str(Z) fails because e.g. Z[5] fails, contrary m[5] ** TODO asNumeric(x) : the generic must get a "..." argument, so can use "rounding mode" in Rmpfr ** DONE URGENT / BAD : Segfaults, Wrong Results, etc ** DONE completely *wrong* pmin() and pmax(, ): uses Numerator in comparison ??? *** TODO: Find the *underlying* reason where pmin() goes wrong w/o warning! ** TODO Missing bigq %% and %/% [was 'Not working Arithmetic'] *** TODO bigq %% and %/% are not even defined (but are for 'numeric')! *** DONE as.bigz(1:4) + as.bigq(7) failed, so do '*', '/', ... Fixed (for 0.6-0), via new add.big() etc _S3_ methods *** DONE more checking: q <- 2.3; Fn <- gmp:::`^.bigq`; Fn(q,q) silently gave wrong result; now a good error message *** DONE %*% silently gave wrong result; now works, as does crossprod(), tcrossprod() *** DONE bigz %% and %/% should be R compatible, notably fulfilling (a %/% b)*b + (a %% b) == a for all a and b Examples as.bigz(-2:2) %/% as.bigz(3) **** DONE %% and %/% fail with "division by zero": now warning = ok. whereas the numeric/integer version of these work fine, returning NA; see matOuter() and eqA[] in tests/arith-ex.R * Miscellaneous ** TODO provide as.bigq.fractions(): to accept MASS::fractions() results ** TODO [MM:] is.whole() conflicts with sfsmisc::is.whole(): maybe get that as default method ? *** Note that we use all(is.whole(.)) importantly. --> Make fast all_whole() via C ? ** gmp <--> Rmpfr: *** Z <- as.bigz(1:7); Z[1] <- mpfr(1, 20) now gives an error {did segfault!}; but later, *with* Rmpfr we should make Z into an 'mpfr'. This is completely analogous to I <- 1:7 ;typeof(I) # "integer" I[1] <- 1.0 ;typeof(I) # "double" (aka "numeric") I[1] <- 1i ;typeof(I) # "complex" **** Want *in addition*: "coercion" from mpfr() to bigz / bigq: Solution: Work via GMP's mpf_t: A. mpfr --> mpf --> mpq (exact for Q) -- see below B. mpfr --> mpz (or round() for Z) -- via mpfr_get_z(mpz_t ROP, mpfr_t OP, mpfr_rnd_t RND) for A) MPFR: int mpfr_get_f (mpf_t ROP, mpfr_t OP, mpfr_rnd_t RND) GMP: void mpq_set_f (mpq_t ROP, mpf_t OP): Set ROP to the value of OP... conversion is exact. BTW: The other direction is via int mpfr_set_z (mpfr_t ROP, mpz_t OP, mpfr_rnd_t RND) int mpfr_set_q (mpfr_t ROP, mpq_t OP, mpfr_rnd_t RND) int mpfr_set_f (mpfr_t ROP, mpf_t OP, mpfr_rnd_t RND) NB: also 2) provide corresponding as(, "bigz") and as(, "bigq") 3) *and* (careful; these are in R pkg gmp; all the above is in Rmpfr): enhance as.bigz() and as.bigq() to work for this case ! ** Vectorization; other "desiderata" *** fibnum(), etc are *not* vectorized -- learn from chooseZ() ! *** allow +/- Inf "bigq" ?? -- +Inf :=: 1/0 -Inf :=: (-1)/0 This would allow the bigq (and bigz) arithmetic to be closer to the other R arithmetic rules. Currently we get "division by 0" instead... not really desirably in quite some cases. **** 2013-03: Currently as.bigz(Inf) now gives 2^8000 *very* arbitrarily; this allows <= Inf to give something better than NA, *but* does not work the same with ; there, the +- Inf := ( +-1 / 0 ) would seem more sensible. However: Clearly found that 'mpq' (GMP library) code does *not* work with "1/0" rational. One possibility: Using +- /1 for "bigq", as +- for "bigz" ** Matrix things *** DONE want *different* M[1,] and M[1] for big[zq] matrices *** DONE 3*M and M*3 are not the same: the first forgets the "nrow" *** DONE x <- as.bigz(2:5); x[1] <- -1; x # -- a matrix !! >> no longer *** DONE qq <- as.bigz(2:5)/7; qq[1] <- -1; qq # -- a matrix !! *** abs(.) or sign() {and probably many others!} return vector instead of matrix, i.e.., lose the "nrow" attribute. *** cbind(, ) returns raw * More general, previous 'TODO': *** The print() method is improved; but matrices are not "noted" yet. Still needs discussion; should be shorter for length 1 ? We could have an option() .. to suppress the initial line. Fine for bigq, but not for bigz *** frexpZ(z) is sufficient; want faster simpler sizeinbase() i.e. sizeinbase(x, base) returning the number "digits" in base 'base'. Notably sizeinbase(z, 2) would directly give frexpZ(z)$exp (minus 1 ?), and could be used in Rmpfr's getPrec() for bigz -> mpfr conversion. *** provide more functions for bigintegers & bigrationals, such as sort, order, xtfrm, rank {-> quantile(), median() !}; mean() !! [-> bigq !] *** Bernoulli() {-> Rmpfr / copula } should return a "bigq" *** more matrix and linear algebra computation functions (SVD, eigen values, determinant). *** provide basic algorithms and number theoretic symbols (CRA, Jacobi symbol) *** provide binary-to-biginteger interface with bitwise operations (i.e., bit access to big integers) *** Create pochZ() for the Pochhammer symbol to complement chooseZ() the same as pochMpfr() in "Rmpfr" complements chooseMpfr() * Systematic Testing *** Arithmetic, Comparison, etc: ensure pairwise compatibility , , *** tests/gmp-test.R: contains Antoine's previous test suite; should add more tests about *correct* result. gmp/configure.ac0000644000176200001440000000331414444267422013335 0ustar liggesusersdnl Process this file with autoconf to produce a configure script. AC_INIT(src/biginteger.cc) AC_ARG_WITH([gmp-include], AS_HELP_STRING([--with-gmp-include=INCLUDE_PATH], [the location of GMP header files]), [gmp_include_path=$withval]) if test -n "$gmp_include_path" ; then GMP_CPPFLAGS="-I${gmp_include_path}" elif test -n "${gmp_INCLUDE}" ; then GMP_CPPFLAGS="-I${gmp_INCLUDE}" fi dnl Ditto for a library path environment variable >> gmp_LDFLAGS << AC_ARG_WITH([gmp-lib], AS_HELP_STRING([--with-gmp-lib=LIB_PATH], [the location of GMP libraries]), [gmp_lib_path=$withval]) if test -n "$gmp_lib_path" ; then GMP_LDFLAGS="-L$gmp_lib_path ${LDFLAGS}" elif test -n "${gmp_LDFLAGS}" ; then GMP_LDFLAGS="-L${gmp_LDFLAGS} ${LDFLAGS}" fi CC=`"${R_HOME}/bin/R" CMD config CC` CFLAGS=`"${R_HOME}/bin/R" CMD config CFLAGS` CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS` CXX=`"${R_HOME}/bin/R" CMD config CXX` CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXXFLAGS` LDFLAGS=`"${R_HOME}/bin/R" CMD config LDFLAGS` MAKE=`"${R_HOME}/bin/R" CMD config MAKE` AC_PROG_CC AC_PROG_CPP AC_PROG_CXX dnl use the include and lib CPPFLAGS="${CPPFLAGS} ${MPFR_CPPFLAGS}" LDFLAGS="${LDFLAGS} ${MPFR_LDFLAGS}" PKG_CPPFLAGS=$CPPFLAGS PKG_CFLAGS=$CFLAGS PKG_LDFLAGS=$LDFLAGS dnl Check for lib gmp AC_CHECK_HEADER([gmp.h], , [AC_MSG_ERROR([Header file gmp.h not found; maybe use --with-gmp-include=INCLUDE_PATH])]) AC_CHECK_LIB(gmp,__gmpz_ui_sub,, [AC_MSG_ERROR([GNU MP not found, or not 4.1.4 or up, see http://gmplib.org])]) AC_SUBST(PKG_CPPFLAGS) AC_SUBST(PKG_CFLAGS) AC_SUBST(PKG_LDFLAGS) AC_CONFIG_FILES(src/Makevars) AC_OUTPUT gmp/configure0000755000176200001440000041665414662142527012775 0ustar liggesusers#! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.69. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. # # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # Use a proper internal environment variable to ensure we don't fall # into an infinite loop, continuously re-executing ourselves. if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then _as_can_reexec=no; export _as_can_reexec; # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 as_fn_exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi " as_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 test \$(( 1 + 1 )) = 2 || exit 1" if (eval "$as_required") 2>/dev/null; then : as_have_required=yes else as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir/$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi done;; esac as_found=false done $as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes fi; } IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : export CONFIG_SHELL # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi if test x$as_have_required = xno; then : $as_echo "$0: This script requires a shell more modern than all" $as_echo "$0: the shells that I found on your system." if test x${ZSH_VERSION+set} = xset ; then $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: be upgraded to zsh 4.3.4 or later." else $as_echo "$0: Please tell bug-autoconf@gnu.org about your system, $0: including any error possibly output before this $0: message. Then install a modern shell, or manually run $0: the script under such a shell if you do have one." fi exit 1 fi fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) sed -n ' p /[$]LINENO/= ' <$as_myself | sed ' s/[$]LINENO.*/&-/ t lineno b :lineno N :loop s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ t loop s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # If we had to re-execute with $CONFIG_SHELL, we're ensured to have # already done that, so ensure we don't try to do so again and fall # in an infinite loop. This has already happened in practice. _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). . "./$as_me.lineno" # Exit status is that of the last command. exit } ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` # # Initializations. # ac_default_prefix=/usr/local ac_clean_files= ac_config_libobj_dir=. LIBOBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME= PACKAGE_TARNAME= PACKAGE_VERSION= PACKAGE_STRING= PACKAGE_BUGREPORT= PACKAGE_URL= ac_unique_file="src/biginteger.cc" # Factoring default headers for most tests. ac_includes_default="\ #include #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef STDC_HEADERS # include # include #else # ifdef HAVE_STDLIB_H # include # endif #endif #ifdef HAVE_STRING_H # if !defined STDC_HEADERS && defined HAVE_MEMORY_H # include # endif # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif" ac_subst_vars='LTLIBOBJS LIBOBJS PKG_LDFLAGS PKG_CFLAGS PKG_CPPFLAGS EGREP GREP ac_ct_CXX CXXFLAGS CXX CPP OBJEXT EXEEXT ac_ct_CC CPPFLAGS LDFLAGS CFLAGS CC target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir runstatedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking with_gmp_include with_gmp_lib ' ac_precious_vars='build_alias host_alias target_alias CC CFLAGS LDFLAGS LIBS CPPFLAGS CPP CXX CXXFLAGS CCC' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= verbose= x_includes=NONE x_libraries=NONE # Installation directory options. # These are left unexpanded so users can "make install exec_prefix=/foo" # and all the variables that are supposed to be based on exec_prefix # by default will actually change. # Use braces instead of parens because sh, perl, etc. also accept them. # (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE}' infodir='${datarootdir}/info' htmldir='${docdir}' dvidir='${docdir}' pdfdir='${docdir}' psdir='${docdir}' libdir='${exec_prefix}/lib' localedir='${datarootdir}/locale' mandir='${datarootdir}/man' ac_prev= ac_dashdash= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval $ac_prev=\$ac_option ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file=$ac_optarg ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=*) datadir=$ac_optarg ;; -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ | --dataroo | --dataro | --datar) ac_prev=datarootdir ;; -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) datarootdir=$ac_optarg ;; -disable-* | --disable-*) ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; -docdir | --docdir | --docdi | --doc | --do) ac_prev=docdir ;; -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) docdir=$ac_optarg ;; -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) ac_prev=dvidir ;; -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) dvidir=$ac_optarg ;; -enable-* | --enable-*) ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he | -h) ac_init_help=long ;; -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) ac_init_help=recursive ;; -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) ac_init_help=short ;; -host | --host | --hos | --ho) ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) host_alias=$ac_optarg ;; -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) ac_prev=htmldir ;; -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ | --ht=*) htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir=$ac_optarg ;; -localedir | --localedir | --localedi | --localed | --locale) ac_prev=localedir ;; -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name=$ac_optarg ;; -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) ac_prev=pdfdir ;; -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) pdfdir=$ac_optarg ;; -psdir | --psdir | --psdi | --psd | --ps) ac_prev=psdir ;; -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -runstatedir | --runstatedir | --runstatedi | --runstated \ | --runstate | --runstat | --runsta | --runst | --runs \ | --run | --ru | --r) ac_prev=runstatedir ;; -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ | --run=* | --ru=* | --r=*) runstatedir=$ac_optarg ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; -*) as_fn_error $? "unrecognized option: \`$ac_option' Try \`$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; esac done if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: `$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias host=$host_alias target=$target_alias # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi fi ac_tool_prefix= test -n "$host_alias" && ac_tool_prefix=$host_alias- test "$silent" = yes && exec 6>/dev/null ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. fi # Remove unnecessary trailing slashes from srcdir. # Double slashes in file names in object file debugging info # mess up M-x gdb in Emacs. case $srcdir in */) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; esac for ac_var in $ac_precious_vars; do eval ac_env_${ac_var}_set=\${${ac_var}+set} eval ac_env_${ac_var}_value=\$${ac_var} eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} eval ac_cv_env_${ac_var}_value=\$${ac_var} done # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF \`configure' configures this package to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print \`checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for \`--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or \`..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, \`make install' will install all the files in \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify an installation prefix other than \`$ac_default_prefix' using \`--prefix', for instance \`--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] _ACEOF cat <<\_ACEOF _ACEOF fi if test -n "$ac_init_help"; then cat <<\_ACEOF Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-gmp-include=INCLUDE_PATH the location of GMP header files --with-gmp-lib=LIB_PATH the location of GMP libraries Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory CPP C preprocessor CXX C++ compiler command CXXFLAGS C++ compiler flags Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to the package provider. _ACEOF ac_status=$? fi if test "$ac_init_help" = "recursive"; then # If there are subdirs, report their specific --help. for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue test -d "$ac_dir" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || continue ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } # Check for guested configure. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive elif test -f "$ac_srcdir/configure"; then echo && $SHELL "$ac_srcdir/configure" --help=recursive else $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF configure generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF exit fi ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## # ac_fn_c_try_compile LINENO # -------------------------- # Try to compile conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest.$ac_objext; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_compile # ac_fn_c_try_cpp LINENO # ---------------------- # Try to preprocess conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_cpp () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_cpp conftest.$ac_ext" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } > conftest.i && { test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || test ! -s conftest.err }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_cpp # ac_fn_cxx_try_compile LINENO # ---------------------------- # Try to compile conftest.$ac_ext, and return whether this succeeded. ac_fn_cxx_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_cxx_werror_flag" || test ! -s conftest.err } && test -s conftest.$ac_objext; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_cxx_try_compile # ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists, giving a warning if it cannot be compiled using # the include files in INCLUDES and setting the cache variable VAR # accordingly. ac_fn_c_check_header_mongrel () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if eval \${$3+:} false; then : { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } else # Is the header compilable? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 $as_echo_n "checking $2 usability... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_header_compiler=yes else ac_header_compiler=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 $as_echo "$ac_header_compiler" >&6; } # Is the header present? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 $as_echo_n "checking $2 presence... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include <$2> _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : ac_header_preproc=yes else ac_header_preproc=no fi rm -f conftest.err conftest.i conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 $as_echo "$ac_header_preproc" >&6; } # So? What about this header? case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( yes:no: ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 $as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ;; no:yes:* ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 $as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 $as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 $as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 $as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=\$ac_header_compiler" fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_mongrel # ac_fn_c_try_run LINENO # ---------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. Assumes # that executables *can* be run. ac_fn_c_try_run () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then : ac_retval=0 else $as_echo "$as_me: program exited with status $ac_status" >&5 $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=$ac_status fi rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_run # ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists and can be compiled using the include files in # INCLUDES, setting the cache variable VAR accordingly. ac_fn_c_check_header_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_compile # ac_fn_c_try_link LINENO # ----------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_link () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext conftest$ac_exeext if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || test -x conftest$ac_exeext }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would # interfere with the next link command; also delete a directory that is # left behind by Apple's compiler. We do this before executing the actions. rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_link cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by $as_me, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ _ACEOF exec 5>>config.log { cat <<_ASUNAME ## --------- ## ## Platform. ## ## --------- ## hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` /bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` /bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` /usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` /bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` /bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` _ASUNAME as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. $as_echo "PATH: $as_dir" done IFS=$as_save_IFS } >&5 cat >&5 <<_ACEOF ## ----------- ## ## Core tests. ## ## ----------- ## _ACEOF # Keep a trace of the command line. # Strip out --no-create and --no-recursion so they do not pile up. # Strip out --silent because we don't want to record it for future runs. # Also quote any args containing shell meta-characters. # Make two passes to allow for proper duplicate-argument suppression. ac_configure_args= ac_configure_args0= ac_configure_args1= ac_must_keep_next=false for ac_pass in 1 2 do for ac_arg do case $ac_arg in -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then ac_must_keep_next=false # Got value, back to normal. else case $ac_arg in *=* | --config-cache | -C | -disable-* | --disable-* \ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ | -with-* | --with-* | -without-* | --without-* | --x) case "$ac_configure_args0 " in "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; esac ;; -* ) ac_must_keep_next=true ;; esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset ac_configure_args1;} # When interrupted or exit'd, cleanup temporary files, and complete # config.log. We remove comments because anyway the quotes in there # would cause problems or look ugly. # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? # Save into config.log some information that might help in debugging. { echo $as_echo "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ "s/'\''/'\''\\\\'\'''\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) echo $as_echo "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then $as_echo "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then $as_echo "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && $as_echo "$as_me: caught signal $ac_signal" $as_echo "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && exit $exit_status ' 0 for ac_signal in 1 2 13 15; do trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal done ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h $as_echo "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. cat >>confdefs.h <<_ACEOF #define PACKAGE_NAME "$PACKAGE_NAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_TARNAME "$PACKAGE_TARNAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_VERSION "$PACKAGE_VERSION" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_STRING "$PACKAGE_STRING" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_URL "$PACKAGE_URL" _ACEOF # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. ac_site_file1=NONE ac_site_file2=NONE if test -n "$CONFIG_SITE"; then # We do not want a PATH search for config.site. case $CONFIG_SITE in #(( -*) ac_site_file1=./$CONFIG_SITE;; */*) ac_site_file1=$CONFIG_SITE;; *) ac_site_file1=./$CONFIG_SITE;; esac elif test "x$prefix" != xNONE; then ac_site_file1=$prefix/share/config.site ac_site_file2=$prefix/etc/config.site else ac_site_file1=$ac_default_prefix/share/config.site ac_site_file2=$ac_default_prefix/etc/config.site fi for ac_site_file in "$ac_site_file1" "$ac_site_file2" do test "x$ac_site_file" = xNONE && continue if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 $as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 $as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 $as_echo "$as_me: creating cache $cache_file" >&6;} >$cache_file fi # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false for ac_var in $ac_precious_vars; do eval ac_old_set=\$ac_cv_env_${ac_var}_set eval ac_new_set=\$ac_env_${ac_var}_set eval ac_old_val=\$ac_cv_env_${ac_var}_value eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 $as_echo "$as_me: former value: \`$ac_old_val'" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu # Check whether --with-gmp-include was given. if test "${with_gmp_include+set}" = set; then : withval=$with_gmp_include; gmp_include_path=$withval fi if test -n "$gmp_include_path" ; then GMP_CPPFLAGS="-I${gmp_include_path}" elif test -n "${gmp_INCLUDE}" ; then GMP_CPPFLAGS="-I${gmp_INCLUDE}" fi # Check whether --with-gmp-lib was given. if test "${with_gmp_lib+set}" = set; then : withval=$with_gmp_lib; gmp_lib_path=$withval fi if test -n "$gmp_lib_path" ; then GMP_LDFLAGS="-L$gmp_lib_path ${LDFLAGS}" elif test -n "${gmp_LDFLAGS}" ; then GMP_LDFLAGS="-L${gmp_LDFLAGS} ${LDFLAGS}" fi CC=`"${R_HOME}/bin/R" CMD config CC` CFLAGS=`"${R_HOME}/bin/R" CMD config CFLAGS` CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS` CXX=`"${R_HOME}/bin/R" CMD config CXX` CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXXFLAGS` LDFLAGS=`"${R_HOME}/bin/R" CMD config LDFLAGS` MAKE=`"${R_HOME}/bin/R" CMD config MAKE` ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. set dummy ${ac_tool_prefix}gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_CC"; then ac_ct_CC=$CC # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi else CC="$ac_cv_prog_CC" fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. set dummy ${ac_tool_prefix}cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi fi if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else ac_prog_rejected=no as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue fi ac_cv_prog_CC="cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift if test $# != 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" fi fi fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then for ac_prog in cl.exe do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$CC" && break done fi if test -z "$CC"; then ac_ct_CC=$CC for ac_prog in cl.exe do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$ac_ct_CC" && break done if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi fi fi test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See \`config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 $as_echo_n "checking whether the C compiler works... " >&6; } ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" ac_rmfiles= for ac_file in $ac_files do case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; * ) ac_rmfiles="$ac_rmfiles $ac_file";; esac done rm -f $ac_rmfiles if { { ac_try="$ac_link_default" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. # So ignore a value of `no', otherwise this would lead to `EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, # so that the user can short-circuit this test for compilers unknown to # Autoconf. for ac_file in $ac_files '' do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; [ab].out ) # We found the default executable, but exeext='' is most # certainly right. break;; *.* ) if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi # We set ac_cv_exeext here because the later test for it is not # safe: cross compilers may not add the suffix if given an `-o' # argument, so we may need to know it at that point already. # Even if this section looks crufty: it has the advantage of # actually working. break;; * ) break;; esac done test "$ac_cv_exeext" = no && ac_cv_exeext= else ac_file='' fi if test -z "$ac_file"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables See \`config.log' for more details" "$LINENO" 5; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 $as_echo_n "checking for C compiler default output file name... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 $as_echo "$ac_file" >&6; } ac_exeext=$ac_cv_exeext rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 $as_echo_n "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # If both `conftest.exe' and `conftest' are `present' (well, observable) # catch `conftest.exe'. For instance with Cygwin, `ls conftest' will # work properly (i.e., refer to `conftest.exe'), while it won't with # `rm'. for ac_file in conftest.exe conftest conftest.*; do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` break;; * ) break;; esac done else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest conftest$ac_cv_exeext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 $as_echo "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext ac_exeext=$EXEEXT cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF ac_clean_files="$ac_clean_files conftest.out" # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 $as_echo_n "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then cross_compiling=no else if test "$cross_compiling" = maybe; then cross_compiling=yes else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run C compiled programs. If you meant to cross compile, use \`--host'. See \`config.log' for more details" "$LINENO" 5; } fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 $as_echo "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 $as_echo_n "checking for suffix of object files... " >&6; } if ${ac_cv_objext+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF rm -f conftest.o conftest.obj if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : for ac_file in conftest.o conftest.obj conftest.*; do test -f "$ac_file" || continue; case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` break;; esac done else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 $as_echo "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; } if ${ac_cv_c_compiler_gnu+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_compiler_gnu=yes else ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 $as_echo "$ac_cv_c_compiler_gnu" >&6; } if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 $as_echo_n "checking whether $CC accepts -g... " >&6; } if ${ac_cv_prog_cc_g+:} false; then : $as_echo_n "(cached) " >&6 else ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes else CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 $as_echo "$ac_cv_prog_cc_g" >&6; } if test "$ac_test_CFLAGS" = set; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" else CFLAGS="-g" fi else if test "$GCC" = yes; then CFLAGS="-O2" else CFLAGS= fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 $as_echo_n "checking for $CC option to accept ISO C89... " >&6; } if ${ac_cv_prog_cc_c89+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include struct stat; /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); static char *e (p, i) char **p; int i; { return p[i]; } static char *f (char * (*g) (char **, int), char **p, ...) { char *s; va_list v; va_start (v,p); s = g (p, va_arg (v,int)); va_end (v); return s; } /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has function prototypes and stuff, but not '\xHH' hex character constants. These don't provoke an error unfortunately, instead are silently treated as 'x'. The following induces an error, until -std is added to get proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an array size at least. It's necessary to write '\x00'==0 to get something that's true only with -std. */ int osf4_cc_array ['\x00' == 0 ? 1 : -1]; /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters inside strings and character constants. */ #define FOO(x) 'x' int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; int test (int i, double x); struct s1 {int (*f) (int a);}; struct s2 {int (*f) (double a);}; int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); int argc; char **argv; int main () { return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; ; return 0; } _ACEOF for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_c89=$ac_arg fi rm -f core conftest.err conftest.$ac_objext test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC fi # AC_CACHE_VAL case "x$ac_cv_prog_cc_c89" in x) { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 $as_echo "none needed" >&6; } ;; xno) { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 $as_echo "unsupported" >&6; } ;; *) CC="$CC $ac_cv_prog_cc_c89" { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 $as_echo "$ac_cv_prog_cc_c89" >&6; } ;; esac if test "x$ac_cv_prog_cc_c89" != xno; then : fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 $as_echo_n "checking how to run the C preprocessor... " >&6; } # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= fi if test -z "$CPP"; then if ${ac_cv_prog_CPP+:} false; then : $as_echo_n "(cached) " >&6 else # Double quotes because CPP needs to be expanded for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" do ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : break fi done ac_cv_prog_CPP=$CPP fi CPP=$ac_cv_prog_CPP else ac_cv_prog_CPP=$CPP fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 $as_echo "$CPP" >&6; } ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "C preprocessor \"$CPP\" fails sanity check See \`config.log' for more details" "$LINENO" 5; } fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_ext=cpp ac_cpp='$CXXCPP $CPPFLAGS' ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_cxx_compiler_gnu if test -z "$CXX"; then if test -n "$CCC"; then CXX=$CCC else if test -n "$ac_tool_prefix"; then for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CXX+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CXX"; then ac_cv_prog_CXX="$CXX" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CXX=$ac_cv_prog_CXX if test -n "$CXX"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5 $as_echo "$CXX" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$CXX" && break done fi if test -z "$CXX"; then ac_ct_CXX=$CXX for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CXX+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CXX"; then ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CXX="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CXX=$ac_cv_prog_ac_ct_CXX if test -n "$ac_ct_CXX"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5 $as_echo "$ac_ct_CXX" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$ac_ct_CXX" && break done if test "x$ac_ct_CXX" = x; then CXX="g++" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CXX=$ac_ct_CXX fi fi fi fi # Provide some information about the compiler. $as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C++ compiler" >&5 $as_echo_n "checking whether we are using the GNU C++ compiler... " >&6; } if ${ac_cv_cxx_compiler_gnu+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_cxx_try_compile "$LINENO"; then : ac_compiler_gnu=yes else ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_cxx_compiler_gnu=$ac_compiler_gnu fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5 $as_echo "$ac_cv_cxx_compiler_gnu" >&6; } if test $ac_compiler_gnu = yes; then GXX=yes else GXX= fi ac_test_CXXFLAGS=${CXXFLAGS+set} ac_save_CXXFLAGS=$CXXFLAGS { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5 $as_echo_n "checking whether $CXX accepts -g... " >&6; } if ${ac_cv_prog_cxx_g+:} false; then : $as_echo_n "(cached) " >&6 else ac_save_cxx_werror_flag=$ac_cxx_werror_flag ac_cxx_werror_flag=yes ac_cv_prog_cxx_g=no CXXFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_cxx_try_compile "$LINENO"; then : ac_cv_prog_cxx_g=yes else CXXFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_cxx_try_compile "$LINENO"; then : else ac_cxx_werror_flag=$ac_save_cxx_werror_flag CXXFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_cxx_try_compile "$LINENO"; then : ac_cv_prog_cxx_g=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cxx_werror_flag=$ac_save_cxx_werror_flag fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5 $as_echo "$ac_cv_prog_cxx_g" >&6; } if test "$ac_test_CXXFLAGS" = set; then CXXFLAGS=$ac_save_CXXFLAGS elif test $ac_cv_prog_cxx_g = yes; then if test "$GXX" = yes; then CXXFLAGS="-g -O2" else CXXFLAGS="-g" fi else if test "$GXX" = yes; then CXXFLAGS="-O2" else CXXFLAGS= fi fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu CPPFLAGS="${CPPFLAGS} ${MPFR_CPPFLAGS}" LDFLAGS="${LDFLAGS} ${MPFR_LDFLAGS}" PKG_CPPFLAGS=$CPPFLAGS PKG_CFLAGS=$CFLAGS PKG_LDFLAGS=$LDFLAGS { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 $as_echo_n "checking for grep that handles long lines and -e... " >&6; } if ${ac_cv_path_GREP+:} false; then : $as_echo_n "(cached) " >&6 else if test -z "$GREP"; then ac_path_GREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_GREP" || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in *GNU*) ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'GREP' >> "conftest.nl" "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_GREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_GREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_GREP"; then as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_GREP=$GREP fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 $as_echo "$ac_cv_path_GREP" >&6; } GREP="$ac_cv_path_GREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 $as_echo_n "checking for egrep... " >&6; } if ${ac_cv_path_EGREP+:} false; then : $as_echo_n "(cached) " >&6 else if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 then ac_cv_path_EGREP="$GREP -E" else if test -z "$EGREP"; then ac_path_EGREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_EGREP" || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in *GNU*) ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'EGREP' >> "conftest.nl" "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_EGREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_EGREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_EGREP"; then as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_EGREP=$EGREP fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 $as_echo "$ac_cv_path_EGREP" >&6; } EGREP="$ac_cv_path_EGREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 $as_echo_n "checking for ANSI C header files... " >&6; } if ${ac_cv_header_stdc+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_header_stdc=yes else ac_cv_header_stdc=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "memchr" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "free" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. if test "$cross_compiling" = yes; then : : else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #if ((' ' & 0x0FF) == 0x020) # define ISLOWER(c) ('a' <= (c) && (c) <= 'z') # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) #else # define ISLOWER(c) \ (('a' <= (c) && (c) <= 'i') \ || ('j' <= (c) && (c) <= 'r') \ || ('s' <= (c) && (c) <= 'z')) # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) #endif #define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) int main () { int i; for (i = 0; i < 256; i++) if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) return 2; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : else ac_cv_header_stdc=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 $as_echo "$ac_cv_header_stdc" >&6; } if test $ac_cv_header_stdc = yes; then $as_echo "#define STDC_HEADERS 1" >>confdefs.h fi # On IRIX 5.3, sys/types and inttypes.h are conflicting. for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ inttypes.h stdint.h unistd.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default " if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done ac_fn_c_check_header_mongrel "$LINENO" "gmp.h" "ac_cv_header_gmp_h" "$ac_includes_default" if test "x$ac_cv_header_gmp_h" = xyes; then : else as_fn_error $? "Header file gmp.h not found; maybe use --with-gmp-include=INCLUDE_PATH" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for __gmpz_ui_sub in -lgmp" >&5 $as_echo_n "checking for __gmpz_ui_sub in -lgmp... " >&6; } if ${ac_cv_lib_gmp___gmpz_ui_sub+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lgmp $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char __gmpz_ui_sub (); int main () { return __gmpz_ui_sub (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_gmp___gmpz_ui_sub=yes else ac_cv_lib_gmp___gmpz_ui_sub=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gmp___gmpz_ui_sub" >&5 $as_echo "$ac_cv_lib_gmp___gmpz_ui_sub" >&6; } if test "x$ac_cv_lib_gmp___gmpz_ui_sub" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBGMP 1 _ACEOF LIBS="-lgmp $LIBS" else as_fn_error $? "GNU MP not found, or not 4.1.4 or up, see http://gmplib.org" "$LINENO" 5 fi ac_config_files="$ac_config_files src/Makevars" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure # scripts and configure runs, see configure's option --config-cache. # It is not useful on other systems. If it contains results you don't # want to keep, you may remove or edit it. # # config.status only pays attention to the cache file if you give it # the --recheck option to rerun configure. # # `ac_cv_env_foo' variables (set or unset) will be overridden when # loading this file, other *unset* `ac_cv_foo' will be assigned the # following values. _ACEOF # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. ( for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space=' '; set) 2>&1` in #( *${as_nl}ac_space=\ *) # `set' does not quote correctly, so add quotes: double-quote # substitution turns \\\\ into \\, and sed turns \\ into \. sed -n \ "s/'/'\\\\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" ;; #( *) # `set' quotes correctly as required by POSIX, so do not add quotes. sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) | sed ' /^ac_cv_env_/b end t clear :clear s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ t end s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ :end' >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then if test "x$cache_file" != "x/dev/null"; then { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 $as_echo "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then cat confcache >"$cache_file" else case $cache_file in #( */* | ?:*) mv -f confcache "$cache_file"$$ && mv -f "$cache_file"$$ "$cache_file" ;; #( *) mv -f confcache "$cache_file" ;; esac fi fi else { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' # Transform confdefs.h into DEFS. # Protect against shell expansion while executing Makefile rules. # Protect against Makefile macro expansion. # # If the first sed substitution is executed (which looks for macros that # take arguments), then branch to the quote section. Otherwise, # look for a macro that doesn't take arguments. ac_script=' :mline /\\$/{ N s,\\\n,, b mline } t clear :clear s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\)/-D\1=\2/g t quote s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g t quote b any :quote s/[ `~#$^&*(){}\\|;'\''"<>?]/\\&/g s/\[/\\&/g s/\]/\\&/g s/\$/$$/g H :any ${ g s/^\n// s/\n/ /g p } ' DEFS=`sed -n "$ac_script" confdefs.h` ac_libobjs= ac_ltlibobjs= U= for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue # 1. Remove the extension, and $U if already installed. ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' ac_i=`$as_echo "$ac_i" | sed "$ac_script"` # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR # will be set to the directory where LIBOBJS objects are built. as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' done LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs : "${CONFIG_STATUS=./config.status}" ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 $as_echo "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL # Generated by $as_me. # Run this file to recreate the current configuration. # Compiler output produced by configure, useful for debugging # configure, is in config.log if it exists. debug=false ac_cs_recheck=false ac_cs_silent=false SHELL=\${CONFIG_SHELL-$SHELL} export SHELL _ASEOF cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" exec 6>&1 ## ----------------------------------- ## ## Main body of $CONFIG_STATUS script. ## ## ----------------------------------- ## _ASEOF test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" This file was extended by $as_me, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS CONFIG_LINKS = $CONFIG_LINKS CONFIG_COMMANDS = $CONFIG_COMMANDS $ $0 $@ on `(hostname || uname -n) 2>/dev/null | sed 1q` " _ACEOF case $ac_config_files in *" "*) set x $ac_config_files; shift; ac_config_files=$*;; esac cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # Files that config.status was made for. config_files="$ac_config_files" _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 ac_cs_usage="\ \`$as_me' instantiates files and other configuration actions from templates according to the current configuration. Unless the files and actions are specified as TAGs, all are instantiated by default. Usage: $0 [OPTION]... [TAG]... -h, --help print this help, then exit -V, --version print version number and configuration settings, then exit --config print configuration, then exit -q, --quiet, --silent do not print progress messages -d, --debug don't remove temporary files --recheck update $as_me by reconfiguring in the same conditions --file=FILE[:TEMPLATE] instantiate the configuration file FILE Configuration files: $config_files Report bugs to the package provider." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ config.status configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" Copyright (C) 2012 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." ac_pwd='$ac_pwd' srcdir='$srcdir' test -n "\$AWK" || AWK=awk _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # The default lists apply if the user does not specify any file. ac_need_defaults=: while test $# != 0 do case $1 in --*=?*) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` ac_shift=: ;; --*=) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg= ac_shift=: ;; *) ac_option=$1 ac_optarg=$2 ac_shift=shift ;; esac case $ac_option in # Handling of the options. -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) ac_cs_recheck=: ;; --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) $as_echo "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) $as_echo "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --file | --fil | --fi | --f ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" ac_need_defaults=false;; --he | --h | --help | --hel | -h ) $as_echo "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; # This is an error. -*) as_fn_error $? "unrecognized option: \`$1' Try \`$0 --help' for more information." ;; *) as_fn_append ac_config_targets " $1" ac_need_defaults=false ;; esac shift done ac_configure_extra_args= if $ac_cs_silent; then exec 6>/dev/null ac_configure_extra_args="$ac_configure_extra_args --silent" fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" fi _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 exec 5>>config.log { echo sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX $as_echo "$ac_log" } >&5 _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Handling of arguments. for ac_config_target in $ac_config_targets do case $ac_config_target in "src/Makevars") CONFIG_FILES="$CONFIG_FILES src/Makevars" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac done # If the user did not use the arguments to specify the items to instantiate, # then the envvar interface is used. Set only those that are not. # We use the long form for the default assignment because of an extremely # bizarre bug on SunOS 4.1.3. if $ac_need_defaults; then test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files fi # Have a temporary directory for convenience. Make it in the build tree # simply because there is no reason against having it here, and in addition, # creating and moving files from /tmp can sometimes cause problems. # Hook for its removal unless debugging. # Note that there is a small window in which the directory will not be cleaned: # after its creation but before its name has been assigned to `$tmp'. $debug || { tmp= ac_tmp= trap 'exit_status=$? : "${ac_tmp:=$tmp}" { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status ' 0 trap 'as_fn_exit 1' 1 2 13 15 } # Create a (secure) tmp directory for tmp files. { tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && test -d "$tmp" } || { tmp=./conf$$-$RANDOM (umask 077 && mkdir "$tmp") } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 ac_tmp=$tmp # Set up the scripts for CONFIG_FILES section. # No need to generate them if there are no CONFIG_FILES. # This happens for instance with `./config.status config.h'. if test -n "$CONFIG_FILES"; then ac_cr=`echo X | tr X '\015'` # On cygwin, bash can eat \r inside `` if the user requested igncr. # But we know of no other shell where ac_cr would be empty at this # point, so we can use a bashism as a fallback. if test "x$ac_cr" = x; then eval ac_cr=\$\'\\r\' fi ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then ac_cs_awk_cr='\\r' else ac_cs_awk_cr=$ac_cr fi echo 'BEGIN {' >"$ac_tmp/subs1.awk" && _ACEOF { echo "cat >conf$$subs.awk <<_ACEOF" && echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && echo "_ACEOF" } >conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` ac_delim='%!_!# ' for ac_last_try in false false false false false :; do . ./conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` if test $ac_delim_n = $ac_delim_num; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done rm -f conf$$subs.sh cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && _ACEOF sed -n ' h s/^/S["/; s/!.*/"]=/ p g s/^[^!]*!// :repl t repl s/'"$ac_delim"'$// t delim :nl h s/\(.\{148\}\)..*/\1/ t more1 s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ p n b repl :more1 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t nl :delim h s/\(.\{148\}\)..*/\1/ t more2 s/["\\]/\\&/g; s/^/"/; s/$/"/ p b :more2 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t delim ' >$CONFIG_STATUS || ac_write_fail=1 rm -f conf$$subs.awk cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACAWK cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && for (key in S) S_is_set[key] = 1 FS = "" } { line = $ 0 nfields = split(line, field, "@") substed = 0 len = length(field[1]) for (i = 2; i < nfields; i++) { key = field[i] keylen = length(key) if (S_is_set[key]) { value = S[key] line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) len += length(value) + length(field[++i]) substed = 1 } else len += 1 + keylen } print line } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" else cat fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 _ACEOF # VPATH may cause trouble with some makes, so we remove sole $(srcdir), # ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and # trailing colons and then remove the whole line if VPATH becomes empty # (actually we leave an empty line to preserve line numbers). if test "x$srcdir" = x.; then ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ h s/// s/^/:/ s/[ ]*$/:/ s/:\$(srcdir):/:/g s/:\${srcdir}:/:/g s/:@srcdir@:/:/g s/^:*// s/:*$// x s/\(=[ ]*\).*/\1/ G s/\n// s/^[^=]*=[ ]*$// }' fi cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 fi # test -n "$CONFIG_FILES" eval set X " :F $CONFIG_FILES " shift for ac_tag do case $ac_tag in :[FHLC]) ac_mode=$ac_tag; continue;; esac case $ac_mode$ac_tag in :[FHL]*:*);; :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; :[FH]-) ac_tag=-:-;; :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; esac ac_save_IFS=$IFS IFS=: set x $ac_tag IFS=$ac_save_IFS shift ac_file=$1 shift case $ac_mode in :L) ac_source=$1;; :[FH]) ac_file_inputs= for ac_f do case $ac_f in -) ac_f="$ac_tmp/stdin";; *) # Look for the file first in the build tree, then in the source tree # (if the path is not absolute). The absolute path cannot be DOS-style, # because $ac_f cannot contain `:'. test -f "$ac_f" || case $ac_f in [\\/$]*) false;; *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; esac || as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; esac case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done # Let's still pretend it is `configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ configure_input='Generated from '` $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 $as_echo "$as_me: creating $ac_file" >&6;} fi # Neutralize special characters interpreted by sed in replacement strings. case $configure_input in #( *\&* | *\|* | *\\* ) ac_sed_conf_input=`$as_echo "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac case $ac_tag in *:-:* | *:-) cat >"$ac_tmp/stdin" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac ;; esac ac_dir=`$as_dirname -- "$ac_file" || $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$ac_file" : 'X\(//\)[^/]' \| \ X"$ac_file" : 'X\(//\)$' \| \ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` as_dir="$ac_dir"; as_fn_mkdir_p ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix case $ac_mode in :F) # # CONFIG_FILE # _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # If the template does not know about datarootdir, expand it. # FIXME: This hack should be removed a few years after 2.60. ac_datarootdir_hack=; ac_datarootdir_seen= ac_sed_dataroot=' /datarootdir/ { p q } /@datadir@/p /@docdir@/p /@infodir@/p /@localedir@/p /@mandir@/p' case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in *datarootdir*) ac_datarootdir_seen=yes;; *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 $as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_datarootdir_hack=' s&@datadir@&$datadir&g s&@docdir@&$docdir&g s&@infodir@&$infodir&g s&@localedir@&$localedir&g s&@mandir@&$mandir&g s&\\\${datarootdir}&$datarootdir&g' ;; esac _ACEOF # Neutralize VPATH when `$srcdir' = `.'. # Shell code in configure.ac might set extrasub. # FIXME: do we really want to maintain this feature? cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_sed_extra="$ac_vpsub $extrasub _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 :t /@[a-zA-Z_][a-zA-Z_0-9]*@/!b s|@configure_input@|$ac_sed_conf_input|;t t s&@top_builddir@&$ac_top_builddir_sub&;t t s&@top_build_prefix@&$ac_top_build_prefix&;t t s&@srcdir@&$ac_srcdir&;t t s&@abs_srcdir@&$ac_abs_srcdir&;t t s&@top_srcdir@&$ac_top_srcdir&;t t s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t s&@builddir@&$ac_builddir&;t t s&@abs_builddir@&$ac_abs_builddir&;t t s&@abs_top_builddir@&$ac_abs_top_builddir&;t t $ac_datarootdir_hack " eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ "$ac_tmp/out"`; test -z "$ac_out"; } && { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&5 $as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&2;} rm -f "$ac_tmp/stdin" case $ac_file in -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; esac \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac done # for ac_tag as_fn_exit 0 _ACEOF ac_clean_files=$ac_clean_files_save test $ac_write_fail = 0 || as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 # configure is writing to config.log, and then calls config.status. # config.status does its own redirection, appending to config.log. # Unfortunately, on DOS this fails, as config.log is still kept open # by configure, so config.status won't be able to write to it; its # output is simply discarded. So we exec the FD to /dev/null, # effectively closing config.log, so it can be properly (re)opened and # appended to by config.status. When coming back to configure, we # need to make the FD available again. if test "$no_create" != yes; then ac_cs_success=: ac_config_status_args= test "$silent" = yes && ac_config_status_args="$ac_config_status_args --quiet" exec 5>/dev/null $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false exec 5>>config.log # Use ||, not &&, to avoid exiting from the if with $? = 1, which # would make configure fail if this is the last instruction. $ac_cs_success || as_fn_exit 1 fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi gmp/man/0000755000176200001440000000000014662142527011621 5ustar liggesusersgmp/man/biginteger.rand.Rd0000644000176200001440000000206614444267422015156 0ustar liggesusers\name{Random} \alias{urand.bigz} %- Also NEED an '\alias' for EACH other topic documented here. \title{Generate a random number} \description{ Generate a uniformly distributed random number in the range 0 to \eqn{2^{size} -1}{2^size - 1}, inclusive. % If seed is precise, a new seed is initialised. } \usage{ urand.bigz(nb=1,size=200, seed = 0) } %- maybe also 'usage' for other objects documented here. \arguments{ \item{nb}{Integer: number of random numbers to be generated (size of vector returned)} \item{size}{Integer: number will be generated in the range 0 to \eqn{2^{size} -1}{2^size - 1}} \item{seed}{Bigz: random seed initialisation} } \value{ A biginteger of class bigz. } \references{ \samp{mpz\_urandomb} from the GMP Library, see \url{https://gmplib.org} } \author{Antoine Lucas} \examples{ # Integers are differents urand.bigz() urand.bigz() urand.bigz() # Integers are the same urand.bigz(seed="234234234324323") urand.bigz(seed="234234234324323") # Vector urand.bigz(nb=50,size=30) } \keyword{arith }% at least one, from doc/KEYWORDS gmp/man/add.biginteger.Rd0000644000176200001440000000721014444267422014756 0ustar liggesusers\name{bigz_operators} \alias{add.bigz} \alias{+.bigz} \alias{sub.bigz} \alias{-.bigz} \alias{mul.bigz} \alias{*.bigz} \alias{div.bigz} \alias{/.bigz} \alias{mod.bigz} \alias{\%\%.bigz} \alias{\%/\%.bigz} \alias{divq.bigz} \alias{abs.bigz} \alias{inv.bigz} \alias{inv} \alias{pow.bigz} \alias{pow} \alias{^.bigz} \alias{log.bigz} \alias{log2.bigz} \alias{log10.bigz} \title{Basic Arithmetic Operators for Large Integers ("bigz")} \description{ Addition, substraction, multiplication, (integer) division, remainder of division, multiplicative inverse, power and logarithm functions. } \usage{ add.bigz(e1, e2) sub.bigz(e1, e2 = NULL) mul.bigz(e1, e2) div.bigz(e1, e2) divq.bigz(e1,e2) ## == e1 \%/\% e2 mod.bigz(e1, e2) ## == e1 \%\% e2 \method{abs}{bigz}(x) inv.bigz(a, b,...)## == (1 / a) (modulo b) % inv(a, ...) pow.bigz(e1, e2,...)## == e1 ^ e2 % pow(a, ...) \S3method{log}{bigz}(x, base=exp(1)) \S3method{log2}{bigz}(x) \S3method{log10}{bigz}(x) } \arguments{ \item{x}{bigz, integer or string from an integer} \item{e1, e2, a,b}{bigz, integer or string from an integer} \item{base}{base of the logarithm; base e as default} \item{...}{Additional parameters} } \details{ Operators can be used directly when objects are of class bigz: a + b, log(a), etc. For details about the internal modulus state, \emph{and} the rules applied for arithmetic operations on big integers with a modulus, see the \code{\link{bigz}} help page. \code{a / b} \eqn{=} \code{div(a,b)} returns a rational number unless the operands have a (matching) modulus where \code{a * b^-1} results. \cr \code{a \%/\% b} (or, equivalently, \code{divq(a,b)}) returns the quotient of simple \emph{integer} division (with truncation towards zero), possibly re-adding a modulus at the end (but \emph{not} using a modulus like in \code{a / b}). \code{r <- inv.bigz(a, m)}, the multiplicative inverse of \code{a} modulo \eqn{m}, corresponds to \code{1/a} or \code{a ^-1} from above \emph{when} \code{a} has modulus \code{m}. Note that \eqn{a} not always has an inverse modulo \eqn{m}, in which case \code{r} will be \code{\link{NA}} with a warning that can be turned off via \preformatted{options("gmp:warnNoInv" = FALSE)}. } \value{ Apart from \code{/} (or \code{div}), where rational numbers (\code{\link{bigq}}) may result, these functions return an object of class \code{"bigz"}, representing the result of the arithmetic operation. } \references{The GNU MP Library, see \url{https://gmplib.org}} \author{Immanuel Scholz and Antoine Lucas} \examples{ # 1+1=2 as.bigz(1) + 1 as.bigz(2)^10 as.bigz(2)^200 # if my.large.num.string is set to a number, this returns the least byte (my.large.num.string <- paste(sample(0:9, 200, replace=TRUE), collapse="")) mod.bigz(as.bigz(my.large.num.string), "0xff") # power exponents can be up to MAX_INT in size, or unlimited if a # bigz's modulus is set. pow.bigz(10,10000) ## Modulo 11, 7 and 8 are inverses : as.bigz(7, mod = 11) * 8 ## ==> 1 (mod 11) inv.bigz(7, 11)## hence, 8 a <- 1:10 (i.a <- inv.bigz(a, 11)) d <- as.bigz(7) a \%/\% d # = divq(a, d) a \%\% d # = mod.bigz (a, d) (ii <- inv.bigz(1:10, 16)) ## with 5 warnings (one for each NA) op <- options("gmp:warnNoInv" = FALSE) i2 <- inv.bigz(1:10, 16) # no warnings (i3 <- 1 / as.bigz(1:10, 16)) i4 <- as.bigz(1:10, 16) ^ -1 stopifnot(identical(ii, i2), identical(as.bigz(i2, 16), i3), identical(i3, i4)) options(op)# revert previous options' settings stopifnot(inv.bigz(7, 11) == 8, all(as.bigz(i.a, 11) * a == 1), identical(a \%/\% d, divq.bigz(1:10, 7)), identical(a \%\% d, mod.bigz (a, d)) ) } \keyword{arith} %\keyword{bigz} gmp/man/extract.Rd0000644000176200001440000000445114662074261013565 0ustar liggesusers\name{extract} \title{Extract or Replace Parts of a 'bigz' or 'bigq' Object} \alias{[.bigz} %F\alias{[<-}% otherwise warning " Objects in \usage w/o \alias : '[<-' " \alias{[<-.bigz} \alias{[[.bigz} \alias{[[<-.bigz} \alias{c.bigz} \alias{rep.bigz} \alias{length.bigz} \alias{length<-.bigz} \alias{[.bigq} \alias{[<-.bigq} \alias{[[.bigq} \alias{[[<-.bigq} %- \alias{c.bigq} \alias{rep.bigq} \alias{length.bigq} \alias{length<-.bigq} \description{ Operators acting on vectors, arrays and lists to extract or replace subsets. } \usage{ \method{[}{bigz}(x, i=NULL, j=NULL, drop = TRUE) \method{[}{bigq}(x, i=NULL, j=NULL, drop = TRUE) %F \method{[<-}{bigq}(x, i=NULL, j=NULL, value) % ==> "the same", manually -- R check-bug: %F x[i=NULL, j=NULL] <- value % still WARNING .. usage in doc.. .. but not in code: `[<-` ##___ In the following, only the bigq method is mentioned (but 'bigz' is "the same"): ___ \method{c}{bigq}(\dots, recursive = FALSE) \method{rep}{bigq}(x, times=1, length.out=NA, each=1, \dots) } \arguments{ \item{x}{\R object of class \code{"bigz"} or \code{"bigq"}, respectively.} \item{\dots}{further arguments, notably for \code{c()}.} \item{i,j}{indices, see standard \R subsetting and subassignment.} \item{drop}{logical, unused here, i.e., matrix subsetting \bold{always} returns a matrix, here!} %F \item{value}{\R object, typically of same \code{\link{class}} as %F \code{x}, or also \code{\link{numeric}}.} \item{times, length.out, each}{integer; typically only \emph{one} is specified; for more see \code{\link{rep}} (standard \R, package \pkg{base}). } \item{recursive}{from \code{c()}'s default method; disregarded here} } \examples{ a <- as.bigz(123) ## indexing "outside" --> extends the vectors (filling with NA) a[2] <- a[1] a[4] <- -4 ## create a vector of 3 a c(a,a,a) ## repeate a 5 times rep(a,5) ## with matrix: 3 x 2 m <- matrix.bigz(1:6,3) m[1,] # the first row m[1,, drop=TRUE] # the same: drop does *not* drop m[1] m[-c(2,3),] m[-c(2,3)] m[c(TRUE,FALSE,FALSE)] \dontshow{ stopifnot(identical(c(a,a), rep(a,2)), identical(rep(a,0), a[FALSE]), length(a[FALSE]) == 0, identical(m[1,], m[-(2:3),]), identical(m[1,], m[c(TRUE,FALSE,FALSE),]) ) } ##_modification on matrix m[2,-1] <- 11 } \keyword{arith} gmp/man/factor.Rd0000644000176200001440000000115714444267422013372 0ustar liggesusers\name{factorization} \alias{factorize} \title{Factorize a number} \description{Give all primes numbers to factor the number} \usage{factorize(n)} \arguments{ \item{n}{Either integer, numeric or string value (String value: ither starting with \code{0x} for hexadecimal, \code{0b} for binary or without prefix for decimal values.) Or an element of class bigz.} } \details{ The factorization function uses the Pollard Rho algorithm. } \value{ Vector of class bigz. } \references{The GNU MP Library, see \url{https://gmplib.org}} \author{Antoine Lucas} \examples{ factorize(34455342) } \keyword{arith} gmp/man/binomQ.Rd0000644000176200001440000000332714444267422013342 0ustar liggesusers\name{binomQ} \title{Exact Rational Binomial Probabilities} \alias{dbinomQ} %NOT YET \alias{pbinomQ} \description{ Compute \emph{exact} binomial probabilities using (big integer and) big rational arithmetic. } \usage{ dbinomQ(x, size, prob, log = FALSE) } %% pbinomQ(q, size, prob, lower.tail = TRUE, log.p = FALSE) % \arguments{ \item{x, size}{integer or big integer (\code{"\link{bigz}"}), will be passed to \code{\link{chooseZ}()}.} \item{prob}{the probability; should be big rational (\code{"\link{bigq}"}); if not it is coerced with a warning.} \item{log}{logical; must be \code{FALSE} on purpose. Use \code{log(Rmpfr::\link[Rmpfr]{mpfr}(dbinomQ(..), precB))} for the logarithm of such big rational numbers.} } \value{a big rational (\code{"\link{bigq}"}) of the \code{\link{length}} of (recycled) \code{x+size+prob}. } \author{Martin Maechler} \seealso{ \code{\link{chooseZ}}; \R's (\pkg{stats} package) \code{\link{dbinom}()}. } \examples{ dbinomQ(0:8,8, as.bigq(1,2)) ## 1/256 1/32 7/64 7/32 35/128 7/32 7/64 1/32 1/256 ph16. <- dbinomQ(0:16, size=16, prob = 1/2) # innocous warning ph16 <- dbinomQ(0:16, size=16, prob = as.bigq(1,2)) ph16.75 <- dbinomQ(0:16, size=16, prob = as.bigq(3,4)) ph8.75 <- dbinomQ(0:8, 8, as.bigq(3,4)) stopifnot(exprs = { dbinomQ(0:8,8, as.bigq(1,2)) * 2^8 == choose(8, 0:8) identical(ph8.75, chooseZ(8,0:8) * 3^(0:8) / 4^8) all.equal(ph8.75, choose (8,0:8) * 3^(0:8) / 4^8, tol=1e-15) # see exactly equal identical(ph16, ph16.) identical(ph16, dbinomQ(0:16, size=16, prob = as.bigz(1)/2)) all.equal(dbinom(0:16, 16, prob=1/2), asNumeric(ph16), tol=1e-15) all.equal(dbinom(0:16, 16, prob=3/4), asNumeric(ph16.75), tol=1e-15) }) } gmp/man/operators_bigq.Rd0000644000176200001440000000230514444267422015130 0ustar liggesusers\name{Bigq_operators} \alias{add.bigq} \alias{+.bigq} \alias{sub.bigq} \alias{-.bigq} \alias{mul.bigq} \alias{*.bigq} \alias{div.bigq} \alias{/.bigq} \alias{pow.bigq} \alias{^.bigq} \alias{abs.bigq} \title{Basic arithmetic operators for large rationals} \description{ Addition, subtraction, multiplication, division, and absolute value for large rationals, i.e. \code{"\link{bigq}"} class \R objects. } \usage{ add.bigq(e1, e2) \method{+}{bigq}(e1, e2) sub.bigq(e1, e2=NULL) \method{-}{bigq}(e1, e2) mul.bigq(e1, e2) \method{*}{bigq}(e1, e2) div.bigq(e1, e2) \method{/}{bigq}(e1, e2) \method{^}{bigq}(e1, e2) \method{abs}{bigq}(x) } \arguments{ \item{e1,e2, x}{of class \code{"\link{bigq}"}, or (\code{e1} and \code{e2}) integer or string from an integer} } \details{ Operators can be use directly when the objects are of class \code{"\link{bigq}"}: a + b, a * b, etc, and \code{a ^ n}, where \code{n} must be coercable to a biginteger (\code{"\link{bigz}"}). } \value{ A bigq class representing the result of the arithmetic operation. } \author{Immanuel Scholz and Antoine Lucas} \examples{ ## 1/3 + 1 = 4/3 : as.bigq(1,3) + 1 r <- as.bigq(12, 47) stopifnot(r ^ 3 == r*r*r) } \keyword{arith} gmp/man/Oakley.Rd0000644000176200001440000000172714444267422013343 0ustar liggesusers\name{Oakley} \alias{Oakley} \alias{Oakley1} \alias{Oakley2} \title{RFC 2409 Oakley Groups - Parameters for Diffie-Hellman Key Exchange} \description{ RFC 2409 standardizes global unique prime numbers and generators for the purpose of secure asymmetric key exchange on the Internet. } \usage{ data(Oakley1) data(Oakley2) } \value{ Oakley1 returns an object of class \code{\link{bigz}} for a 768 bit Diffie-Hellman group. The generator is stored as value with the respective prime number as modulus attribute. Oakley2 returns an object of class \code{\link{bigz}} for a 1024 bit Diffie-Hellman group. The generator is stored as value with the respective prime number as modulus attribute. } \references{The Internet Key Exchange (RFC 2409), Nov. 1998} \examples{ packageDescription("gmp") # {possibly useful for debugging} data(Oakley1) (M1 <- modulus(Oakley1)) isprime(M1)# '1' : "probably prime" sizeinbase(M1)# 232 digits (was 309 in older version) } \keyword{data} gmp/man/is.whole.Rd0000644000176200001440000000210314444267422013634 0ustar liggesusers\name{is.whole} \alias{is.whole} \alias{is.whole.default} \alias{is.whole.bigz} \alias{is.whole.bigq} \title{Whole ("Integer") Numbers} \description{ Check which elements of \code{x[]} are integer valued aka \dQuote{whole} numbers. } \usage{ is.whole(x) \S3method{is.whole}{default}(x) \S3method{is.whole}{bigz}(x) \S3method{is.whole}{bigq}(x) } \arguments{ \item{x}{any \R vector} } \value{ logical vector of the same length as \code{x}, indicating where \code{x[.]} is integer valued. } \author{Martin Maechler} \seealso{ \code{\link{is.integer}(x)} (\pkg{base} package) checks for the \emph{internal} mode or class; not if \code{x[i]} are integer valued. The \code{\link[Rmpfr]{is.whole}()} method for "mpfr" numbers. } \examples{ is.integer(3) # FALSE, it's internally a double is.whole(3) # TRUE ## integer valued complex numbers (two FALSE) : is.whole(c(7, 1 + 1i, 1.2, 3.4i, 7i)) is.whole(factorialZ(20)^(10:12)) ## "bigz" are *always* whole numbers q <- c(as.bigz(36)^50 / as.bigz(30)^40, 3, factorialZ(30:31), 12.25) is.whole(q) # F T T T F } \keyword{math} gmp/man/powm.Rd0000644000176200001440000000140514444267422013072 0ustar liggesusers\name{powm} \alias{powm} \title{Exponentiation function} \description{ This function return \eqn{x ^ y mod n}. This function return \eqn{x ^ y mod n}{x ^ y mod n} pow.bigz do the same when modulus is set. } \usage{ powm(x, y, n) } %- maybe also 'usage' for other objects documented here. \arguments{ \item{x}{Integer or big integer - possibly a vector} \item{y}{Integer or big integer - possibly a vector} \item{n}{Integer or big integer - possibly a vector} } % \details{ % This function return \eqn{x ^ y mod n}{x ^ y mod n} % pow.bigz do the same when modulus is set. % } \value{ A bigz class representing the parameter value. } \author{A. L.} \seealso{\code{\link{pow.bigz}}} \examples{ powm(4,7,9) x = as.bigz(4,9) x ^ 7 } \keyword{arith} gmp/man/utils.Rd0000644000176200001440000000071014444267422013246 0ustar liggesusers\name{gmp.utils} \title{GMP Number Utilities} % \alias{gmp.is.0} % \alias{gmp.is.integer} \alias{gmpVersion} % \description{ \code{gmpVersion()} returns the version of the GMP library which \pkg{gmp} is currently linked to. } \usage{ gmpVersion() } % \arguments{ % } \references{The GNU MP Library, see \url{https://gmplib.org}} % \details{ % ~~ If necessary, more details than the description above ~~ % } \examples{ gmpVersion() } \keyword{arith} gmp/man/gcdex.Rd0000644000176200001440000000132114444267422013177 0ustar liggesusers\name{gcdex} \alias{gcdex} \title{Compute Bezoult Coefficient} \description{ Compute g,s,t as \eqn{as + bt = g = gcd(a,b)}{as + bt = g = gcd(a,b)}. s and t are also known as Bezoult coefficients. } \usage{ gcdex(a, b) } \arguments{ \item{a,b}{either integer, numeric, character string, or of class \code{"bigz"}; If a string, either starting with \code{"0x"} for hexadecimal, \code{"0b"} for binary or without prefix for decimal values.} } \value{ a class \code{"bigz"} vector of length 3 with (long integer) values \eqn{g, s, t}. } \references{The GNU MP Library, see \url{https://gmplib.org}} \author{Antoine Lucas} \seealso{\code{\link{gcd.bigz}}} \examples{ gcdex(342,654) } \keyword{arith} gmp/man/extreme.Rd0000644000176200001440000000320214444267422013556 0ustar liggesusers\name{Extremes} \title{Extrema (Maxima and Minima)} \alias{max.bigz} \alias{max.bigq} \alias{min.bigz} \alias{min.bigq} \alias{which.max,bigq-method} \alias{which.max,bigz-method} \alias{which.min,bigq-method} \alias{which.min,bigz-method} \usage{ \method{max}{bigz}(..., na.rm=FALSE) \method{max}{bigq}(..., na.rm=FALSE) \method{min}{bigz}(..., na.rm=FALSE) \method{min}{bigq}(..., na.rm=FALSE) \S4method{which.min}{bigz}(x) %S4method{which.min}{bigq}(x) %S4method{which.max}{bigz}(x) \S4method{which.max}{bigq}(x) } \description{ We provide S3 \code{\link{methods}} for \code{\link{min}} and \code{\link{max}} for big rationals (\code{bigq}) and big integers (\code{biqz}); consequently, \code{\link{range}()} works as well. Similarly, S4 methods are provided for \code{\link{which.min}()} and \code{\link{which.max}()}. } \arguments{ \item{x}{a \dQuote{big integer} (\code{bigz}) or \dQuote{big rational} (\code{bigq}) vector.} \item{...}{numeric arguments} \item{na.rm}{a logical indicating whether missing values should be removed.} } \value{ an object of class \code{"\link{bigz}"} or \code{"\link{bigq}"}. } \author{Antoine Lucas}% Martin Maechler: which.min & which.max \examples{ x <- as.bigz(1:10) max(x) min(x) range(x) # works correctly via default method x <- x[c(7:10,6:3,1:2)] which.min(x) ## 9 which.max(x) ## 4 Q <- as.bigq(1:10, 3) max(Q) min(Q) (Q <- Q[c(6:3, 7:10,1:2)]) stopifnot(which.min(Q) == which.min(asNumeric(Q)), which.max(Q) == which.max(asNumeric(Q))) stopifnot(range(x) == c(1,10), 3*range(Q) == c(1,10)) } \seealso{ \code{\link{max}} etc in \pkg{base}. } \keyword{arith} gmp/man/gcd.Rd0000644000176200001440000000212614444267422012646 0ustar liggesusers\name{gcd.bigz} \title{Greatest Common Divisor (GCD) and Least Common Multiple (LCM)} \alias{gcd.bigz} \alias{gcd} \alias{gcd.default} \alias{lcm.default} %\alias{lcm}% FIXME (R !): conflict with graphics::lcm is the trivial function \alias{lcm.bigz} \concept{GCD} \concept{LCM} \description{ Compute the greatest common divisor (GCD) and least common multiple (LCM) of two (big) integers. } \usage{ \method{gcd}{bigz}(a, b) lcm.bigz(a, b) } \arguments{ \item{a,b}{Either integer, numeric, \code{\link{bigz}} or a string value; if a string, either starting with \code{0x} for hexadecimal, \code{0b} for binary or without prefix for decimal values.} } \value{ An element of class bigz } \references{The GNU MP Library, see \url{https://gmplib.org}} \author{Antoine Lucas} \seealso{\code{\link{gcdex}}} \examples{ gcd.bigz(210,342) # or also lcm.bigz(210,342) a <- 210 ; b <- 342 stopifnot(gcd.bigz(a,b) * lcm.bigz(a,b) == a * b) ## or (a <- as.bigz("82696155787249022588")) (b <- as.bigz("65175989479756205392")) gcd(a,b) # 4 stopifnot(gcd(a,b) * lcm.bigz(a,b) == a * b) } \keyword{arith} gmp/man/sizeinbase.Rd0000644000176200001440000000147114444267422014247 0ustar liggesusers\name{sizeinbase} \alias{sizeinbase} \title{Compute size of a bigz in a base} \description{ Return an approximation to the number of character the integer X would have printed in base b. The approximation is never too small. In case of powers of 2, function gives exact result. } \usage{ sizeinbase(a, b=10) } \arguments{ \item{a}{big integer, i.e. \code{"\link{bigz}"}} \item{b}{base} } \value{ integer of the same length as \code{a}: the size, i.e. number of digits, of each \code{a[i]}. } \references{The GNU MP Library, see \url{https://gmplib.org}} \author{Antoine Lucas} \examples{ sizeinbase(342434, 10)# 6 obviously Iv <- as.bigz(2:7)^500 sizeinbase(Iv) stopifnot(sizeinbase(Iv) == nchar(as.character(Iv)), sizeinbase(Iv, b=16) == nchar(as.character(Iv, b=16))) } \keyword{arith} gmp/man/frexpZ.Rd0000644000176200001440000000256714444267422013400 0ustar liggesusers\name{frexpZ} \title{Split Number into Fractional and Exponent of 2 Parts} \alias{frexpZ} \alias{frexp}% for search -- FIXME? make frexp() a generic with bigz() method? \description{ Breaks the number \code{x} into its binary significand (\dQuote{fraction}) \eqn{d \in [0.5, 1)}{d in [0.5, 1)} and \eqn{ex}, the integral exponent for 2, such that \eqn{x = d \cdot 2^{ex}.}{x = d * 2 ^ ex.} If \code{x} is zero, both parts (significand and exponent) are zero. } \usage{ frexpZ(x) } \arguments{ \item{x}{integer or big integer (\code{\link{bigz}}).} } \value{ a \code{\link{list}} with the two components \item{d}{a numeric vector whose absolute values are either zero, or in \eqn{[\frac{1}{2}, 1)}{[0.5, 1)}.} \item{exp}{an integer vector of the same length; note that \code{exp == 1 + floor(log2(x))}, and hence always \code{exp > log2(x)}.} } \author{Martin Maechler} \seealso{ \code{\link{log2}}, etc; for \code{\link{bigz}} objects built on (the C++ equivalent of) \code{frexp()}, actually GMP's \samp{mpz_get_d_2exp()}. } \examples{ frexpZ(1:10) ## and confirm : with(frexpZ(1:10), d * 2^exp) x <- rpois(1000, lambda=100) * (1 + rpois(1000, lambda=16)) X <- as.bigz(x) stopifnot(all.equal(x, with(frexpZ(x), d* 2^exp)), 1+floor(log2(x)) == (fx <- frexpZ(x)$exp), fx == frexpZ(X)$exp, 1+floor(log2(X)) == fx ) } \keyword{arith} gmp/man/isprime.Rd0000644000176200001440000000363214444267422013564 0ustar liggesusers\name{isprime} \alias{isprime} \title{Determine if number is (very probably) prime} \description{ Determine whether the number \eqn{n} is prime or not, with \emph{three} possible answers: \describe{ \item{2:}{\eqn{n} is prime,} \item{1:}{\eqn{n} is probably prime (without beeing certain),} \item{0:}{\eqn{n} is composite.} } } \usage{ isprime(n, reps = 40) % we feel better with 40 :) } \arguments{ \item{n}{integer number, to be tested.} \item{reps}{integer number of primality testing repeats.} } \details{ This function does some trial divisions, then some Miller-Rabin probabilistic primary tests. \code{reps} controls how many such tests are done, 5 to 10 is already a resonable number. More will reduce the chances of a composite being returned as \dQuote{probably prime}. } \value{ \item{0}{\eqn{n} is not prime} \item{1}{\eqn{n} is probably prime} \item{2}{\eqn{n} is prime} } \references{The GNU MP Library, see \url{https://gmplib.org}} \author{Antoine Lucas} \seealso{ \code{\link{nextprime}}, \code{\link{factorize}}. Note that for \dQuote{small} \eqn{n}, which means something like \eqn{n < 10'000'000}, non-probabilistic methods (such as \code{\link{factorize}()}) are fast enough. } \examples{ isprime(210) isprime(71) # All primes numbers from 1 to 100 t <- isprime(1:99) (1:99)[t > 0] table(isprime(1:10000))# 0 and 2 : surely prime or not prime primes <- function(n) { ## all primes <= n stopifnot(length(n) == 1, n <= 1e7) # be reasonable p <- c(2L, as.integer(seq(3, n, by=2))) p[isprime(p) > 0] } ## quite quickly, but for these small numbers ## still slower than e.g., sfsmisc::primes() system.time(p100k <- primes(100000)) ## The first couple of Mersenne primes: p.exp <- primes(1000) Mers <- as.bigz(2) ^ p.exp - 1 isp.M <- sapply(seq_along(Mers), function(i) isprime(Mers[i], reps=256)) cbind(p.exp, isp.M)[isp.M > 0,] Mers[isp.M > 0] } \keyword{arith} gmp/man/formatN.Rd0000644000176200001440000000242514444267422013521 0ustar liggesusers\name{formatN} \title{Format Numbers Keeping Classes Distinguishable} \alias{formatN} \alias{formatN.default} \alias{formatN.integer} \alias{formatN.double} \alias{formatN.bigz} \alias{formatN.bigq} \description{ Format (generalized) numbers in a way that their \code{\link{class}}es are distinguishable. Contrary to \code{\link{format}()} which uses a common format for all elements of \code{x}, here, each entry is formatted individually. } \usage{ formatN(x, ...) \S3method{formatN}{default}(x, ...) \S3method{formatN}{integer}(x, ...) \S3method{formatN}{double}(x, ...) \S3method{formatN}{bigz}(x, ...) \S3method{formatN}{bigq}(x, ...) } \arguments{ \item{x}{any \R object, typically \dQuote{number-like}.} \item{\dots}{potentially further arguments passed to methods.} } \value{ a character vector of the same \code{\link{length}} as \code{x}, each entry a representation of the corresponding entry in \code{x}. } \author{Martin Maechler} \seealso{ \code{\link{format}}, including its (sophisticated) default method; \code{\link{as.character}}. } \examples{ ## Note that each class is uniquely recognizable from its output: formatN( -2:5)# integer formatN(0 + -2:5)# double precision formatN(as.bigz(-2:5)) formatN(as.bigq(-2:5, 4)) } \keyword{character} \keyword{print} gmp/man/base-copies.Rd0000644000176200001440000000111514444267422014300 0ustar liggesusers\name{gmp-ifiworkarounds} \alias{outer} \title{Base Functions in 'gmp'-ified Versions} \description{ Functions from \pkg{base} etc which need a \emph{copy} in the \pkg{gmp} namespace so they correctly dispatch. } \usage{ outer(X, Y, FUN = "*", ...) } \arguments{ \item{X, Y, FUN, ...}{See \pkg{base} package help: \code{\link[base]{outer}}.} } \seealso{ \code{\link[base]{outer}}. } \examples{ twop <- as.bigz(2)^(99:103) (mtw <- outer(twop, 0:2)) stopifnot( identical(dim(mtw), as.integer(c(5,3))) , mtw[,1] == 0 , identical(as.vector(mtw[,2]), twop) ) } \keyword{misc} gmp/man/mpfr.Rd0000644000176200001440000000176614447323634013067 0ustar liggesusers\name{mpfr} \title{Exported function for mpfr use} \alias{.as.bigz} \alias{..as.bigz} \alias{.as.char.bigz} \alias{.sub.bigq} \description{ Theses hidden function are provided for mpfr use. Use theses function with care. } \usage{ .as.bigz(a, mod=NA) } \arguments{ \item{a}{either \code{\link{integer}}, \code{\link{numeric}} (i.e., \code{\link{double}}) or \code{\link{character}} vector. If character: the strings either start with \code{0x} for hexadecimal, \code{0b} for binary, \code{0} for octal, or without a \code{0*} prefix for decimal values. Formatting errors are signalled as with \code{\link{stop}}.} \item{mod}{an integer, numeric, string or bigz of the internal modulus, see below.} } \references{The GNU MP Library, see \url{https://gmplib.org}} % \details{ % ~~ If necessary, more details than the description above ~~ % } \value{ An \R object of (S3) class \code{"bigz"}, representing the argument (\code{x} or \code{a}). } \examples{ .as.bigz(1) } \keyword{arith} gmp/man/comp.biginteger.Rd0000644000176200001440000000120714444267422015164 0ustar liggesusers\name{Relational_Operator} \alias{==.bigz} \alias{!=.bigz} \alias{<.bigz} \alias{<=.bigz} \alias{>.bigz} \alias{>=.bigz} \alias{sign.bigz} \title{Relational Operators} \description{ Binary operators which allow the comparison of values in atomic vectors. } \usage{ \method{sign}{bigz}(x) \method{==}{bigz}(e1, e2) \method{<}{bigz} (e1, e2) \method{>=}{bigz}(e1, e2) } \arguments{ \item{x, e1, e2}{\R object (vector or matrix-like) of class \code{"\link{bigz}"}.} } \seealso{\code{\link{mod.bigz}} for arithmetic operators. } \examples{ x <- as.bigz(8000) x ^ 300 < 2 ^x sign(as.bigz(-3:3)) sign(as.bigq(-2:2, 7)) } \keyword{arith} gmp/man/solve.Rd0000644000176200001440000000301414444267422013236 0ustar liggesusers\name{solve.bigz} \alias{solve.bigz} \alias{solve.bigq} \title{Solve a system of equation} \description{ This generic function solves the equation \eqn{a \%*\% x = b} for \eqn{x}, where \eqn{b} can be either a vector or a matrix. If a and b are rational, return is a rational matrix. If a and b are big integers (of class bigz) solution is in Z/nZ if there is a common modulus, or a rational matrix if not. } \usage{ \method{solve}{bigz}(a, b, ...) \method{solve}{bigq}(a, b, ...) } \arguments{ \item{a,b}{A element of class bigz or bigq} \item{\dots}{Unused} } \details{ It uses the Gauss and trucmuch algo \dots (to be detailled).%% FIXME } \value{ If a and b are rational, return is a rational matrix. If a and b are big integers (of class bigz) solution is in Z/nZ if there is a common modulus, of a rational matrix if not. } \author{Antoine Lucas} \seealso{\code{\link{solve}}} \examples{ x <- matrix(1:4,2,2) ## standard solve : solve(x) q <- as.bigq(x) ## solve with rational solve(q) z <- as.bigz(x) modulus(z) <- 7 ## solve in Z/7Z : solve(z) b <- c(1,3) solve(q,b) solve(z,b) ## Inversion of ("non-trivial") rational matrices : A <- rbind(c(10, 1, 3), c( 4, 2, 10), c( 1, 8, 2)) (IA.q <- solve(as.bigq(A))) # fractions.. stopifnot(diag(3) == A \%*\% IA.q)# perfect set.seed(5); B <- matrix(round(9*runif(5^2, -1,1)), 5) B (IB.q <- solve(as.bigq(B))) stopifnot(diag(5) == B \%*\% IB.q, diag(5) == IB.q \%*\% B, identical(B, asNumeric(solve(IB.q)))) } \keyword{arith} gmp/man/modulus.Rd0000644000176200001440000000173614444267422013607 0ustar liggesusers\name{modulus} \alias{modulus} \alias{modulus<-} \alias{modulus.bigz} \alias{modulus<-.bigz} \title{Modulus of a Big Integer} \description{ The modulus of a \code{\link{bigz}} number \eqn{a} is \dQuote{unset} when \eqn{a} is a regular integer, \eqn{a \in Z}). Or the modulus can be set to \eqn{m} which means \eqn{a \in Z/\,m\cdot Z}{a in Z/mZ}), i.e., all arithmetic with \eqn{a} is performed \sQuote{modulo m}. } \usage{ modulus(a) modulus(a) <- value } \arguments{ \item{a}{\R object of class \code{"\link{bigz}"}} \item{value}{integer number or object of class \code{"\link{bigz}"}.} } \examples{ x <- as.bigz(24) modulus(x) # NULL, i.e. none # x element of Z/31Z : modulus(x) <- 31 x+x # 48 |-> (17 \%\% 31) 10*x # 240 |-> (23 \%\% 31) x31 <- x # reset modulus to "none": modulus(x) <- NA; x; x. <- x x <- x31 modulus(x) <- NULL; x stopifnot(identical(x, as.bigz(24)), identical(x, x.), identical(modulus(x31), as.bigz(31))) } \keyword{arith} gmp/man/asNumeric.Rd0000644000176200001440000000327714444267422014047 0ustar liggesusers\name{asNumeric} \alias{asNumeric} \alias{asNumeric-methods} \alias{asNumeric,ANY-method} \alias{asNumeric,bigq-method} \alias{asNumeric,bigz-method} \title{Coerce to 'numeric', not Loosing Dimensions} \description{ a number-like object is coerced to type (\link{typeof}) \code{"numeric"}, keeping \code{\link{dim}} (and maybe \code{\link{dimnames}}) when present. } \usage{ asNumeric(x) } \arguments{ \item{x}{a \dQuote{number-like} object, e.g., big integer (\code{\link{bigz}}), or \code{\link[Rmpfr]{mpfr}}, notably including matrices and arrays of such numbers.} } \section{Methods}{ \describe{ \item{\code{signature(x = "ANY")}}{the default method, which is the identity for \code{\link{numeric}} array.} \item{\code{signature(x = "bigq")}}{the method for big rationals.} \item{\code{signature(x = "bigq")}}{the method for big integers.} } Note that package \pkg{Rmpfr} provides methods for its own number-like objects. % --> ~/R/Pkgs/Rmpfr/man/asNumeric-methods.Rd } %% \details{ %% %% ~~ If necessary, more details than the description above ~~ %% } \value{ an \R object of type (\code{\link{typeof}}) \code{"numeric"}, a \code{\link{matrix}} or \code{\link{array}} if \code{x} had non-NULL dimension \code{\link{dim}()}. } \author{Martin Maechler} \seealso{ \code{\link{as.numeric}} coerces to both \code{"numeric"} and to a \code{\link{vector}}, whereas \code{asNumeric()} should keep \code{\link{dim}} (and other) attributes. } \examples{ m <- matrix(1:6, 2,3) stopifnot(identical(m, asNumeric(m)))# remains matrix (M <- as.bigz(m) / 5) ##-> "bigq" matrix asNumeric(M) # numeric matrix stopifnot(all.equal(asNumeric(M), m/5)) } \keyword{arith} \keyword{methods} gmp/man/Stirling.Rd0000644000176200001440000000564214531371253013705 0ustar liggesusers\name{Stirling} \title{Eulerian and Stirling Numbers of First and Second Kind} \alias{Eulerian} \alias{Stirling1} \alias{Stirling2} \alias{Eulerian.all} \alias{Stirling1.all} \alias{Stirling2.all} \description{ Compute Eulerian numbers and Stirling numbers of the first and second kind, possibly vectorized for all \eqn{k} \dQuote{at once}. } \usage{ Stirling1(n, k) Stirling2(n, k, method = c("lookup.or.store", "direct")) Eulerian (n, k, method = c("lookup.or.store", "direct")) Stirling1.all(n) Stirling2.all(n) Eulerian.all (n) } \arguments{ \item{n}{positive integer (\code{0} is allowed for \code{Eulerian()}).} \item{k}{integer in \code{0:n}.} \item{method}{for \code{Eulerian()} and \code{Stirling2()}, string specifying the method to be used. \code{"direct"} uses the explicit formula (which may suffer from some cancelation for \dQuote{large} \code{n}).} } \details{ Eulerian numbers:\cr \eqn{A(n,k) =} the number of permutations of 1,2,\dots,n with exactly \eqn{k} ascents (or exactly \eqn{k} descents). Stirling numbers of the first kind:\cr \eqn{s(n,k) = (-1)^{n-k}} times the number of permutations of 1,2,\dots,n with exactly k cycles. Stirling numbers of the second kind:\cr \eqn{S^{(k)}_n}{S(n,k)} is the number of ways of partitioning a set of \eqn{n} elements into \eqn{k} non-empty subsets. } \value{ \eqn{A(n,k)}, \eqn{s(n,k)} or \eqn{S(n,k) = S^{(k)}_n}{S(n,k)}, respectively. \code{Eulerian.all(n)} is the same as \code{sapply(0:(n-1), Eulerian, n=n)} (for \eqn{n > 0}), \cr \code{Stirling1.all(n)} is the same as \code{sapply(1:n, Stirling1, n=n)}, and\cr \code{Stirling2.all(n)} is the same as \code{sapply(1:n, Stirling2, n=n)}, but more efficient. } \note{ For typical double precision arithmetic,\cr \code{Eulerian*(n, *)} overflow (to \code{Inf}) for \eqn{n \ge 172},\cr \code{Stirling1*(n, *)} overflow (to \eqn{\pm}{+/-}\code{Inf}) for \eqn{n \ge 171}, and\cr \code{Stirling2*(n, *)} overflow (to \code{Inf}) for \eqn{n \ge 220}. %% and it would be possible to implement Stirling*(n, log=TRUE) without %% overflow, but a bit tedious, as one should "log-scale arithmetic only %% for large n, and hence as to *switch* for n >= n.max } \author{Martin Maechler ("direct": May 1992)} \references{ \bold{Eulerians:} NIST Digital Library of Mathematical Functions, 26.14: \url{https://dlmf.nist.gov/26.14} \bold{Stirling numbers:} Abramowitz and Stegun 24,1,4 (p. 824-5 ; Table 24.4, p.835); Closed Form : p.824 "C." NIST Digital Library of Mathematical Functions, 26.8: \url{https://dlmf.nist.gov/26.8} } \seealso{ \code{\link{chooseZ}} for the binomial coefficients. } \examples{ Stirling1(7,2) Stirling2(7,3) stopifnot( Stirling1.all(9) == c(40320, -109584, 118124, -67284, 22449, -4536, 546, -36, 1) , Stirling2.all(9) == c(1, 255, 3025, 7770, 6951, 2646, 462, 36, 1) , Eulerian.all(7) == c(1, 120, 1191, 2416, 1191, 120, 1) ) } \keyword{arithmetic} gmp/man/comp.bigq.Rd0000644000176200001440000000110714444267422013766 0ustar liggesusers\name{Bigq} \alias{==.bigq} \alias{!=.bigq} \alias{<.bigq} \alias{<=.bigq} \alias{>.bigq} \alias{>=.bigq} \alias{sign.bigq} \title{Relational Operators} \description{ Binary operators which allow the comparison of values in atomic vectors. } \usage{ \method{sign}{bigq}(x) \method{<}{bigq}(e1, e2) \method{<=}{bigq}(e1, e2) \method{==}{bigq}(e1, e2) \method{>=}{bigq}(e1, e2) \method{>}{bigq}(e1, e2) \method{!=}{bigq}(e1, e2) } \arguments{ \item{x, e1, e2}{Object or vector of class \code{\link{bigq}}} } \examples{ x <- as.bigq(8000,21) x < 2 * x } \keyword{arith} gmp/man/cumsum.Rd0000644000176200001440000000205414444267422013422 0ustar liggesusers\name{cumsum} \alias{cumsum.bigz} \alias{cumsum.bigq} \alias{sum.bigz} \alias{sum.bigq} \alias{prod.bigz} \alias{prod.bigq} \title{(Cumulative) Sums, Products of Large Integers and Rationals} \description{ Theses are methods to \sQuote{overload} the \code{\link{sum}()}, \code{\link{cumsum}()} and \code{\link{prod}()} functions for big rationals and big integers. } \usage{ \S3method{cumsum}{bigz}(x) \S3method{cumsum}{bigq}(x) \S3method{sum}{bigz}(..., na.rm = FALSE) \S3method{sum}{bigq}(..., na.rm = FALSE) \S3method{prod}{bigz}(..., na.rm = FALSE) \S3method{prod}{bigq}(..., na.rm = FALSE) } \arguments{ \item{x, ...}{\R objects of class \code{bigz} or \code{bigq} or \sQuote{simple} numbers.} \item{na.rm}{logical indicating if missing values (\code{\link{NA}}) should be removed before the computation.} } \value{ return an element of class bigz or bigq. } \author{Antoine Lucas} \seealso{\code{\link{apply}} } \examples{ x <- as.bigz(1:12) cumsum(x) prod(x) sum(x) x <- as.bigq(1:12) cumsum(x) prod(x) sum(x) } \keyword{arith} gmp/man/bigrational.Rd0000644000176200001440000000660714444267422014414 0ustar liggesusers\name{bigq} \title{Large sized rationals} \alias{bigq} \alias{bigq-class} \alias{as.bigq} \alias{is.bigq} \alias{as.character.bigq} \alias{as.double.bigq} \alias{print.bigq} \alias{is.na.bigq} \alias{NA_bigq_} \alias{as.bigz.bigq} \alias{c_bigq} \alias{denominator} \alias{denominator<-} \alias{numerator} \alias{numerator<-} \description{ Class \code{"bigq"} encodes rationals encoded as ratios of arbitrary large integers (via GMP). A simple S3 class (internally a \code{\link{raw}} vector), it has been registered as formal (S4) class (via \code{\link{setOldClass}}), too. } \usage{ as.bigq(n, d = 1) \S3method{as.character}{bigq}(x, b=10,...) \S3method{as.double}{bigq}(x,...) as.bigz.bigq(a, mod=NA) is.bigq(x) \S3method{is.na}{bigq}(x) \S3method{print}{bigq}(x, quote=FALSE, initLine = TRUE, ...) denominator(x) numerator(x) NA_bigq_ c_bigq(L) } \arguments{ \item{n,d}{either integer, numeric or string value (String value: either starting with \code{0x} for hexadecimal, \code{0b} for binary or without prefix for decimal values. Any format error results in \code{0}). \code{n} stands for numerator, \code{d} for denominator.} \item{a}{an element of class \code{"bigq"}} \item{mod}{optional modulus to convert into biginteger} \item{x}{a \dQuote{rational number} (vector), of class \code{"bigq"}.} \item{b}{base: from 2 to 36} \item{...}{additional arguments passed to methods} \item{quote}{(for printing:) logical indicating if the numbers should be quoted (as characters are); the default used to be \code{TRUE} (implicitly) till 2011.} \item{initLine}{(for printing:) logical indicating if an \bold{init}ial line (with the class and length or dimension) should be printed. % not yet smart default .. The default prints it for % those cases where the class is not easily discernable from the % print output. } \item{L}{a \code{\link{list}} where each element contains \code{"bigq"} numbers, for \code{c_bigq()}, this allows something like an \code{\link{sapply}()} for \code{"bigq"} vectors, see \code{sapplyQ()} in the examples below.} } \value{ An \R object of (S3) class \code{"bigq"} representing the parameter value. } \details{ \code{as.bigq(x)} when \code{x} is \code{\link{numeric}} (aka \code{\link{double}} precision) calls the \file{GMP} function \code{mpq_set_d()} which is documented to be \emph{exact} (every finite double precision number is a rational number). \code{as.bigz.bigq()} returns the smallest integers not less than the corresponding rationals bigq. \code{NA_bigq_} is computed on package load time as \code{as.bigq(NA)}. } \author{Antoine Lucas} \examples{ x <- as.bigq(21,6) x # 7 / 2 # Wow ! result is simplified. y <- as.bigq(5,3) # addition works ! x + y # You can even try multiplication, division... x * y / 13 # and, since May 2012, x ^ 20 stopifnot(is.bigq(x), is.bigq(x + y), x ^ 20 == as.bigz(7)^20 / 2^20) # convert to string, double as.character(x) as.double(x) stopifnot( is.na(NA_bigq_) ) # Depict the "S4-class" bigq, i.e., the formal (S4) methods: if(require("Rmpfr")) # mostly interesting there showMethods(class="bigq") # an sapply() version that works for big rationals "bigq": sapplyQ <- function(X, FUN, ...) c_bigq(lapply(X, FUN, ...)) # dummy example showing it works (here): qq <- as.bigq(1, 1:999) q1 <- sapplyQ(qq, function(q) q^2) stopifnot( identical(q1, qq^2) ) } \keyword{arith} gmp/man/biginteger.Rd0000644000176200001440000001521214444267422014230 0ustar liggesusers\name{bigz} \title{Large Sized Integer Values} \alias{bigz} \alias{bigz-class} \alias{as.bigz} \alias{is.bigz} \alias{as.character.bigz} \alias{as.double.bigz} \alias{print.bigz} \alias{is.na.bigz} \alias{NA_bigz_} \alias{c_bigz} % these two are C symbols, will be removed eventually: \alias{biginteger_as} \alias{biginteger_as_character} \description{ Class \code{"bigz"} encodes arbitrarily large integers (via GMP). A simple S3 class (internally a \code{\link{raw}} vector), it has been registered as formal (S4) class (via \code{\link{setOldClass}}), too. } \usage{ as.bigz(a, mod = NA) NA_bigz_ \S3method{as.character}{bigz}(x, b = 10, \dots) % \S3method{as.double}{bigz}(x,\dots) is.bigz(x) \S3method{is.na}{bigz}(x) \S3method{print}{bigz}(x, quote=FALSE, initLine = is.null(modulus(x)), \dots) c_bigz(L) } \arguments{ \item{a}{either \code{\link{integer}}, \code{\link{numeric}} (i.e., \code{\link{double}}) or \code{\link{character}} vector. If character: the strings either start with \code{0x} for hexadecimal, \code{0b} for binary, \code{0} for octal, or without a \code{0*} prefix for decimal values. Formatting errors are signalled as with \code{\link{stop}}.} \item{b}{base: from 2 to 36} \item{x}{a \dQuote{big integer number} (vector), of class \code{"bigz"}.} \item{\dots}{additional arguments passed to methods} \item{mod}{an integer, numeric, string or bigz of the internal modulus, see below.} \item{quote}{(for printing:) logical indicating if the numbers should be quoted (as characters are); the default used to be \code{TRUE} (implicitly) till 2011.} \item{initLine}{(for printing:) logical indicating if an \bold{init}ial line (with the class and length or dimension) should be printed. The default prints it for those cases where the class is not easily discernable from the print output.} \item{L}{a \code{\link{list}} where each element contains \code{"bigz"} numbers, for \code{c_bigz()}, this allows something like an \code{\link{sapply}()} for \code{"bigz"} vectors, see \code{sapplyZ()} in the examples.} } \value{ An \R object of (S3) class \code{"bigz"}, representing the argument (\code{x} or \code{a}). } \details{ Bigz's are integers of arbitrary, but given length (means: only restricted by the host memory). Basic arithmetic operations can be performed on bigzs as addition, subtraction, multiplication, division, modulation (remainder of division), power, multiplicative inverse, calculating of the greatest common divisor, test whether the integer is prime and other operations needed when performing standard cryptographic operations. For a review of basic arithmetics, see \code{\link{add.bigz}}. Comparison are supported, i.e., \code{"=="}, \code{"!="}, \code{"<"}, \code{"<="}, \code{">"}, and \code{">="}. \code{NA_bigz_} is computed on package load time as \code{as.bigz(NA)}. Objects of class \code{"bigz"} may have a \dQuote{modulus}, accessible via \code{\link{modulus}()}, currently as an attribute \code{mod}. When the object has such a modulus \eqn{m}, arithmetic is performed \emph{\dQuote{modulo m}}, mathematically \dQuote{within the ring \eqn{Z/mZ}}. For many operations, this means \preformatted{ result <- mod.bigz(result, m) ## == result \%\% m } is called after performing the arithmetic operation and the result will have the attribute \code{mod} set accordingly. This however does not apply, e.g., for \code{/}, where \eqn{a / b := a b^{-1}}{a / b = a b^(-1)} and \eqn{b^{-1}}{b^(-1)} is the \emph{multiplicate inverse} of \eqn{b} with respect to ring arithmetic, or \code{\link{NA}} with a warning when the inverse does not exist. The warning can be turned off via \code{options("gmp:warnModMismatch" = FALSE)}% FIXME: show+check option() Powers of bigzs can only be performed, if either a modulus is going to be applied to the result bigz or if the exponent fits into an integer value. So, if you want to calculate a power in a finite group (\dQuote{modulo c}), for large \eqn{c} do not use \code{a ^ b \%\% c}, but rather \code{as.bigz(a,c) ^ b}. The following rules for the result's modulus apply when performing arithmetic operations on \code{bigz}s: \itemize{ \item If none of the operand has a modulus set, the result will not have a modulus. \item If both operands have a different modulus, the result will not have a modulus, except in case of \code{\link{mod.bigz}}, where the second operand's value is used. \item If only one of the operands has a modulus or both have a common (the same), it is set and used for the arithmetic operations, except in case of \code{mod.bigz}, where the second operand's value is used. } } \note{ \preformatted{ x <- as.bigz(1234567890123456789012345678901234567890) } will not work as \R converts the number to a double, losing precision and only then convert to a \code{"bigz"} object. Instead, use the syntax \preformatted{ x <- as.bigz("1234567890123456789012345678901234567890") } } \references{The GNU MP Library, see \url{https://gmplib.org}} \author{Immanuel Scholz} \examples{ ## 1+1=2 a <- as.bigz(1) a + a ## Two non-small Mersenne primes: two <- as.bigz(2) p1 <- two^107 -1 ; isprime(p1); p1 p2 <- two^127 -1 ; isprime(p2); p2 stopifnot( is.na(NA_bigz_) ) ## Calculate c = x^e mod n ## -------------------------------------------------------------------- x <- as.bigz("0x123456789abcdef") # my secret message e <- as.bigz(3) # something smelling like a dangerous public RSA exponent (n <- p1 * p2) # a product of two primes as.character(n, b=16)# as both primes were Mersenne's.. ## recreate the three numbers above [for demo below]: n. <- n; x. <- x; e. <- e # save Rev <- function() { n <<- n.; x <<- x.; e <<- e.} # first way to do it right modulus(x) <- n c <- x ^ e ; c ; Rev() # similar second way (makes more sense if you reuse e) to do it right modulus(e) <- n c2 <- x ^ e stopifnot(identical(c2, c), is.bigz(c2)) ; Rev() # third way to do it right c3 <- x ^ as.bigz(e, n) ; stopifnot(identical(c3, c)) # fourth way to do it right c4 <- as.bigz(x, n) ^ e ; stopifnot(identical(c4, c)) # WRONG! (although very beautiful. Ok only for very small 'e' as here) cc <- x ^ e \%\% n cc == c # Return result in hexa as.character(c, b=16) # Depict the "S4-class" bigz, i.e., the formal (S4) methods: if(require("Rmpfr")) # mostly interesting there showMethods(class="bigz") # an sapply() version that works for big integers "bigz": sapplyZ <- function(X, FUN, ...) c_bigz(lapply(X, FUN, ...)) # dummy example showing it works (here): zz <- as.bigz(3)^(1000+ 1:999) z1 <- sapplyZ(zz, function(z) z^2) stopifnot( identical(z1, zz^2) ) } \keyword{arith} gmp/man/factorialZ.Rd0000644000176200001440000000233014444267422014204 0ustar liggesusers\name{factorialZ} \alias{factorialZ} \alias{chooseZ} \title{Factorial and Binomial Coefficient as Big Integer} \description{ Efficiently compute the factorial \eqn{n!} or a binomial coefficient \eqn{{n\choose k}}{choose(n, k)} as big integer (class \code{\link{bigz}}). } \usage{ factorialZ(n) chooseZ(n, k) } \arguments{ \item{n}{non-negative integer (vector), for \code{factorialZ}. For \code{chooseZ}, may be a \code{bigz} big integer, also negative.} \item{k}{non-negative integer vector.} } \value{ a vector of big integers, i.e., of class \code{\link{bigz}}. } \seealso{ \code{\link{factorial}} and \code{\link{gamma}} in base \R; } \examples{ factorialZ(0:10)# 1 1 2 6 ... 3628800 factorialZ(0:40)# larger factorialZ(200) n <- 1000 f1000 <- factorialZ(n) stopifnot(1e-15 > abs(as.numeric(1 - lfactorial(n)/log(f1000)))) system.time(replicate(8, f1e4 <<- factorialZ(10000))) nchar(as.character(f1e4))# 35660 ... (too many to even look at ..) chooseZ(1000, 100:102)# vectorizes chooseZ(as.bigz(2)^120, 10) n <- c(50,80,100) k <- c(20,30,40) ## currently with an undesirable warning: % from methods/src/eval.c _FIXME_ stopifnot(chooseZ(n,k) == factorialZ(n) / (factorialZ(k)*factorialZ(n-k))) } \keyword{arith} gmp/man/apply.Rd0000644000176200001440000000246314444267422013242 0ustar liggesusers\name{apply} \alias{apply} \alias{apply.bigz} \alias{apply.bigq} \alias{apply.default} \title{Apply Functions Over Matrix Margins (Rows or Columns)} \usage{ \method{apply}{bigz}(X, MARGIN, FUN, \dots) \method{apply}{bigq}(X, MARGIN, FUN, \dots) } \description{ These are S3 \code{\link{methods}} for \code{\link{apply}()} which we re-export as S3 generic function. They \dQuote{overload} the \code{apply()} function for big rationals (\code{"bigq"}) and big integers (\code{"bigz"}). } \arguments{ \item{X}{a matrix of class bigz or bigq, see e.g., \code{\link{matrix.bigz}}.} \item{MARGIN}{1: apply function to rows; 2: apply function to columns} \item{FUN}{\code{\link{function}} to be applied} \item{\dots}{(optional) extra arguments for \code{FUN()}, as e.g., in \code{\link{lapply}}.} } \value{ The \code{bigz} and \code{bigq} methods return a vector of class \code{"bigz"} or \code{"bigq"}, respectively. } \seealso{ \code{\link{apply}}; \code{\link{lapply}} is used by our \code{apply()} method. } \author{Antoine Lucas} \examples{ x <- as.bigz(matrix(1:12,3)) apply(x,1,min) apply(x,2,max) x <- as.bigq(x ^ 3, d = (x + 3)^2) apply(x,1, min) apply(x,2, sum) ## now use the "..." to pass na.rm=TRUE : x[2,3] <- NA apply(x,1, sum) apply(x,1, sum, na.rm = TRUE) } \keyword{arith} gmp/man/roundQ.Rd0000644000176200001440000000605614444267422013367 0ustar liggesusers\name{roundQ} \title{Rounding Big Rationals ("bigq") to Decimals} \alias{roundQ} \alias{round0} \alias{round.bigq} \description{ Rounding big rationals (of class \code{"bigq"}, see \code{\link{as.bigq}()}) to decimal \code{digits} is strictly based on a (optionally choosable) definition of rounding to integer, i.e., \code{digits = 0}, the default method of which we provide as \code{round0()}. The users typically just call \code{round(x, digits)} as elsewhere, and the \code{round()} method will call \code{round(x, digits, round0=round0)}. } \usage{ round0(x) roundQ(x, digits = 0, r0 = round0) \S3method{round}{bigq}(x, digits = 0) } \arguments{ \item{x}{vector of big rationals, i.e., of \code{\link{class}} \code{"bigq"}.} \item{digits}{integer number of decimal digits to round to.} \item{r0}{a \code{\link{function}} of one argument which implements a version of \code{\link{round}(x, digits=0)}. The default for \code{roundQ()} is to use our \code{round0()} which implements \dQuote{round to even}, as base \R's \code{\link{round}}.} } \value{ \code{round0()} returns a vector of big integers, i.e., \code{"bigz"} classed. \code{roundQ(x, digits, round0)} returns a vector of big rationals, \code{"bigq"}, as \code{x}. \code{round.bigq} is very simply defined as \code{function(x, digits) roundQ(x, digits)} . } \references{ The vignette \dQuote{\emph{Exact Decimal Rounding via Rationals}} from CRAN package \CRANpkg{round}, % not yet % \url{https://CRAN.R-project.org/package=round/vignettes/rationalRound.html} Wikipedia, Rounding, notably "Round half to even": \url{https://en.wikipedia.org/wiki/Rounding#Round_half_to_even} } \author{Martin Maechler, ETH Zurich} \seealso{ \code{\link{round}} for (double precision) numbers in base \R; \code{\link[round]{roundX}} from CRAN package \CRANpkg{round}. } \examples{ qq <- as.bigq((-21:31), 10) noquote(cbind(as.character(qq), asNumeric(qq))) round0(qq) # Big Integer ("bigz") ## corresponds to R's own "round to even" : stopifnot(round0(qq) == round(asNumeric(qq))) round(qq) # == round(qq, 0): the same as round0(qq) *but* Big Rational ("bigq") halfs <- as.bigq(1,2) + -5:12 \dontshow{q <- c(halfs, qq) stopifnot(round0(q) == round(q)) ; rm(q) } \dontshow{if(FALSE)}% do not create it in user's globalenv ## round0() is simply round0 <- function (x) { nU <- as.bigz.bigq(xU <- x + as.bigq(1, 2)) # traditional round: .5 rounded up if(any(I <- is.whole.bigq(xU))) { # I <==> x == .5 : "hard case" I[I] <- .mod.bigz(nU[I], 2L) == 1L # rounded up is odd ==> round *down* nU[I] <- nU[I] - 1L } nU } ## 's' for simple: rounding as you learned in school: round0s <- function(x) as.bigz.bigq(x + as.bigq(1, 2)) cbind(halfs, round0s(halfs), round0(halfs)) \dontshow{if(FALSE)} ## roundQ() is simply roundQ <- function(x, digits = 0, r0 = round0) { ## round(x * 10^d) / 10^d -- vectorizing in both (x, digits) p10 <- as.bigz(10) ^ digits # class: if(all(digits >= 0)) "bigz" else "bigq" r0(x * p10) / p10 } } \keyword{arith} \concept{Rounding} gmp/man/matrix.Rd0000644000176200001440000001301514662074266013420 0ustar liggesusers\name{matrix} \alias{matrix} \alias{matrix.default} \alias{matrix.bigz} \alias{matrix.bigq} \alias{is.matrixZQ} \alias{as.matrix.bigz} \alias{as.matrix.bigq} \alias{as.vector.bigq} \alias{as.vector.bigz} %-- if this worked with S4: % \alias{\%*\%,bigq,bigq-method} % \alias{\%*\%,bigq,ANY-method} % \alias{\%*\%,ANY,bigq-method} % \alias{\%*\%,bigz,bigz-method} % \alias{\%*\%,bigz,ANY-method} % \alias{\%*\%,ANY,bigz-method} % \alias{crossprod,bigq,bigq-method} % \alias{crossprod,bigq,ANY-method} % \alias{crossprod,ANY,bigq-method} % \alias{crossprod,bigz,bigz-method} % \alias{crossprod,bigz,ANY-method} % \alias{crossprod,ANY,bigz-method} % \alias{tcrossprod,bigq,bigq-method} % \alias{tcrossprod,bigq,ANY-method} % \alias{tcrossprod,ANY,bigq-method} % \alias{tcrossprod,bigz,bigz-method} % \alias{tcrossprod,bigz,ANY-method} % \alias{tcrossprod,ANY,bigz-method} %-- need to stay S3 -- as primitive %*% does not dispatch on setOldClass()ed pseudo-S4 \alias{\%*\%} \alias{\%*\%.default} \alias{\%*\%.bigq} \alias{\%*\%.bigz} \alias{crossprod} \alias{crossprod.default} \alias{crossprod.bigq} \alias{crossprod.bigz} \alias{tcrossprod} \alias{tcrossprod.default} \alias{tcrossprod.bigq} \alias{tcrossprod.bigz} % \alias{ncol.bigq} \alias{ncol.bigz} \alias{nrow.bigq} \alias{nrow.bigz} \alias{cbind.bigz} \alias{cbind.bigq} \alias{rbind.bigz} \alias{rbind.bigq} \alias{t.bigq} \alias{t.bigz} \alias{dim.bigq} \alias{dim<-.bigq} \alias{dim.bigz} \alias{dim<-.bigz} \title{Matrix manipulation with gmp} \description{ Overload of \dQuote{all} standard tools useful for matrix manipulation adapted to large numbers. } % \S4method{\%*\%}{bigz,bigz}(x, y) % \S4method{\%*\%}{bigz,ANY}(x, y) % \S4method{\%*\%}{ANY,bigz}(x, y) \usage{ \S3method{matrix}{bigz}(data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL, mod = NA,...) is.matrixZQ(x) \S3method{\%*\%}{bigz}(x, y) \S3method{\%*\%}{bigq}(x, y) \S3method{crossprod}{bigq}(x, y=NULL,...) \S3method{tcrossprod}{bigz}(x, y=NULL,...) \S3method{cbind}{bigz}(..., deparse.level=1) \S3method{rbind}{bigq}(..., deparse.level=1) ## ..... etc } \arguments{ \item{data}{an optional data vector} \item{nrow}{the desired number of rows } \item{ncol}{the desired number of columns} \item{byrow}{logical. If \code{FALSE} (the default), the matrix is filled by columns, otherwise the matrix is filled by rows.} \item{dimnames}{not implemented for \code{"bigz"} or \code{"bigq"} matrices.} \item{mod}{optional modulus (when \code{data} is \code{"bigz"}).} \item{x,y}{numeric, \code{bigz}, or \code{bigq} matrices or vectors.} \item{..., deparse.level}{arguments from the generic; \emph{not} made use of, i.e., disregarded here.} } \details{ The extract function (\code{"["}) is the same use for vector or matrix. Hence, \code{x[i]} returns the same values as \code{x[i,]}. This is not considered a feature and may be changed in the future (with warnings). All matrix multiplications should work as with numeric matrices. Special features concerning the \code{"\link{bigz}"} class: the modulus can be \describe{ \item{Unset:}{Just play with large numbers} \item{Set with a vector of size 1:}{Example: \code{matrix.bigz(1:6,nrow=2,ncol=3,mod=7)} This means you work in \eqn{Z/nZ}, for the whole matrix. It is the only case where the \code{\%*\%} and \code{\link{solve}} functions will work in \eqn{Z/nZ}.} \item{Set with a vector smaller than data:}{Example: \code{matrix.bigz(1:6,nrow=2,ncol=3,mod=1:5)}. Then, the modulus is repeated to the end of data. This can be used to define a matrix with a different modulus at each row. } \item{Set with same size as data:}{Modulus is defined for each cell} } } \value{ \code{matrix()}: A matrix of class \code{"bigz"} or \code{"bigq"}. \code{is.matrixZQ()}: \code{\link{TRUE}} or \code{FALSE}. \code{dim()}, \code{ncol()}, etc: integer or \code{NULL}, as for simple matrices. \code{cbind(x,y,...)} and \code{rbind(x,y,...)} now (2024-01, since \pkg{gmp} version 0.9-5), do drop \code{deparse.level=.} instead of wrongly creating an extra column or row \emph{and} the \code{"bigz"} method takes all arguments into account and calls the \code{"bigq"} method in case of arguments inheriting from \code{"\link{bigq}"}. } \author{Antoine Lucas and Martin Maechler} \seealso{Solving a linear system: \code{\link{solve.bigz}}. \code{\link[base]{matrix}} } \examples{ V <- as.bigz(v <- 3:7) crossprod(V)# scalar product (C <- t(V)) stopifnot(dim(C) == dim(t(v)), C == v, dim(t(C)) == c(length(v), 1), crossprod(V) == sum(V * V), tcrossprod(V) == outer(v,v), identical(C, t(t(C))), is.matrixZQ(C), !is.matrixZQ(V), !is.matrixZQ(5) ) ## a matrix x <- diag(1:4) ## invert this matrix (xI <- solve(x)) ## matrix in Z/7Z y <- as.bigz(x,7) ## invert this matrix (result is *different* from solve(x)): (yI <- solve(y)) stopifnot(yI \%*\% y == diag(4), y \%*\% yI == diag(4)) ## matrix in Q z <- as.bigq(x) ## invert this matrix (result is the same as solve(x)) (zI <- solve(z)) stopifnot(abs(zI - xI) <= 1e-13, z \%*\% zI == diag(4), identical(crossprod(zI), zI \%*\% t(zI)) ) A <- matrix(2^as.bigz(1:12), 3,4) for(a in list(A, as.bigq(A, 16), factorialZ(20), as.bigq(2:9, 3:4))) { a.a <- crossprod(a) aa. <- tcrossprod(a) stopifnot(identical(a.a, crossprod(a,a)), identical(a.a, t(a) \%*\% a) , identical(aa., tcrossprod(a,a)), identical(aa., a \%*\% t(a)) ) }# {for} } \keyword{arith} gmp/man/BernoulliQ.Rd0000644000176200001440000000172414444267422014170 0ustar liggesusers\name{BernoulliQ} \alias{BernoulliQ} \title{Exact Bernoulli Numbers} \description{%% ../R/Stirling-n-etc.R : Return the \eqn{n}-th Bernoulli number \eqn{B_n}, (or \eqn{B_n^+}{Bn+}, see the reference), where \eqn{B_1 = + \frac 1 2}{B_1 = + 1/2}. } \usage{ BernoulliQ(n, verbose = getOption("verbose", FALSE)) } \arguments{ \item{n}{integer \emph{vector}, \eqn{n \ge 0}{n >= 0}.} \item{verbose}{logical indicating if computation should be traced.} } \value{ a big rational (class \code{\link[=bigq-class]{"bigq"}}) vector of the Bernoulli numbers \eqn{B_n}. } \references{\url{https://en.wikipedia.org/wiki/Bernoulli_number} } \author{Martin Maechler} \seealso{ \code{\link[Rmpfr]{Bernoulli}} in \CRANpkg{Rmpfr} in arbitrary precision via Riemann's \eqn{\zeta}{zeta} function. % \code{\link[DPQ]{Bern}(n)} \code{Bern(n)} in \CRANpkg{DPQ} uses standard (double precision) \R arithmetic for the n-th Bernoulli number. } \examples{ (Bn0.10 <- BernoulliQ(0:10)) } gmp/man/fibonacci.Rd0000644000176200001440000000137714444267422014035 0ustar liggesusers\name{lucnum} \alias{fibnum} \alias{fibnum2} \alias{lucnum} \alias{lucnum2} \title{Compute Fibonacci and Lucas numbers} \description{ fibnum compute n-th Fibonacci number. fibnum2 compute (n-1)-th and n-th Fibonacci number. lucnum compute n-th lucas number. lucnum2 compute (n-1)-th and n-th lucas number. Fibonacci numbers are define by: \eqn{F_n=F_{n-1}+F_{n-2}}{Fn=Fn-1 + Fn-2} Lucas numbers are define by: \eqn{L_n=F_n+2F_{n-1}}{Ln=Fn + 2Fn-1} } \usage{ fibnum(n) fibnum2(n) lucnum(n) lucnum2(n) } \arguments{ \item{n}{Integer} } \value{ Fibonacci numbers and Lucas number. } \references{The GNU MP Library, see \url{https://gmplib.org}} \author{Antoine Lucas} \examples{ fibnum(10) fibnum2(10) lucnum(10) lucnum2(10) } \keyword{arith} gmp/man/nextprime.Rd0000644000176200001440000000137514444267422014131 0ustar liggesusers\name{nextprime} \alias{nextprime} \title{Next Prime Number} \description{ Return the next prime number, say \eqn{p}, with \eqn{p > n}{p > n}. } \usage{ nextprime(n) } \arguments{ \item{n}{Integer} } \details{ This function uses probabilistic algorithm to identify primes. For practical purposes, it is adequate, the chance of a composite passing will be extremely small. } \value{ A (probably) prime number } \references{The GNU MP Library, see \url{https://gmplib.org}} \author{Antoine Lucas} \seealso{ \code{\link{isprime}} and its references and examples. } \examples{ nextprime(14) ## still very fast: (p <- nextprime(1e7)) ## to be really sure { isprime() gives "probably prime" } : stopifnot(identical(p, factorize(p))) } \keyword{arith} gmp/DESCRIPTION0000755000176200001440000000245314662153602012557 0ustar liggesusersPackage: gmp Version: 0.7-5 Date: 2024-08-23 Title: Multiple Precision Arithmetic Authors@R: c(person("Antoine","Lucas",role = c("aut","cre"), email = "antoinelucas@gmail.com", comment = c(ORCID="0000-0002-8059-9767")), person("Immanuel","Scholz", role= "aut"), person("Rainer","Boehme", role = "ctb", email= "rb-gmp@reflex-studio.de"), person("Sylvain","Jasson", role = "ctb", email= "Sylvain.Jasson@inrae.fr"), person("Martin", "Maechler", role = "ctb", email="maechler@stat.math.ethz.ch")) Maintainer: Antoine Lucas Description: Multiple Precision Arithmetic (big integers and rationals, prime number tests, matrix computation), "arithmetic without limitations" using the C library GMP (GNU Multiple Precision Arithmetic). Depends: R (>= 3.5.0) Imports: methods Suggests: Rmpfr, MASS, round SystemRequirements: gmp (>= 4.2.3) License: GPL (>= 2) BuildResaveData: no LazyDataNote: not available, as we use data/*.R *and* our classes NeedsCompilation: yes URL: https://forgemia.inra.fr/sylvain.jasson/gmp Packaged: 2024-08-23 17:22:31 UTC; antoine Author: Antoine Lucas [aut, cre] (), Immanuel Scholz [aut], Rainer Boehme [ctb], Sylvain Jasson [ctb], Martin Maechler [ctb] Repository: CRAN Date/Publication: 2024-08-23 18:40:02 UTC