gmp/0000755000175000017500000000000014140302240011155 5ustar nileshnileshgmp/MD50000644000175000017500000001044114140302240011465 0ustar nileshnilesh08b673189c281130b39e36dd517e9106 *ChangeLog ebb3e86d6b9fae7939450340f88b351e *Changes 34c98914cf619b69576a457012540ac2 *DESCRIPTION 077a366c9fe40923ba402b72b1d8e901 *NAMESPACE 031eddddcfbf9c2a9bc74c83342699e5 *R/AllClasses-etc.R a6eb2430e9ce0c4c619c0176c4492020 *R/Stirling-n-etc.R 707b5c805b1a4ff20be56140838d4803 *R/biginteger.R d793f18fb2d2c0dc7647a8c863886146 *R/bigq.R 148e5baac0cbb043d07e62369301fd5a *R/matrix-prods.R 91e36fd7733ed9d24d282be854183743 *R/matrixq.R 33cae7758bad9c6510a7c4d6d5d7aa1d *R/matrixz.R 95f68ef3a6a5a0effdd2bd05bd6e91ef *R/zzz.R b5264f5e34c6b7096ed632c72b3ed2bd *TODO a8d707d0cad53cb4e52a114d1a441af8 *cleanup c3e229d4d21233ad1becdd2c3f41092b *configure 714a17bebf8eba38bee637a755466954 *configure.ac c4ff09724b77a5383751dacc935b493f *data/Oakley1.R 76f950c0330af250fae4d9c1d5b13f84 *data/Oakley2.R ad746e23b07ecef7d2262f22c121e95b *man/BernoulliQ.Rd 5f6686564ecbbe8169b01377ccb05f48 *man/Oakley.Rd 49572133013f666062fead8c5e38dbc1 *man/Stirling.Rd 43affda0d0d7a43174ce21998e49cb4e *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 5bafb403b5fecf0a94d76aad00406d44 *man/comp.biginteger.Rd 4c1e5520660a32530461f2f1f46eb665 *man/comp.bigq.Rd 5447ec49bb927b8807dfa4dbe32eaf98 *man/cumsum.Rd 0bec805ede93ce752ecb2f63ba56e8e2 *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 c2b78372c54216b70260daa432b58fa5 *man/isprime.Rd 233c553d118a6e36663ce2fa48c5cc07 *man/matrix.Rd 13ff65f59b4f53d6f504cf1d9372aac1 *man/modulus.Rd 158a7d9b7fe35cb25762c7a53205a2c1 *man/nextprime.Rd fea86d45035c626e8940d35b0fcbc374 *man/operators_bigq.Rd abafd95558517a2a0b6f8a9b4671f514 *man/powm.Rd 6188c692e3c6e7213f05b7eeb0b827b2 *man/roundQ.Rd bf889df64a7c88dace8e491e9eb67d35 *man/sizeinbase.Rd 8ff72446e3d97f374074ebaed3215503 *man/solve.Rd d8cb9c64227e9cabd609dd235eb3dd86 *man/utils.Rd 5c6982b46de9c458c9019f1df91662ee *src/Makevars.in 4df25307cd0a3d79ad9917172dba1868 *src/Makevars.win 4f6f803f0dda152d0ce87d3619b2facc *src/Rgmp.h 3b9adba4fe112898991f8381a22956ec *src/apply.cc 2f25f95aedc17f66633efad43411089a *src/apply.h eef09382dee0ff669708b1233eb030c3 *src/biginteger.cc e5bc28b18ba5b3da011147bf01ca9199 *src/biginteger.h dbcfd8961b67af720fa7fde1b2f3d064 *src/bigintegerR.cc 4ef2c01da2922ccf7811b4f6c4a97da8 *src/bigintegerR.h b94f17d3b125e4d7f15d24f4545fc4fd *src/bigmod.cc 46394c774a6bb2d90ffc10ae038a0556 *src/bigmod.h feaed23dd65918cbc042d57debe23575 *src/bigrational.cc b955bbe21614a83c5a6ac745037a90ce *src/bigrational.h c9a5b75c692d44ee5e3218c5f2db4292 *src/bigrationalR.cc ffd81aa2f88bf05b583cd3cee3ecfcfa *src/bigrationalR.h e1ec49fc0a6442772c8639c756868efd *src/bigvec.cc bf002878f8fc45c33b4af4549d00292f *src/bigvec.h bc00dbc4293e1ab6fed83a277ad20208 *src/bigvec_q.cc 6f1233b11c4fe09df1ec46a788970e58 *src/bigvec_q.h 50ff06a5ad1980f1fc0291e07e4efe7c *src/extract_matrix.cc d1690f0d155d059963ee29b0665d9f70 *src/extract_matrix.h ce3846aa109f07e4e81aac715e24f7fe *src/factor.cc c2c8803dbb6bb4aa409704e91b4ce6b5 *src/factor.h b481a12932f9dc8c11ab31c0ae0d5646 *src/factorize.cc fa4b1298454f3eab5efccd4dc82d2c78 *src/factorize.h d1fcf00956d9ef65eafe8789d4e09cd0 *src/init.cc 9a6ff68e8bbbe85fb055ce2db4997d60 *src/matrix.cc 420b233916b4a748ff0977d13c1e9cf8 *src/matrix.h 84839e01d092853989862bf26d199d7d *src/matrixq.cc e03e4a39b9275c27367fd87c3ce26c4b *src/matrixq.h 7ddf216fc7d6c1796f6eac06289eb8de *src/primes.h 47814a89e2c9c5b9f0f8ebbbcacd4e87 *src/solve.cc 424de6e67afb73e0d28ddf5c0f35bd33 *src/solve.h 18c6cd135269a0517f9ca7a587651da5 *src/templateMatrix.h 7076c656465f9b92e0278367734a2b5a *tests/arith-ex.R 514a31d717a791a7fde4a34bc783e9a4 *tests/basic-ex.R d00bb629ea5114b153e53acb4781197f *tests/gmp-test.R 605bd200f6ec1e09fa48c39214a495ef *tests/gmp-test.Rout.save gmp/DESCRIPTION0000755000175000017500000000160114140302240012664 0ustar nileshnileshPackage: gmp Version: 0.6-2.1 Date: 2021-01-07 Title: Multiple Precision Arithmetic Author: Antoine Lucas, Immanuel Scholz, Rainer Boehme , Sylvain Jasson , Martin Maechler 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: 2021-11-02 17:06:16 UTC; hornik Repository: CRAN Date/Publication: 2021-11-02 18:34:08 UTC gmp/man/0000755000175000017500000000000013735324616011754 5ustar nileshnileshgmp/man/nextprime.Rd0000644000175000017500000000137513735324616014264 0ustar nileshnilesh\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/man/extract.Rd0000644000175000017500000000431513033760377013717 0ustar nileshnilesh\name{extract} \title{Extract or Replace Parts of an Object} \alias{[.bigz} \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) ##_______ In the following, only the bigq method is mentioned: ______ %%FIXME: R-Rd bug in "rendering" this ( '[' is ok ) %%FIXME \method{[<-}{bigq}(x, i=NULL, j=NULL, value) ==> "the same", manually : %% x[i, j] <- value | But this gives ... WARNING .. Objects in \usage w/o \alias \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.} %%FIXME \item{value}{\R object, typically of same \code{\link{class}} as %%FIXME \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}{unused here} } \note{ Unlike standard matrices, \code{x[i]} and \code{x[i,]} do the same. %% MM: hmm, just because of lazyness ?? } \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 m <- matrix.bigz(1:6,3) ## these do the same: m[1,] 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/BernoulliQ.Rd0000644000175000017500000000172413735324616014323 0ustar nileshnilesh\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/isprime.Rd0000644000175000017500000000374013735324616013717 0ustar nileshnilesh\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. For example, \code{\link[sfsmisc]{primes}} in package \pkg{sfsmisc}. } \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/base-copies.Rd0000644000175000017500000000111513656207461014433 0ustar nileshnilesh\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/matrix.Rd0000644000175000017500000001175313656210065013550 0ustar nileshnilesh\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,...) ## ..... 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{...}{Not used} \item{x,y}{numeric, \code{bigz}, or \code{bigq} matrices or vectors.} } \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. } \author{Antoine Lucas} \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/biginteger.rand.Rd0000644000175000017500000000206613735324616015311 0ustar nileshnilesh\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/Stirling.Rd0000644000175000017500000000563413735324616014046 0ustar nileshnilesh\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 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/bigrational.Rd0000644000175000017500000000660713735324616014547 0ustar nileshnilesh\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/cumsum.Rd0000644000175000017500000000205413033760377013554 0ustar nileshnilesh\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/factorialZ.Rd0000644000175000017500000000233013033760377014336 0ustar nileshnilesh\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/factor.Rd0000644000175000017500000000115713735324616013525 0ustar nileshnilesh\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/formatN.Rd0000644000175000017500000000242513033760377013653 0ustar nileshnilesh\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/apply.Rd0000644000175000017500000000246313033760377013374 0ustar nileshnilesh\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/utils.Rd0000644000175000017500000000071013735324616013401 0ustar nileshnilesh\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/comp.biginteger.Rd0000644000175000017500000000120713033760377015316 0ustar nileshnilesh\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/sizeinbase.Rd0000644000175000017500000000147113735324616014402 0ustar nileshnilesh\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.Rd0000644000175000017500000000256713033760377013532 0ustar nileshnilesh\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/Oakley.Rd0000644000175000017500000000172713604426245013472 0ustar nileshnilesh\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/gcdex.Rd0000644000175000017500000000132113735324616013332 0ustar nileshnilesh\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/is.whole.Rd0000644000175000017500000000210313033760377013766 0ustar nileshnilesh\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/gcd.Rd0000644000175000017500000000212613735324616013001 0ustar nileshnilesh\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/add.biginteger.Rd0000644000175000017500000000721013735324616015111 0ustar nileshnilesh\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/fibonacci.Rd0000644000175000017500000000137713735324616014170 0ustar nileshnilesh\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/modulus.Rd0000644000175000017500000000173613033760377013741 0ustar nileshnilesh\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/comp.bigq.Rd0000644000175000017500000000110713033760377014120 0ustar nileshnilesh\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/solve.Rd0000644000175000017500000000301413033760377013370 0ustar nileshnilesh\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/powm.Rd0000644000175000017500000000140513033760377013224 0ustar nileshnilesh\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/operators_bigq.Rd0000644000175000017500000000230513433723441015255 0ustar nileshnilesh\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/roundQ.Rd0000644000175000017500000000605613735324616013522 0ustar nileshnilesh\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/asNumeric.Rd0000644000175000017500000000327713033760377014201 0ustar nileshnilesh\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/biginteger.Rd0000644000175000017500000001521213735324616014363 0ustar nileshnilesh\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/extreme.Rd0000644000175000017500000000320213735324616013711 0ustar nileshnilesh\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/src/0000755000175000017500000000000013775603060011765 5ustar nileshnileshgmp/src/bigmod.h0000644000175000017500000001637313667642073013420 0ustar nileshnilesh/*! \file bigmod.h * \brief Description of class bigmod * * \date Created: 22/05/06 * \date Last modified: Time-stamp: <2019-03-10 10:30:30 (antoine)> * * \author Immanuel Scholz * * \note Licence: GPL (>= 2) */ #ifndef BIGMOD_HEADER_ #define BIGMOD_HEADER_ 1 #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: /** optional source */ biginteger * value_ptr; biginteger * modulus_ptr; protected: /** \brief Value of our bigmod -- only references*/ biginteger & value; /** \brief modulus of our bigmod representation: value %% modulus */ biginteger & modulus; public: /** keep both references value / modulus */ bigmod(biginteger& value_, biginteger& modulus_) : value_ptr(NULL), modulus_ptr(NULL), value(value_),modulus(modulus_) {}; /** keep references value / modulus is new object. */ bigmod(biginteger& value_) : value_ptr(NULL), modulus_ptr(new biginteger()), value(value_),modulus(*modulus_ptr) {}; /** * create 2 new objects valus / modulus. */ bigmod(const biginteger& value_, const biginteger& modulus_) : value_ptr(new biginteger(value_)), modulus_ptr(new biginteger(modulus_)), value(*value_ptr),modulus(*modulus_ptr) {}; bigmod(const biginteger& value_) : value_ptr(new biginteger(value_)), modulus_ptr(new biginteger()), value(*value_ptr),modulus(*modulus_ptr) {}; bigmod() : value_ptr(new biginteger()), modulus_ptr(new biginteger()), value(*value_ptr),modulus(*modulus_ptr) {}; /** \brief copy operator */ bigmod(const bigmod & rhs) : value_ptr(new biginteger(rhs.getValue())), modulus_ptr(new biginteger(rhs.getModulus())), value(*value_ptr),modulus(*modulus_ptr) { }; virtual ~bigmod(){ if(value_ptr != NULL) delete value_ptr; if(modulus_ptr != NULL) delete modulus_ptr; }; /** * \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; biginteger & getValue() { return value; } biginteger & getModulus() { return modulus; } const biginteger & getValue() const{ return value; } const biginteger & getModulus() const { return modulus; } }; class DefaultBigMod : public bigmod { private: /** \brief Value of our bigmod */ biginteger valueLocal; /** \brief modulus of our bigmod representation: value %% modulus */ biginteger modulusLocal; public: /** \brief creator */ DefaultBigMod(const biginteger& value_ = biginteger(), const biginteger& modulus_ = biginteger()) : bigmod(valueLocal,modulusLocal), valueLocal(value_),modulusLocal(modulus_) { value = valueLocal; modulus = modulusLocal; } /** \brief copy operator */ DefaultBigMod(const bigmod & rhs) : bigmod(valueLocal,modulusLocal), valueLocal(rhs.getValue()),modulusLocal(rhs.getModulus()) { value = valueLocal; modulus = modulusLocal; } /** \brief copy operator */ DefaultBigMod(const DefaultBigMod & rhs) : bigmod(valueLocal,modulusLocal), valueLocal(rhs.getValue()),modulusLocal(rhs.getModulus()) { value = valueLocal; modulus = modulusLocal; } ~DefaultBigMod(){}; }; /** * a bigmod that has only integer. */ class BigModInt : public bigmod { private: /** \brief modulus of our bigmod representation */ biginteger modulusLocal; public: /** \brief creator */ BigModInt(biginteger& value_) : bigmod(value_,modulusLocal), modulusLocal() { modulus = modulusLocal; } ~BigModInt(){}; }; /** \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. */ DefaultBigMod operator+(const bigmod& rhs, const bigmod& lhs); /** * \brief Subtract two bigmods. * * For modulus description, see operator+(bigmod, bigmod) */ DefaultBigMod operator-(const bigmod& rhs, const bigmod& lhs); /** * \brief Multiply two bigmods. * * For modulus description, see operator+(bigmod, bigmod) */ DefaultBigMod operator*(const bigmod& rhs, const bigmod& lhs); /** * \brief Divide two bigmods a / b := a * b^(-1) */ DefaultBigMod div_via_inv(const bigmod& a, const bigmod& b); /** * \brief Divide two bigmods. * * For modulus description, see operator+(bigmod, bigmod) */ DefaultBigMod 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. */ DefaultBigMod 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) */ DefaultBigMod 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) */ DefaultBigMod 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). */ DefaultBigMod 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) */ DefaultBigMod gcd(const bigmod& rhs, const bigmod& lhs); /** * \brief Return the least common multiply of both parameter. * * For modulus description, see operator+(bigmod, bigmod) */ DefaultBigMod lcm(const bigmod& rhs, const bigmod& lhs); /** * \brief function used to make any binary operation between * two bigmod that return a bigmod (addition substraction... ) */ DefaultBigMod create_bigmod(const bigmod& lhs, const bigmod& rhs, gmp_binary f, bool zeroRhsAllowed = true) ; #endif gmp/src/init.cc0000644000175000017500000000763713654725536013265 0ustar nileshnilesh// This ensures registration -- see also useDynLib(...) in ../NAMESPACE #include #include // include those that have an extern "C" { .... } : #include "apply.h" #include "bigintegerR.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/bigmod.cc0000644000175000017500000002242513654725536013553 0ustar nileshnilesh #include "bigmod.h" #define DEBUG_bigmod #undef DEBUG_bigmod #ifdef DEBUG_bigmod #include #endif // for GetOption etc: #include #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.setValue( rhs.getModulus() ); value.setValue(rhs.value ); } 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)) warning(_("inv(x) returning NA as x has no inverse")); return bigmod(); // return NA; was } return bigmod(val, modulus); } 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); return(!(rhs.getModulus() != lhs.getModulus())); } DefaultBigMod operator+(const bigmod& lhs, const bigmod& rhs) { return create_bigmod(lhs, rhs, mpz_add); } DefaultBigMod operator-(const bigmod& lhs, const bigmod& rhs) { return create_bigmod(lhs, rhs, mpz_sub); } DefaultBigMod 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() */ DefaultBigMod div_via_inv(const bigmod& a, const bigmod& b) { // compute a/b as a * b^(-1) return operator*(a, pow(b, DefaultBigMod(-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() */ DefaultBigMod operator/(const bigmod& lhs, const bigmod& rhs) { return create_bigmod(lhs, rhs, integer_div, false); } DefaultBigMod operator%(const bigmod& lhs, const bigmod& rhs) { if (lhs.getValue().isNA() || rhs.getValue().isNA()) return DefaultBigMod(); if (mpz_sgn(rhs.getValue().getValueTemp()) == 0) { warning(_("biginteger division by zero: returning NA")); return DefaultBigMod(); } 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 DefaultBigMod(val, mod); } // Either 'base' has a modulus, or it has not *and* exp >= 0 : DefaultBigMod 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 DefaultBigMod(biginteger(1)); if (base.getValue().isNA() || exp.getValue().isNA()) return DefaultBigMod(); 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) error(_("** internal error (negative powers for Z/nZ), please report!")); if (!mpz_fits_ulong_p(exp.getValue().getValueTemp())) error(_("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)) warning(_("pow(x, -|n|) returning NA as x has no inverse wrt modulus")); return(DefaultBigMod()); // return NA; was } // else: val = x^(-1) already: ==> result = val ^ |exp| = val ^ (-exp) : // nExp := - exp mpz_t nExp; mpz_init(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 DefaultBigMod(val, mod); } DefaultBigMod inv(const bigmod& x, const bigmod& m) { if (x.getValue().isNA() || m.getValue().isNA()) return DefaultBigMod(); 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) warning(_("inv(0) returning NA")); return DefaultBigMod(); } 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) warning(_("inv(x,m) returning NA as x has no inverse modulo m")); return(DefaultBigMod()); // return NA; was } return DefaultBigMod(val, mod); } // R as.bigz() : DefaultBigMod set_modulus(const bigmod& x, const bigmod& m) { if (!m.getValue().isNA() && mpz_sgn(m.getValue().getValueTemp()) == 0) error(_("modulus 0 is invalid")); // if (!m.getValue().isNA() && mpz_cmp(x.getValue().getValueTemp(),m.getValue().getValueTemp())>=0) { if (!m.getValue().isNA() ) { DefaultBigMod t(x%m); return DefaultBigMod(t.getValue(), m.getValue()); } else return DefaultBigMod(x.getValue(), m.getValue()); } DefaultBigMod gcd(const bigmod& lhs, const bigmod& rhs) { return create_bigmod(lhs, rhs, mpz_gcd); } DefaultBigMod 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)) 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 DefaultBigMod create_bigmod(const bigmod& lhs, const bigmod& rhs, gmp_binary f, bool zeroRhsAllowed) { if (lhs.getValue().isNA() || rhs.getValue().isNA()) return DefaultBigMod(); if (!zeroRhsAllowed && mpz_sgn(rhs.getValue().getValueTemp()) == 0) { warning(_("returning NA for (modulus) 0 in RHS")); return DefaultBigMod(); } 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 DefaultBigMod(val, mod); } gmp/src/factor.h0000644000175000017500000000175313667642073013431 0ustar nileshnilesh/*! \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/bigvec_q.h0000644000175000017500000000472513667642073013734 0ustar nileshnilesh/*! \file bigve_cq.h * \brief bigvec_q class definition * * \version 1 * * \date Created: 2005 * \date Last modified: Time-stamp: <2006-06-16 20:19:01 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); /** * \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/Makevars.win0000644000175000017500000000012713654725536014266 0ustar nileshnilesh PKG_LIBS = -lgmp # need C++11 for long long (not yet the default): CXX_STD = CXX11 gmp/src/primes.h0000644000175000017500000010111413654725536013444 0ustar nileshnileshP( 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/Makevars.in0000644000175000017500000000006213654725536014075 0ustar nileshnileshPKG_CPPFLAGS=@PKG_CPPFLAGS@ PKG_LIBS=@PKG_LIBS@ gmp/src/solve.h0000644000175000017500000000342613735324616013276 0ustar nileshnilesh/*! \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 "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 ) Rf_error("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/templateMatrix.h0000644000175000017500000000456313735324616015151 0ustar nileshnilesh#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; }; 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; /** * \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(); } 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{ return this->size() / nRows(); } } #endif gmp/src/bigrationalR.h0000644000175000017500000001140413667642073014562 0ustar nileshnilesh/*! \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: <2010-04-10 19:27:44 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 for function cbind */ SEXP bigrational_cbind(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_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/biginteger.cc0000644000175000017500000001074713667642073014433 0ustar nileshnilesh/*! \file biginteger.cc * \brief C function for class biginteger & bigmod * * \version 1 * * \date Created: 27/10/04 * \date Last modified: Time-stamp: <2008-02-17 21:42:37 antoine> * * \author Immanuel Scholz * * \note Licence: GPL (>= 2) */ #define USE_RINTERNALS #define R_NO_REMAP // avoid collisions with stl definitions #include "biginteger.h" #include #include #include using std::string; biginteger::biginteger(const char* raw) { 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) { 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/bigvec.cc0000644000175000017500000001463513735324616013547 0ustar nileshnilesh #include "bigvec.h" /** \brief constructor * */ bigvec::bigvec(unsigned int i) : math::Matrix(), value(i), modulus(0), valuesMod(), nrow(-1) { } bigvec::bigvec(const bigvec & vecteur) : math::Matrix(), value(vecteur.value.size()), modulus(vecteur.modulus.size()), valuesMod(), nrow(vecteur.nrow) { // *this = vecteur; value.resize(vecteur.value.size()); modulus.resize(vecteur.modulus.size()); std::vector::const_iterator jt=vecteur.modulus.begin(); std::vector::iterator it = modulus.begin(); while(it != modulus.end()) { *it = *jt; ++it; ++jt; } jt = vecteur.value.begin(); for(it=value.begin(); it != value.end(); ++it) { *it= *jt; ++jt; } } bigvec::~bigvec(){ clearValuesMod(); } // std::string bigvec::str(int i,int b) const { if (value[i].isNA()) return ("NA"); std::string s; // sstream seems to collide with libgmp :-( bool onemodulus = modulus.size()>0; if(onemodulus) onemodulus = !modulus[i%modulus.size()].isNA() ; if (onemodulus) s = "("; s += value[i].str(b); if (onemodulus) { s += " %% "; s += modulus[i%modulus.size()].str(b); s += ")"; } return s; } bigmod & bigvec::get(unsigned int row, unsigned int col) { return (*this)[row + col*nrow]; } bigmod & bigvec::operator[] (unsigned int i) { checkValuesMod(); return *valuesMod[i]; } const bigmod & bigvec::operator[] (unsigned int i) const { bigvec * nonConst = const_cast(this); nonConst->checkValuesMod(); return *valuesMod[i]; } void bigvec::set(unsigned int row, unsigned int col, const bigmod & val) { set( row + col*nrow,val); } void bigvec::checkValuesMod() { if (valuesMod.size() != value.size()){ // reconstruct bigmod that are references to values and modulus: clearValuesMod(); if(modulus.size()>0) { for (unsigned int i = 0 ; i < value.size(); i++) valuesMod.push_back(new bigmod(value[i], modulus[i%modulus.size()])); } else { for (unsigned int i= 0 ; i < value.size(); i++) valuesMod.push_back(new BigModInt(value[i])); } } } void bigvec::clearValuesMod(){ for (unsigned int i = 0 ; i < valuesMod.size(); i++){ delete valuesMod[i]; } valuesMod.clear(); } void bigvec::set(unsigned int i,const bigmod & val) { value[i] = val.getValue(); if(!val.getModulus().isNA()) { if(modulus.size()> i) { modulus[i] = val.getModulus() ; return; } unsigned int nrow_mod = nrow; if(nrow<1) nrow_mod = 1; if( (modulus.size() == (unsigned int)nrow_mod ) || (modulus.size() == 1) ) { // check "row-mod" or "global" modulus if(!(val.getModulus() != modulus[i % modulus.size()])) { return; } } // we add "previous" nrow_mod = modulus.size(); for(unsigned int j = nrow_mod; j< i;++j) modulus.push_back(modulus[j % nrow_mod]); modulus.push_back(val.getModulus()); clearValuesMod(); } } void bigvec::push_back(const bigmod & number) { unsigned int nrow_mod = (nrow < 0) ? 1 : nrow; clearValuesMod(); value.push_back(number.getValue()); if((!number.getModulus().isNA()) || (modulus.size()>0) ) { // pathologic case: value.size >0 ; modulus.size =0 // we assume previous mod where NA if((modulus.size() ==0) && (value.size()>0)) { modulus.resize(value.size()-1); modulus.push_back( number.getModulus()); return; } // standard cas if((modulus.size() != 1 ) && (modulus.size() != nrow_mod)) { modulus.push_back(number.getModulus()); return; } // pathologic case: // value modulus [nrow=4] // 2 2 push_back: ok // 2 2 push_back: nothing // 2 1 push_back: shoud add previous modulus then 1 // note nrow_mod is either 1 ither nrow (when nrow >1) nrow_mod = modulus.size(); if(modulus[(value.size() -1)% nrow_mod ] != number.getModulus()) { // we add "previous" for(unsigned int i = nrow_mod; i< value.size()-1;i++) modulus.push_back(modulus[i % nrow_mod]); modulus.push_back(number.getModulus()); } } } /** * insert int value */ void bigvec::push_back(int value_p) { clearValuesMod(); value.push_back(biginteger(value_p)); } /** * insert int value */ void bigvec::push_back(biginteger & value_p) { clearValuesMod(); value.push_back(value_p); } /** * Insert Big Integer value */ void bigvec::push_back(const __mpz_struct * value_p) { clearValuesMod(); value.push_back(biginteger(value_p)); } // return size of value unsigned int bigvec::size() const { return(value.size()); } unsigned int bigvec::nRows() const { return abs(nrow); } // hummm. to avoid ! void bigvec::resize(unsigned int i) { clearValuesMod(); value.resize(i); if(i < modulus.size()) modulus.resize(i); } // clear all void bigvec::clear() { clearValuesMod(); value.clear(); modulus.clear(); nrow = -1; } // assignment operator bigvec & bigvec::operator= (const bigvec & rhs) { if(this != &rhs) { value.resize(rhs.value.size()); modulus.resize(rhs.modulus.size()); std::vector::const_iterator jt=rhs.modulus.begin(); std::vector::iterator it = modulus.begin(); while(it != modulus.end()) { *it = *jt; ++it; ++jt; } jt = rhs.value.begin(); for(it=value.begin(); it != value.end(); ++it) { *it= *jt; ++jt; } nrow = rhs.nrow; } return(*this); } // Comparison operator bool operator!=(const bigvec & rhs, const bigvec& lhs) { std::vector::const_iterator it = rhs.value.begin(); std::vector::const_iterator jt = lhs.value.begin(); if( (rhs.value.size() != lhs.value.size()) || \ (rhs.nrow != lhs.nrow ) ) return(false); // check value while(it != rhs.value.end()) { if(*it != *jt) return(false); it++; jt++; } for(unsigned int i=0; i < std::max( rhs.modulus.size() ,lhs.modulus.size() ); ++i) if(rhs.modulus[i % rhs.modulus.size()] != \ lhs.modulus[i % lhs.modulus.size()] ) 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 < (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/solve.cc0000644000175000017500000000555113667642073013441 0ustar nileshnilesh/*! \file solve.cc * \brief functions to solve matrix * * \version 1 * * \date Created: 25/05/06 * \date Last modified: Time-stamp: <2006-05-25 23:05:20 antoine> * * \author A. Lucas * * \note Licence: GPL (>= 2) */ #include "solve.h" #include "bigrationalR.h" #include "bigintegerR.h" // inverse a rational matrix SEXP inverse_q(SEXP A) { bigvec_q a = bigrationalR::create_bignum(A); return(solve_gmp_R::inverse_q(a)); } SEXP solve_gmp_R::inverse_q(bigvec_q a) { if(a.nrow * a.nrow != (int) a.size()) error(_("Argument 1 must be a square matrix")); bigvec_q b (a.size()); b.nrow = a.nrow; // initialize b to identity for(int i=0; i1) common_modulus = false; // -> solve with rational if(b.modulus.size() == 1) { if(b.modulus[0] == a.modulus[0]) common_modulus = false; // -> solve with rational } else b.modulus.push_back(a.modulus[0]); // solve in Z/nZ if(common_modulus) { // case: b a vector if(b.nrow<1) b.nrow = b.size(); if(a.nrow * a.nrow != (int) a.size()) error(_("Argument 1 must be a square matrix")); if(a.nrow != b.nrow) error(_("Dimensions do not match")); solve_gmp_R::solve(a,b); return(bigintegerR::create_SEXP(b)); } } bigvec_q aq (a); bigvec_q bq (b); return(solve_gmp_R::solve_q(aq,bq)); } // solve AX=B SEXP solve_q(SEXP A,SEXP B) { bigvec_q a = bigrationalR::create_bignum(A); bigvec_q b = bigrationalR::create_bignum(B); return(solve_gmp_R::solve_q(a,b)); } // solve AX = B SEXP solve_gmp_R::solve_q(bigvec_q a, bigvec_q b) { if(a.nrow * a.nrow != (int) a.size()) error(_("Argument 1 must be a square matrix")); // case: b a vector if(b.nrow<0) b.nrow = b.size(); if(a.nrow != b.nrow) error(_("Dimensions do not match")); solve_gmp_R::solve(a,b); return(bigrationalR::create_SEXP(b)); } gmp/src/bigvec.h0000644000175000017500000000537113667642073013412 0ustar nileshnilesh/*! \file bigvec.h * \brief bigvec class definition * * \version 1 * * \date Created: 2005 * \date Last modified: Time-stamp: <2013-06-08 22:27:37 antoine> * * * \note Licence: GPL (>= 2) */ #ifndef BIGVEC_HEADER_ #define BIGVEC_HEADER_ 1 #include "bigmod.h" #include "templateMatrix.h" #include /** \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 { public: /** \brief value */ std::vector value; /** \brief modulus */ std::vector modulus; /** array with all bigmod, that are references to values in vector. */ std::vector valuesMod; /** \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); /** * 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(); private: void checkValuesMod() ; void clearValuesMod() ; }; // /** \brief comparison operator */ bool operator!= (const bigvec& rhs, const bigvec& lhs); #endif gmp/src/matrixq.cc0000644000175000017500000002523513667642073013777 0ustar nileshnilesh/************************************************************/ /*! \file matrixq.cc * \brief C++ function to add matrix support * * \version 1 * * \date Created: 19/02/06 * \date Last modified: Time-stamp: <2008-02-17 19:54:11 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 "bigintegerR.h" #include "matrixq.h" // function called by matrix.bigz() SEXP as_matrixq (SEXP x, SEXP nrR, SEXP ncR, SEXP byrowR, SEXP den) { /* 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 */ error(_("matrix: invalid 'nrow' value (too large or NA)")); if (nr < 0) error(_("matrix: invalid 'nrow' value (< 0)")); if (nc < 0) error(_("matrix: invalid 'ncol' value (< 0)")); if (nc == NA_INTEGER) error(_("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)) 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)) 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)){ 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, nc,nr); mat2.nrow = nr; return( bigrationalR::create_SEXP (mat2)); } return( bigrationalR::create_SEXP (mat)); } // function called by t(m) when m is a bigrational SEXP bigq_transposeR(SEXP x) { 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 { error(_("argument must be a matrix of class \"bigq\"")); nr = -1;// -Wall } int nc = (int) n / nr; bigvec_q mat_transp = matrixq::bigq_transpose(mat, nr,nc); mat_transp.nrow = nc; // FIXME - needed ? UNPROTECT(2); return( bigrationalR::create_SEXP( mat_transp)); } /* \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) { 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.. 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(int i=0; i < m; 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(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); return( bigrationalR::create_SEXP (res)); } // 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) { 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() ) error(_("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 { error(_("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)); } // matrix_mul_q() #undef K_LOOP SEXP bigrational_rbind(SEXP args) { int i=0,j=0; bigvec_q result; bigvec_q v; result = bigrationalR::create_bignum(VECTOR_ELT(args,0)); if(result.nrow ==0) result.nrow = result.size(); result = matrixq::bigq_transpose(result, result.nrow, result.size() / result.nrow); for(i=1; i< LENGTH(args); i++) { v = bigrationalR::create_bignum(VECTOR_ELT(args,i)); if(v.nrow == 0 ) v.nrow = v.size(); v = matrixq::bigq_transpose(v,v.nrow,v.size() / v.nrow); for(j=0; j< (int)v.size(); j++) result.push_back(v[j]); v.clear(); } result = matrixq::bigq_transpose(result, result.nrow, result.size() / result.nrow); return bigrationalR::create_SEXP(result); } bigvec_q matrixq::bigq_transpose (const bigvec_q & mat,int nr,int nc) { int i,j; bigvec_q matbis (nr * nc); matbis.nrow = nc; /* we compute transpose */ for(i=0; i < nr; i++) for(j=0; j < nc; j++) matbis.value[j+i*nc].setValue(mat.value[i+j*nr]); return(matbis); } gmp/src/matrix.cc0000644000175000017500000003206213667642073013612 0ustar nileshnilesh/************************************************************/ /*! \file matrix.cc * \brief C++ function to add matrix support * * \version 1 * * \date Created: 19/02/06 * \date Last modified: Time-stamp: <2006-06-17 23:10:44 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 using namespace std; #include "Rgmp.h" #include "biginteger.h" #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) { 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.value.size(); // int sizemod = mat.modulus.size(); // when modulus specified bigvec modulus = bigintegerR::create_bignum(mod); if(modulus.value.size()>0) // should be allways the case if(!modulus.value[0].isNA()) { mat.modulus.resize(modulus.size()); for (unsigned int i = 0; i < modulus.size(); i++) mat.modulus[i] = modulus.value[i]; // sizemod = modulus.size(); } // A copy from R project to get correct dimension // all warnings... // if (nr == NA_INTEGER) // This is < 0 error(_("matrix: invalid 'nrow' value (too large or NA)")); if (nr < 0) error(_("matrix: invalid 'nrow' value (< 0)")); if (nc < 0) error(_("matrix: invalid 'ncol' value (< 0)")); if (nc == NA_INTEGER) error(_("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)) 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)) 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)){ 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 mat2 = matrixz::bigint_transpose (mat, nc,nr); mat2.nrow = nr;// FIXME - needed ?? return( bigintegerR::create_SEXP (mat2)); } return( bigintegerR::create_SEXP (mat)); } /* * Transposition */ SEXP bigint_transposeR(SEXP x) { 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 error(_("argument must be a matrix of class \"bigz\"")); } UNPROTECT(2); int nc = (int) n / nr; // Rprintf(" o bigI_tr(<%d x %d>) ..\n", nr,nc); return( bigintegerR::create_SEXP(matrixz::bigint_transpose(mat, nr,nc))); } /* \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) { bool useMod = FALSE, tr = (bool)Rf_asLogical(trans); bigvec mat_a = bigintegerR::create_bignum(a); int sizemod = mat_a.modulus.size(), 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) { // maybe 'useMod' i.e., can use common modulus: if(sizemod == 1) { mpz_set(common_modulus, mat_a.modulus[0].getValueTemp()); if(!mat_a.modulus[0].isNA()) 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.value [ i + k *a_nrow] #define B_K_J mat_a.value [ j + k *a_nrow] K_LOOP #undef A_I_K #undef B_K_J } else {//------------- crossprod --------------------------- #define A_I_K mat_a.value [ k + i *a_nrow] #define B_K_J mat_a.value [ 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); } // for(i ..) for(j ..) if(useMod) res.modulus.push_back(biginteger(common_modulus)); mpz_clear(R_ij); mpz_clear(tt); mpz_clear(common_modulus); return( bigintegerR::create_SEXP (res)); } // 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) { 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 sizemod_a = mat_a.modulus.size(), sizemod_b = mat_b.modulus.size(); 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() ) error(_("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 { error(_("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 */ if( !(sizemod_a > 1 || sizemod_b > 1)) { if((sizemod_a == 1) && (sizemod_b == 1)) { mpz_set(common_modulus, mat_a.modulus[0].getValueTemp()); if(mpz_cmp(common_modulus, mat_b.modulus[0].getValueTemp()) == 0 && !mat_a.modulus[0].isNA()) useMod = TRUE; } else { // at least one of the sizemod_* is > 1 : if ((sizemod_a == 1) && !mat_a.modulus[0].isNA()) { mpz_set(common_modulus, mat_a[0].getModulus().getValueTemp()); useMod = TRUE; } else if ((sizemod_b == 1) && !mat_b.modulus[0].isNA()) { mpz_set(common_modulus, mat_b[0].getModulus().getValueTemp()); useMod = TRUE; } } } // bigmod tmp; // here the computation: for(int i=0; i < n; i++) for(int j=0; j < m; j++) { #define R_IJ res.value[ 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.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.value [ i + k *a_nrow] #define B_K_J mat_b.value [ 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.value [ k + i *a_nrow] #define B_K_J mat_b.value [ k + j *b_nrow] K_LOOP #undef A_I_K #undef B_K_J } else {//(o_ == 2) ------------- tcrossprod --------------------------- #define A_I_K mat_a.value [ i + k *a_nrow] #define B_K_J mat_b.value [ j + k *b_nrow] K_LOOP #undef A_I_K #undef B_K_J } } if(useMod) res.modulus.push_back(biginteger(common_modulus)); mpz_clear(tt); mpz_clear(common_modulus); return( bigintegerR::create_SEXP (res)); } // matrix_mul_z() #undef R_IJ #undef K_LOOP SEXP biginteger_rbind(SEXP args) { int i=0,j=0; bigvec result; bigvec v; result = bigintegerR::create_bignum(VECTOR_ELT(args,0)); if(result.nrow==0) result.nrow = result.size(); result = matrixz::bigint_transpose(result, result.nrow, result.size() / result.nrow); for(i=1; i < LENGTH(args); i++) { v = bigintegerR::create_bignum(VECTOR_ELT(args,i)); if(v.nrow == 0 ) v.nrow = v.size(); v = matrixz::bigint_transpose(v,v.nrow,v.size() / v.nrow); for(j=0; j< (int)v.size(); j++) result.push_back(v[j]); v.clear(); } result = matrixz::bigint_transpose(result, result.nrow, result.size() / result.nrow); return bigintegerR::create_SEXP(result); } namespace matrixz { bigvec bigint_transpose ( bigvec & mat,int nr,int nc) { int i,j; /* cas: square matrix */ bigvec matbis (nr * nc); matbis.nrow = nc; /* we compute transpose */ for(i =0; i 0 && dimb > 0) { if (dimb != dima) error(_("Matrix dimensions do not match")); } else { /* either a or b is a matrix */ if(dima == -1) return(dimb); } return(dima); } } gmp/src/bigintegerR.cc0000644000175000017500000011056113667642073014550 0ustar nileshnilesh/************************************************************/ /*! \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 "Rgmp.h" #include "bigintegerR.h" // only for ^ -|n| : #include "bigrationalR.h" #include "matrix.h" #include #include using namespace std; #include /* 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.value.resize(sizevec); for (int i = 0; i < sizevec; ++i) { v.value[i] = biginteger(&raw[pos]); pos += v.value[i].raw_size(); // increment number of bytes read. } return v; } case REALSXP: { double* d = REAL(param); //bigvec v(d,d+LENGTH(param)); bigvec v; v.value.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.value[j] = 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 mpz_ui_pow_ui (LARGE, (unsigned long int) 2, (unsigned long int) 8000); if(dj == R_PosInf) v.value[j] = LARGE; else if(dj == R_NegInf) { mpz_t neg_L; mpz_init(neg_L); mpz_neg(neg_L, LARGE); v.value[j] = neg_L; mpz_clear(neg_L); } else// should never happen v.value[j] = dj; mpz_clear(LARGE); } } return v; } case INTSXP: case LGLSXP: { int* i = INTEGER(param); //bigvec v(i,i+LENGTH(param)); bigvec v; v.value.resize(LENGTH(param)); for (int j = 0; j < LENGTH(param); ++j) v.value[j] = i[j]; return v; } case STRSXP: { bigvec v; v.value.resize(LENGTH(param)); for (int i = 0; i < LENGTH(param); ++i) { if (STRING_ELT(param,i) == NA_STRING) v.value[i]= biginteger(); else v.value[i]=biginteger(std::string(CHAR(STRING_ELT(param,i)))); } return v; } default: // no longer: can be fatal later! return bigvec(); error(_("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; v.modulus = bigintegerR::create_vector(modAttr).value; } 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; v.reserve(LENGTH(param)); 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 std::vector& v) { unsigned int i; int size = sizeof(int); // starting with vector-size-header for (i = 0; i < v.size(); ++i) size += v[i].raw_size(); // adding each bigint's needed size SEXP ans = PROTECT(Rf_allocVector(RAWSXP, size)); // Rprintf(" o create_SEXP(vect): size=%d, v.size()=%d\n", size, v.size()); char* r = (char*)(RAW(ans)); ((int*)(r))[0] = v.size(); // first int is vector-size-header int pos = sizeof(int); // current position in r[] (starting after vector-size-header) for (i = 0; i < v.size(); ++i) pos += v[i].as_raw(&r[pos]); UNPROTECT(1); return(ans); } SEXP create_SEXP(const bigvec& v) { SEXP ans = PROTECT(create_SEXP(v.value)); // 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.modulus.size() > 0) { SEXP mod = PROTECT(create_SEXP(v.modulus)); // 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; } /** * \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) { bigvec va = bigintegerR::create_bignum(a); bigvec vb = bigintegerR::create_bignum(b), result; int size = (va.value.empty() || vb.value.empty()) ? 0 : max(va.value.size(), vb.value.size()); result.value.reserve(size); for (int i = 0; i < size; ++i) result.push_back(f(va[i%va.size()], vb[i%vb.size()])); result.nrow = matrixz::checkDims(va.nrow,vb.nrow); // Rprintf(" o bigI_b_op(.); size=%d -> nrow=%d\n", size, result.nrow); return bigintegerR::create_SEXP(result); } SEXP biginteger_logical_binary_operation(const SEXP & a,const SEXP & b, biginteger_logical_binary_fn f) { bigvec va = bigintegerR::create_bignum(a); bigvec vb = bigintegerR::create_bignum(b), result; int size = (va.value.empty() || vb.value.empty()) ? 0 : max(va.value.size(), vb.value.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.value[i % va.value.size()]; biginteger bm = vb.value[i % vb.value.size()]; if (am.isNA() || bm.isNA()) r[i] = NA_LOGICAL; else r[i] = f(am, bm) ? 1 : 0; } int nrow = matrixz::checkDims(va.nrow,vb.nrow) ; // 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; } 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 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) int len_m_a = A.modulus.size(), len_m_b = B.modulus.size(); if(len_m_a == 0 && len_m_b == 0) // deal with important case quickly: return bigrational_div(a, b); else if(len_m_a == 0) { // and len_m_b > 0: // should work directly using b's "mod" --> compute a * b^(-1) } else if(len_m_b == 0) { // and len_m_a > 0: // should use a's "mod" for b: div_via_inv() need's b's modulus B.modulus = A.modulus; return bigintegerR::biginteger_binary_operation(a, bigintegerR::create_SEXP(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)? int m = (len_m_a < len_m_b) ? len_m_b : len_m_a; // = max(l..a, l..b) for(int i = 0; i < m; i++) if(A.modulus[i % len_m_a] != B.modulus[i % len_m_b]) { 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): return bigrational_div(a, b); } } return bigintegerR::biginteger_binary_operation(a,b, div_via_inv); } SEXP biginteger_pow (SEXP a, SEXP b) { bigvec v = bigintegerR::create_bignum(a), exp = bigintegerR::create_bignum(b); if(v.modulus.size() == 0) { /* 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.value.size(); ++i) { if(mpz_sgn(exp.value[i].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 } 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) { bigvec v = bigintegerR::create_bignum(a); SEXP ans; int base = Rf_asInteger(b); if (base < 2 || base > 36) error(_("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.value.size() / v.nrow; Rf_setAttrib(ans, Rf_mkString("dim"), dim); UNPROTECT(1); } UNPROTECT(1); return ans; } SEXP biginteger_as_numeric(SEXP a) { 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.value[i].isNA() ? NA_REAL : v.value[i].as_double(); UNPROTECT(1); return ans; } SEXP biginteger_as_integer(SEXP a) { 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.value[i].isNA()) { r[i] = NA_INTEGER; } else if(!mpz_fits_slong_p(v.value[i].getValueTemp())) { Rf_warning("NAs introduced by coercion from big integer"); r[i] = NA_INTEGER; } else { r[i] = mpz_get_si(v.value[i].getValueTemp()); } } UNPROTECT(1); return ans; } SEXP biginteger_get_at(SEXP a, SEXP i) { //result = a [i] bigvec va = bigintegerR::create_bignum(a); return(bigintegerR::create_SEXP(bigintegerR::biginteger_get_at_C(va,i))); } // also called from matrix_get_at_z(.) in ./extract_matrix.cc : bigvec bigintegerR::biginteger_get_at_C(bigvec va, SEXP ind) { vector v_ind = bigintegerR::create_int(ind); bigvec result; // logical: ind = true/false if (TYPEOF(ind) == LGLSXP) { for (unsigned int i = 0; i < va.size(); ++i) if (v_ind[i%v_ind.size()]) { //std::cout << "cas LOGIC "<< std::endl; result.push_back(va[i]); } return result; } else { std::remove(v_ind.begin(), v_ind.end(), 0); // remove all zeroes from ind if (v_ind.empty()) return bigvec(); // case: a[-ind] if (v_ind[0] < 0) { //std::cout << "cas ngatif" << std::cout; for (vector::iterator it = v_ind.begin(); it != v_ind.end(); ++it) if (*it > 0) error(_("only 0's may mix with negative subscripts")); else if (-(*it)-1 >= (int)va.size()) error(_("subscript out of bounds")); // TODO: This is optimized for large va.size and small v_ind.size. // Maybe add a condition to use a different approach for large v_ind's result.value.reserve(va.size()-v_ind.size()); for (int i = 0; i < (int)va.size(); ++i) if (find(v_ind.begin(), v_ind.end(), -i-1) == v_ind.end()) { result.push_back(va[i]); } } else { // standard case: a[ind] with ind: integers result.value.reserve(v_ind.size()); for (vector::iterator it = v_ind.begin(); it != v_ind.end(); ++it) { if (*it <= 0) error(_("only 0's may mix with negative subscripts")); if (*it <= (int)va.size()) { //std::cout << "on sort " << va.value[(*it)-1].str(10) << std::endl; result.push_back(va[(*it)-1]); } else result.push_back(DefaultBigMod()); // NA for out of range's } } } return (result); } SEXP biginteger_set_at(SEXP src, SEXP idx, SEXP value) { // return = ( src[idx] <- value ) bigvec result = bigintegerR::create_bignum(src); bigvec vvalue = bigintegerR::create_bignum(value); vector vidx = bigintegerR::create_int(idx); if(vvalue.size() == 0) { if(result.size() == 0) return bigintegerR::create_SEXP(result); else error(_("replacement has length zero")); } //case: logicals if (TYPEOF(idx) == LGLSXP) { int pos = 0; for (unsigned int i = 0; i < result.size(); ++i) if (vidx[i%vidx.size()]) result.set(i, vvalue[pos++ % vvalue.size()]); return bigintegerR::create_SEXP(result); } else { std::remove(vidx.begin(), vidx.end(), 0); // remove all zeroes if (vidx.empty()) return bigintegerR::create_SEXP(result); // return = (src[-idx] <- value) if (vidx[0] < 0) { for (vector::iterator it = vidx.begin(); it != vidx.end(); ++it) if (*it > 0) error(_("only 0's may mix with negative subscripts")); else if (-(*it)-1 >= (int)result.size()) error(_("subscript out of bounds")); int pos = 0; for (int i = 0; i < (int)result.size(); ++i) if (find(vidx.begin(), vidx.end(), -i-1) == vidx.end()) result.set(i, vvalue[pos++%vvalue.size()]); } //standard case: return = (src[idx] <- value) with idx: positive integer else { // finding maximum to resize vector if needed int maximum = INT_MIN; for (vector::iterator it = vidx.begin(); it != vidx.end(); ++it) maximum = max(maximum, *it); if (maximum > (int)result.size()) result.resize(maximum); int pos = 0; for (vector::iterator it = vidx.begin(); it != vidx.end(); ++it) { if (*it < 0) error(_("only 0's may mix with negative subscripts")); result.set((*it)-1,vvalue[pos++%vvalue.size()]); } } } return bigintegerR::create_SEXP(result); } SEXP biginteger_length(SEXP a) { return Rf_ScalarInteger(bigintegerR::create_bignum(a).size()); } SEXP biginteger_setlength(SEXP vec, SEXP value) { int len = 0; switch (TYPEOF(value)) { case INTSXP: case LGLSXP: if (LENGTH(value) != 1) error(_("invalid second argument")); len = Rf_asInteger(value); if (len < 0) error(_("vector size cannot be negative")); else if (len == NA_INTEGER) error(_("vector size cannot be NA")); break; case REALSXP: if (LENGTH(value) != 1) error(_("invalid second argument")); len = (int)*REAL(value); if (len < 0) error(_("vector size cannot be negative")); else if (! (R_FINITE (len ) )) error(_("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 ;-) error(_("negative length vectors are not allowed")); default: error(_("invalid second argument")); } bigvec v =bigintegerR::create_bignum(vec); v.resize(len); return bigintegerR::create_SEXP(v); } SEXP biginteger_is_na(SEXP a) { 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; } SEXP biginteger_sgn(SEXP a) { 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; } SEXP biginteger_c(SEXP args) { // if(TYPEOF(args) != VECSXP) error(_("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); } SEXP biginteger_cbind(SEXP args) { // if(TYPEOF(args) != VECSXP) error(_("should be a list")); bigvec result = bigintegerR::create_bignum(VECTOR_ELT(args,0)); if(result.nrow <= 0) result.nrow = result.size(); for(int i = 1; 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); } SEXP biginteger_rep(SEXP x, SEXP times) { bigvec v = bigintegerR::create_bignum(x), result; int rep = Rf_asInteger(times); result.value.reserve(v.size()*rep); 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); } SEXP biginteger_is_prime(SEXP a, SEXP reps) { 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; } SEXP biginteger_nextprime(SEXP a) { bigvec v = bigintegerR::create_bignum(a), result; result.value.reserve(v.size()); mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); for (unsigned int i = 0; i < v.size(); ++i) { mpz_nextprime(val,v[i].getValue().getValueTemp()); result.push_back(DefaultBigMod(val)); } return bigintegerR::create_SEXP(result); } SEXP biginteger_abs(SEXP a) { bigvec v = bigintegerR::create_bignum(a), result; result.value.reserve(v.size()); 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(DefaultBigMod(val)); // TODO: understand why following lines don't work. //result.push_back(bigmod()); //result[i].value.setValue(val); } result.modulus = v.modulus; return bigintegerR::create_SEXP(result); } /** @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) { bigvec va = bigintegerR::create_bignum(a), vb = bigintegerR::create_bignum(b), result; if(va.size() != vb.size()) return bigintegerR::create_SEXP(bigvec()); result.value.reserve(3*va.size()); 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); for(unsigned int i=0; i < va.size(); i++) { mpz_gcdext (g,s,t,va[i].getValue().getValueTemp(),vb[i].getValue().getValueTemp()); result.value.push_back(biginteger(g)); // Hem... not very elegant ! result.value.push_back(biginteger(s)); result.value.push_back(biginteger(t)); /* result[i*3].value.setValue(g); result[i*3+1].value.setValue(s); result[i*3+2].value.setValue(t);*/ } return bigintegerR::create_SEXP(result); } /** @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) { 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); result.value.reserve(size); /* 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.value[i].getValue(), (unsigned long int)nn[i]); } } return bigintegerR::create_SEXP(result); } // 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) { bigvec result, n_ = bigintegerR::create_bignum(n); int *kk = INTEGER(AS_INTEGER(k)), n_k = Rf_length(k); int size = (n_.value.empty() || n_k == 0) ? 0 : // else: max(n_.value.size(), n_k) (((int)n_.value.size() <= n_k) ? n_k : n_.value.size()); result.value.resize(size); for (int i = 0; i < size; ++i) { result.value[i].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.value[i].getValue(), n_.value[i % n_.value.size()].getValueTemp(), k_i); } } return bigintegerR::create_SEXP(result); } /** @brief fibnum return nth Fibonacci number * @param n integer */ SEXP bigI_fibnum(SEXP n) { bigvec result; if(Rf_length(n) > 0) { int nn = Rf_asInteger(n); unsigned long int num = nn; if(nn < 0 || nn == NA_INTEGER) error(_("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(DefaultBigMod(val)); // result[0].value.setValue(val); } // else // error(_("argument must not be an empty list")); return bigintegerR::create_SEXP(result); } /** @brief fibnum2 return nth and n-1th Fibonacci number * @param n integer */ SEXP bigI_fibnum2(SEXP n) { bigvec result; if(Rf_length(n) > 0) { int nn = Rf_asInteger(n); unsigned long int num = nn; if(nn < 0 || nn == NA_INTEGER) error(_("argument must be non-negative")); result.value.reserve(1); 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(DefaultBigMod(val2)); result.push_back(DefaultBigMod(val)); } else error(_("argument must not be an empty list")); return bigintegerR::create_SEXP(result); } /** @brief lucnum return nth lucas number * @param n integer */ SEXP bigI_lucnum(SEXP n) { bigvec result; if(Rf_length(n) > 0) { int nn = Rf_asInteger(n); unsigned long int num = nn; if(nn < 0 || nn == NA_INTEGER) error(_("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(DefaultBigMod(val)); } // else // error(_("argument must not be an empty list")); return bigintegerR::create_SEXP(result); } /** @brief lucnum2 return nth and n-1th lucas number * @param n integer */ SEXP bigI_lucnum2(SEXP n) { bigvec result; if(Rf_length(n) > 0) { int nn = Rf_asInteger(n); unsigned long int num = nn; if(nn < 0 || nn == NA_INTEGER) error(_("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(DefaultBigMod(val2)); result.push_back(DefaultBigMod(val)); } else error(_("argument must not be an empty list")); return bigintegerR::create_SEXP(result); } //Return max SEXP biginteger_max(SEXP a, SEXP narm) { 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.value[i].isNA() && !na_remove) return(bigintegerR::create_SEXP(result)); else if(!(va.value[i] < va.value[maximum] )) maximum = i; // if va.value[maximum = 0] is NA => false for the "<" => maximum changed = good } result.push_back(va.value[maximum]); // now the modulus ! if(va.modulus.size() == 1) result.modulus.push_back(va.modulus[0]); if(va.modulus.size()>1) { biginteger modulus ; modulus.setValue(va.modulus[0].getValueTemp()); for(unsigned int i = 1 ; i < va.modulus.size() ; ++i) { if(modulus != va.modulus[i]) // if one is different: no modulus return(bigintegerR::create_SEXP(result)); } result.modulus.push_back(modulus); } return(bigintegerR::create_SEXP(result)); } // Return min SEXP biginteger_min(SEXP a, SEXP narm) { 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.value[i].isNA() && !na_remove) return bigintegerR::create_SEXP(result); else if(!(va.value[i] > va.value[minimum] )) minimum = i; } result.push_back(va.value[minimum]); // now the modulus ! if(va.modulus.size() == 1) result.modulus.push_back(va.modulus[0]); if(va.modulus.size()>1) { biginteger modulus ; modulus.setValue(va.modulus[0].getValueTemp()); for(unsigned int i = 1 ; i < va.modulus.size() ; ++i) { if(modulus != va.modulus[i]) // if one is different: no modulus return bigintegerR::create_SEXP(result); } result.modulus.push_back(modulus); } return bigintegerR::create_SEXP(result); } SEXP biginteger_cumsum(SEXP a) { bigvec result, va = bigintegerR::create_bignum(a); result.value.resize(va.value.size()); mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); bool hasmodulus = true; // first the modulus ! if(va.modulus.size() > 1) { biginteger modulus ; modulus.setValue(va.modulus[0].getValueTemp()); for(unsigned int i = 1 ; i < va.modulus.size() ; ++i) { if(modulus != va.modulus[i]) { // if one is different: no modulus hasmodulus = false; break; } } if(hasmodulus) result.modulus.push_back(modulus); } else if(va.modulus.size() == 1) { result.modulus.push_back(va.modulus[0]); hasmodulus = true; } else hasmodulus = false; for(unsigned int i = 0 ; i < va.size(); ++i) { { if(va.value[i].isNA() ) { break; // all last values are NA. } mpz_add(val,val,va.value[i].getValueTemp()); if(hasmodulus) mpz_mod(val,val,va.modulus[0].getValueTemp() ); result.value[i].setValue(val); } } return(bigintegerR::create_SEXP(result)); } SEXP biginteger_sum(SEXP a) { bigvec result, va = bigintegerR::create_bignum(a); result.value.resize(1); mpz_t val; mpz_init(val); mpz_t_sentry val_s(val); bool hasmodulus = true; // first the modulus ! if(va.modulus.size() > 1) { biginteger modulus ; modulus.setValue(va.modulus[0].getValueTemp()); for(unsigned int i = 1 ; i < va.modulus.size() ; ++i) { if(modulus != va.modulus[i]) { // if one is different: no modulus hasmodulus = false; break; } } if(hasmodulus) result.modulus.push_back(modulus); } else if(va.modulus.size() == 1) { result.modulus.push_back(va.modulus[0]); hasmodulus = true; } else hasmodulus = false; for(unsigned int i = 0 ; i < va.size(); ++i) { { if(va.value[i].isNA() ) { break; // all last values are NA. } mpz_add(val,val,va.value[i].getValueTemp()); if(hasmodulus) mpz_mod(val,val,va.modulus[0].getValueTemp() ); } } result.value[0].setValue(val); return(bigintegerR::create_SEXP(result)); } SEXP biginteger_prod(SEXP a) { bigvec result; bigvec va = bigintegerR::create_bignum(a); result.value.resize(1); mpz_t val; mpz_init(val); mpz_set_ui(val,1); mpz_t_sentry val_s(val); bool hasmodulus = true; // first the modulus ! if(va.modulus.size()>1) { biginteger modulus ; modulus.setValue(va.modulus[0].getValueTemp()); for(unsigned int i = 1 ; i < va.modulus.size() ; ++i) { if(modulus != va.modulus[i]) { // if one is different: no modulus hasmodulus = false; break; } } if(hasmodulus) result.modulus.push_back(modulus); } else hasmodulus = false; if(va.modulus.size() == 1) { result.modulus.push_back(va.modulus[0]); hasmodulus = true; } for(unsigned int i = 0 ; i < va.size(); ++i) { if(va.value[i].isNA() ) { return (bigintegerR::create_SEXP(result)); } mpz_mul(val,val,va.value[i].getValueTemp()); if(hasmodulus) mpz_mod(val,val,va.modulus[0].getValueTemp() ); } result.value[0].setValue(val); return(bigintegerR::create_SEXP(result)); } // return x ^ y [n] SEXP biginteger_powm(SEXP x, SEXP y, SEXP n) { bigvec result; bigvec vx = bigintegerR::create_bignum(x); bigvec vy = bigintegerR::create_bignum(y); bigvec vn = bigintegerR::create_bignum(n); result.value.resize(vx.value.size()); for (unsigned int i = 0 ; i < vx.value.size(); i++) { result.value[i].NA(false); // check if n != 0 if(mpz_sgn(vn.value[i % vn.value.size()].getValueTemp()) != 0) mpz_powm(result.value[i].getValue(), vx.value[i].getValueTemp(), vy.value[i % vy.value.size()].getValueTemp(), vn.value[i % vn.value.size()].getValueTemp()); } return bigintegerR::create_SEXP(result); } // ..._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. const char *nms[] = {"d", "exp", ""}; SEXP ans, d_R, exp_R; bigvec vx = bigintegerR::create_bignum(x); int n = vx.value.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); for (int i = 0 ; i < n; i++) { signed long int ex; d_[i] = mpz_get_d_2exp(&ex, vx.value[i].getValueTemp()); if(abs(ex) < INT_MAX) exp_[i] = (int) ex; else error(_("exponent too large to fit into an integer")); } UNPROTECT(1); return ans; } // bigI_frexp() SEXP biginteger_log2(SEXP x) { bigvec v = bigintegerR::create_bignum(x); 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.value[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 = bigintegerR::create_bignum(x); 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.value[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/extract_matrix.cc0000644000175000017500000001004713654725536015345 0ustar nileshnilesh#include "extract_matrix.h" #include "bigrationalR.h" // for something like x = A[indi, indj], but also simply A[ind] SEXP matrix_get_at_q(SEXP A,SEXP INDI, SEXP INDJ) { bigvec_q mat = bigrationalR::create_bignum(A); return(bigrationalR::create_SEXP(extract_gmp_R::get_at( mat,INDI,INDJ))); } // for something like x = A[indi, indj], but also simply A[ind] SEXP matrix_get_at_z(SEXP A,SEXP INDI, SEXP INDJ) { bigvec mat = bigintegerR::create_bignum(A); bigvec mat2 = extract_gmp_R::get_at( mat,INDI,INDJ); // now modulus ! // cell based modulus if(mat.modulus.size() == mat.value.size()) { 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) ); } // for something like A[indi, indj] <- val SEXP matrix_set_at_z(SEXP A, SEXP VAL, SEXP INDI, SEXP INDJ) { bigvec mat = bigintegerR::create_bignum(A); if(TYPEOF(INDI) != LGLSXP ) { if(!length(INDI)) return(A); std::vector vidx = bigintegerR::create_int(INDI); for(std::vector::const_iterator it = vidx.begin(); it != vidx.end(); ++it) if(*it >= static_cast(mat.size())) // in this case: we extend the vector return( biginteger_set_at(A,INDI,VAL) ); } bigvec val = bigintegerR::create_bignum(VAL); extract_gmp_R::set_at( mat,val,INDI,INDJ); return(bigintegerR::create_SEXP(mat)); } // for something like A[indi, indj] <- val SEXP matrix_set_at_q(SEXP A,SEXP VAL ,SEXP INDI, SEXP INDJ) { bigvec_q mat = bigrationalR::create_bignum(A); if(TYPEOF(INDI) != LGLSXP ) { if(!length(INDI)) return(A); std::vector vidx = bigintegerR::create_int(INDI); for(std::vector::const_iterator it = vidx.begin(); it != vidx.end(); ++it) if(*it >= static_cast(mat.size())) // in this case: we extend the vector return( bigrational_set_at(A,INDI,VAL) ); } bigvec_q val = bigrationalR::create_bignum(VAL); extract_gmp_R::set_at( mat,val,INDI,INDJ); return(bigrationalR::create_SEXP(mat)); } // // return a vector of n boolean corresponding to values that must be affected. // std::vector extract_gmp_R::indice_set_at (unsigned int n , SEXP & IND) { std::vector vidx = bigintegerR::create_int(IND); std::vector result (n,false); if(TYPEOF(IND) != NILSXP) //LOCICAL if (TYPEOF(IND) == LGLSXP) { for(unsigned int i = 0; i< n; ++i) result[i] = static_cast( vidx[i % vidx.size() ] ); } else //INTEGERS { //negatives integers: all except indices will be modified if (vidx[0] < 0) { for (std::vector::iterator it = result.begin(); it != result.end(); ++it) *it = true; for (std::vector::const_iterator jt = vidx.begin(); jt != vidx.end(); ++jt) { if(*jt > 0) error(_("only 0's may mix with negative subscripts")); if( (*jt != 0) && (*jt >= - static_cast(n))) result[-(*jt)-1] = false; } } else //INTEGERS (and positive) for (std::vector::const_iterator jt = vidx.begin(); jt != vidx.end(); ++jt) { if(*jt < 0) error(_("only 0's may mix with negative subscripts")); if((*jt != 0) && (*jt <= static_cast(n))) result[*jt-1] = true; } } else // NILSXP: return true for (std::vector::iterator it = result.begin(); it != result.end(); ++it) *it = true; return(result); }//end of indice_set_at gmp/src/extract_matrix.h0000644000175000017500000002447313667642073015215 0ustar nileshnilesh/*! \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 #include "bigvec_q.h" #include "bigintegerR.h" #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_set_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)) Rf_error("malformed matrix"); retour.resize(A.size() / A.nrow); for(i = 0; i < retour.size(); ++i) { retour[i] = new T(); retour[i]->value.resize(A.nrow); } // go ! for(i= 0 ; i < A.value.size(); ++i) // retour[col   ] [row ] (retour[i / A.nrow ])->value[ i % A.nrow].setValue(A.value[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) { // 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) 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) 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 { 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 // -------------------------- indJ.empty(); 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]->value.erase(i+(*matrice)[j]->value.begin()); //++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 std::unique(indI.begin(),indI.end()); //indI.erase(it,indI.end()); if ( indI.back() > 0) 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]->value.erase(i+(*matrice)[j]->value.begin()); } //--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: 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) 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])->value[i] = ((*matrice)[j])->value[indI[i]-1]; } else for (j = 0; j < matricework->size(); ++j) ( (*matricework)[j])->value[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.value[i + j* newnrow ] = ((*matrice)[j])->value[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)) Rf_error("malformed matrix"); unsigned int ncol = src.size() / src.nrow; // number of col std::vector vidx = indice_set_at ( src.nrow, IDX); std::vector vjdx = indice_set_at ( ncol, JDX); unsigned int k=0; for(unsigned int j = 0 ; j < ncol; ++j) { if(vjdx[j]) for(int i = 0 ; i < src.nrow; ++i) if(vidx[i]) { src.set(i + j * src.nrow, value[k % value.size()] ); ++k; } } return; }//end set_at }// end namespace #endif gmp/src/factorize.h0000644000175000017500000000044313654725536014136 0ustar nileshnilesh#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/apply.h0000644000175000017500000000014513654725536013274 0ustar nileshnileshextern "C" { SEXP gmpMatToListZ(SEXP X, SEXP line); SEXP gmpMatToListQ(SEXP X, SEXP line); } gmp/src/bigintegerR.h0000644000175000017500000001551013667642073014410 0ustar nileshnilesh/*! \file bigintegerR.h * \brief header for C++ functions used with R * * \version 1 * * \date Created: 2006 * \date Last modified: Time-stamp: <2010-04-10 19:21:20 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 DefaultBigMod (*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 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 std::vector& v); /** * \brief export bigvec to R value */ SEXP create_SEXP(const bigvec & v); 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 for function cbind() */ SEXP biginteger_cbind(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/bigrational.cc0000644000175000017500000000761613667642073014610 0ustar nileshnilesh/*! \file bigrational.cc * \brief Implementation of class bigrational * * \version 1 * * \date Created: 12/12/04 * \date Last modified: Time-stamp: <2014-07-10 08:31:28 antoine> * * \author Antoine Lucas (adapted from biginteger class made by * Immanuel Scholz) * * \note Licence: GPL (>= 2) */ #define USE_RINTERNALS #define R_NO_REMAP // avoid collisions with stl definitions #include "bigrational.h" #include "bigrationalR.h" #include #include using std::string; 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); } // set numerator bigrational::bigrational(void* raw): value(), na(true) { 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); } } 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/matrixq.h0000644000175000017500000000167013667642073013636 0ustar nileshnilesh/*! \file matrixq.h * \brief header for rational matrix functions set * * \date Created: 2005 * \date Last modified: Time-stamp: <2006-05-26 14:35:51 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) ; } /** * \brief Function designed for bigrational matrix */ namespace matrixq { /** * \brief C++ function use to transpose matrix */ bigvec_q bigq_transpose (const bigvec_q & mat,int nr,int nc); } gmp/src/bigrationalR.cc0000644000175000017500000006102013667642073014717 0ustar nileshnilesh/************************************************************/ /*! \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 "Rgmp.h" #include "bigvec_q.h" #include #include using namespace std; #include "bigintegerR.h" #include "bigrationalR.h" #include "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(); error(_("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.value.empty()) // 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; } /** * \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) { 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.value.empty() || vb.value.empty()) // error(_("argument must not be an empty list")); int size = (va.value.empty() || vb.value.empty()) ? 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 = matrixz::checkDims(va.nrow,vb.nrow) ; return bigrationalR::create_SEXP(result); } SEXP bigrational_bigz_binary_operation(SEXP a, SEXP b, bigrational_bigz_binary_fn f) { bigvec_q va = bigrationalR::create_bignum(a), result; bigvec vb = bigintegerR::create_bignum(b); int size = (va.value.empty() || vb.value.empty()) ? 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 = matrixz::checkDims(va.nrow,vb.nrow) ; return bigrationalR::create_SEXP(result); } SEXP bigrational_logical_binary_operation(SEXP a, SEXP b, bigrational_logical_binary_fn f) { 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.value.empty() || vb.value.empty()) // error(_("argument must not be an empty list")); int size = (va.value.empty() || vb.value.empty()) ? 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; } int nrow = matrixz::checkDims(va.nrow,vb.nrow) ; // 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; } 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)) error(_("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)) error(_("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)) error(_("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) error(_("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) { 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; } SEXP bigrational_as_numeric(SEXP a) { 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; } SEXP bigrational_get_at(SEXP a, SEXP b) { bigvec_q va = bigrationalR::create_bignum(a); vector vb = bigintegerR::create_int(b); bigvec_q result; if (TYPEOF(b) == LGLSXP) { for (unsigned int i = 0; i < va.size(); ++i) if (vb[i%vb.size()]) result.push_back(va.value[i]); } else { std::remove(vb.begin(), vb.end(), 0); // remove all zeroes if (vb.empty()) return bigrationalR::create_SEXP(bigvec_q()); if (vb[0] < 0) { for (vector::iterator it = vb.begin(); it != vb.end(); ++it) if (*it > 0) error(_("only 0's may mix with negative subscripts")); else if (-(*it)-1 >= (int)va.size()) error(_("subscript out of bounds")); // TODO: This is optimized for large va.size and small vb.size. // Maybe add a condition to use a different approach for large vb's result.value.reserve(va.size()-vb.size()); for (int i = 0; i < (int)va.size(); ++i) if (find(vb.begin(), vb.end(), -i-1) == vb.end()) result.push_back(va.value[i]); } else { result.value.reserve(vb.size()); for (vector::iterator it = vb.begin(); it != vb.end(); ++it) { if (*it < 0) error(_("only 0's may mix with negative subscripts")); if (*it <= (int)va.size()) result.push_back(va.value[(*it)-1]); else result.push_back(bigrational()); // NA for out of range's } } } return bigrationalR::create_SEXP(result); } SEXP bigrational_set_at(SEXP src, SEXP idx, SEXP value) { vector::iterator it; int i; bigvec_q result = bigrationalR::create_bignum(src); bigvec_q vvalue = bigrationalR::create_bignum(value); vector vidx = bigintegerR::create_int(idx); int pos = 0; if(vvalue.size() == 0) { if(result.size() == 0) return bigrationalR::create_SEXP(result); else error(_("replacement has length zero")); } if (TYPEOF(idx) == LGLSXP) { for (i = 0; i < (int)result.size(); ++i) if (vidx[i%vidx.size()]) result.value[i] = vvalue.value[pos++%vvalue.size()]; } else { std::remove(vidx.begin(), vidx.end(), 0); // remove all zeroes if (vidx.empty()) return bigrationalR::create_SEXP(result); if (vidx[0] < 0) { for ( it = vidx.begin(); it != vidx.end(); ++it) if (*it > 0) error(_("only 0's may mix with negative subscripts")); else if (-(*it)-1 >= (int)result.size()) error(_("subscript out of bounds")); pos = 0; for ( i = 0; i < (int)result.size(); ++i) if (find(vidx.begin(), vidx.end(), -i-1) == vidx.end()) result.value[i] = vvalue.value[pos++%vvalue.size()]; } else { // finding maximum to resize vector if needed int maximum = INT_MIN; for (it = vidx.begin(); it != vidx.end(); ++it) maximum = max(maximum, *it); if (maximum > (int)result.size()) result.value.resize(maximum); pos = 0; for (it = vidx.begin(); it != vidx.end(); ++it) { if (*it < 0) error(_("only 0's may mix with negative subscripts")); result.value[(*it)-1] = vvalue[pos++%vvalue.size()]; } } } return bigrationalR::create_SEXP(result); } SEXP bigrational_length(SEXP a) { return Rf_ScalarInteger(bigrationalR::create_bignum(a).size()); } SEXP bigrational_den(SEXP a) { mpz_t z_tmp; mpz_init(z_tmp); bigvec_q v =bigrationalR::create_bignum(a); bigvec result; result.value.resize(v.size()); for (unsigned int i = 0; i < v.size(); ++i) { mpq_get_den(z_tmp,v.value[i].getValueTemp()); result.value[i].setValue(z_tmp); } mpz_clear(z_tmp); return bigintegerR::create_SEXP(result); } SEXP bigrational_num(SEXP a) { 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.value[i].isNA()) { mpq_get_num(z_tmp,v.value[i].getValueTemp()); result.value[i].setValue(z_tmp); } // else: uninitialized, i.e., NA } mpz_clear(z_tmp); return bigintegerR::create_SEXP(result); } SEXP bigrational_setlength(SEXP vec, SEXP value) { int len = 0; switch (TYPEOF(value)) { case INTSXP: case LGLSXP: if (LENGTH(value) != 1) error(_("invalid second argument")); len = *INTEGER(value); if (len < 0) error(_("vector size cannot be negative")); else if (len == NA_INTEGER) error(_("vector size cannot be NA")); break; case REALSXP: if (LENGTH(value) != 1) error(_("invalid second argument")); len = (int)*REAL(value); if (len < 0) error(_("vector size cannot be negative")); else if (! (R_FINITE (len ) ) ) error(_("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 ;-) error(_("negative length vectors are not allowed")); default: error(_("invalid second argument")); } bigvec_q v =bigrationalR::create_bignum(vec); v.value.resize(len); return bigrationalR::create_SEXP(v); } 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.value[i].isNA(); UNPROTECT(1); return ans; } SEXP bigrational_is_int(SEXP a) { 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.value[i].getValueTemp()); a_[i] = mpz_cmp_ui (z_tmp, 1) == 0; // <==> numerator == 1 } mpz_clear(z_tmp); UNPROTECT(1); return ans; } SEXP bigrational_c(SEXP args) { // if(TYPEOF( args ) != LISTSXP) // error(_("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.value[j]); v.value.clear(); } return bigrationalR::create_SEXP(result); } SEXP bigrational_cbind(SEXP args) { bigvec_q result = bigrationalR::create_bignum(VECTOR_ELT(args,0)); if(result.nrow <= 0) result.nrow = result.size(); for(int i= 1; i < Rf_length(args); i++) { bigvec_q v = bigrationalR::create_bignum(VECTOR_ELT(args,i)); for(int j=0; j < (int)v.size() ; j++) result.push_back(v[j]); v.clear(); } return bigrationalR::create_SEXP(result); } SEXP bigrational_rep(SEXP x, SEXP times) { 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.value[j]); return bigrationalR::create_SEXP(result); } // Return max SEXP bigrational_max(SEXP a, SEXP narm) { 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.value[i].isNA() && ! na_remove) return(bigrationalR::create_SEXP(result)); else if(!(va.value[i] < va.value[maximum] )) maximum = i; // if va.value[maximum = 0] is NA => false for the "<" => maximum changed = good } result.push_back(va.value[maximum]); return bigrationalR::create_SEXP(result); } // Return min SEXP bigrational_min(SEXP a, SEXP narm) { 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.value[i].isNA() && !na_remove) return(bigrationalR::create_SEXP(result)); else if(!(va.value[i] > va.value[minimum] )) minimum = i; // if va.value[maximum = 0] is NA => false for the "<" => maximum changed = good } result.push_back(va.value[minimum]); return bigrationalR::create_SEXP(result); } // Return cumsum SEXP bigrational_cumsum(SEXP a) { bigvec_q result, va = bigrationalR::create_bignum(a); result.value.resize(va.value.size()); mpq_t val; mpq_init(val); mpq_t_sentry val_s(val); for(unsigned int i = 0 ; i < va.size(); ++i) { if(va.value[i].isNA() ) { break; // all last values are NA. } mpq_add(val,val,va.value[i].getValueTemp()); result.value[i].setValue(val); } return(bigrationalR::create_SEXP(result)); } // Return sum SEXP bigrational_sum(SEXP a) { bigvec_q result, va = bigrationalR::create_bignum(a); result.value.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.value[i].isNA()) { break; // all last values are NA. } mpq_add(val,val,va.value[i].getValueTemp()); } result.value[0].setValue(val); return(bigrationalR::create_SEXP(result)); } // Return prod SEXP bigrational_prod(SEXP a) { bigvec_q result, va = bigrationalR::create_bignum(a); result.value.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.value[i].isNA() ) { return (bigrationalR::create_SEXP(result)); } mpq_mul(val,val,va.value[i].getValueTemp()); } result.value[0].setValue(val); return(bigrationalR::create_SEXP(result)); } /* ================================ UNUSED ============================*/ // return x ^ y x: "bigq" y: "bigz" (or INTSXP, REALSXP -- TODO ?) SEXP bigrational_R_pow(SEXP x, SEXP y) { bigvec_q result, vx = bigrationalR::create_bignum(x); bigvec vy = bigintegerR::create_bignum(y); int size = (vx.value.empty() || vy.value.empty()) ? 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.value.resize(size); for (int i = 0 ; i < size; i++) { int i_x = i % vx.value.size(), i_y = i % vy.value.size(); //fails: val.NA(false); if(vx.value[i_x].isNA() || vy.value[i_y].isNA()) break; // else -- res[i] := x[i] ^ y[i] = (num ^ y_i) / (den ^ y_i) ---- if(mpz_sgn(vy.value[i_y].getValueTemp()) < 0) error(_("Negative powers not yet implemented [i = %d]"), i_y +1); if (!mpz_fits_ulong_p(vy.value[i_y].getValueTemp())) error(_("exponent too large for pow [i = %d]"), i_y +1); int y_i = mpz_get_ui(vy.value[i_y].getValueTemp()); // *num = mpq_numref(vx.value[i].getValueTemp()); // *den = mpq_denref(vx.value[i].getValueTemp()); mpq_get_num(num, vx.value[i_x].getValueTemp()); mpq_get_den(den, vx.value[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.value[i].setValue(val); } return bigrationalR::create_SEXP(result); } // ..._pow() gmp/src/factorize.cc0000644000175000017500000001337413654725536014303 0ustar nileshnilesh/* 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 "Rgmp.h" #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; } } error( "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/Rgmp.h0000644000175000017500000000103513654725536013053 0ustar nileshnilesh#ifndef R_gmp_HEADER #define R_gmp_HEADER 1 // gmp.h calls cstddef with __need_size_t defined #include // and avoid the inclusion of stdlib.h #include #include #include #include #include // the only thing we use from : #define AS_INTEGER(x) coerceVector(x,INTSXP) #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/apply.cc0000644000175000017500000000606413654725536013440 0ustar nileshnilesh #include #include // and one thing from Rdefines.h : #define NEW_LIST(n) allocVector(VECSXP,n) #include "apply.h" #include "bigintegerR.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) ); for(unsigned int i = 0; i < nrow; ++i) { bigvec oneLine ; for(unsigned int j = 0; j < ncol; ++j) { oneLine.value.push_back(matrix.value[i+j*nrow]); // modulus, if one by cell if(matrix.modulus.size() ==matrix.value.size() ) oneLine.modulus.push_back(matrix.modulus[i+j*nrow]); } // modulus, if one by line if(((matrix.modulus.size() == nrow ) || (matrix.modulus.size() == 1) ) && (matrix.modulus.size() !=matrix.value.size()) ) oneLine.modulus.push_back(matrix.modulus[i % matrix.modulus.size() ]); SET_VECTOR_ELT(ans, i,bigintegerR::create_SEXP(oneLine)); } UNPROTECT(1); } else { // RETURN a list of all rows ! PROTECT (ans = NEW_LIST(ncol) ); for(unsigned int j = 0; j < ncol; ++j) { bigvec oneLine ; for(unsigned int i = 0; i < nrow; ++i) { oneLine.value.push_back(matrix.value[i+j*nrow]); // modulus, if one by cell if(matrix.modulus.size() ==matrix.value.size() ) oneLine.modulus.push_back(matrix.modulus[i+j*nrow]); } // modulus, if one by line if( (matrix.modulus.size() == 1) && (matrix.modulus.size() !=matrix.value.size()) ) oneLine.modulus.push_back(matrix.modulus[0 ]); SET_VECTOR_ELT(ans, j,bigintegerR::create_SEXP(oneLine)); } 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 bool 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) { // RETURN a list of all lines PROTECT (ans = NEW_LIST(matrix.nrow) ); 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)); } UNPROTECT(1); } else { // RETURN a list of all rows ! PROTECT (ans = NEW_LIST(ncol) ); 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)); } UNPROTECT(1); } return(ans); } gmp/src/matrix.h0000644000175000017500000000240013667642073013445 0ustar nileshnilesh/*! \file matrix.h * \brief C++ function to add matrix support * * \version 1 * * \date Created: 25/05/06 * \date Last modified: Time-stamp: <2006-05-26 14:28:09 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 C functions for matrix */ namespace matrixz{ /** \brief C function use to transpose a matrix */ bigvec bigint_transpose ( bigvec & mat,int nr,int nc); /** \brief Check dimension compatibility */ int checkDims(int dima,int dimb); } #endif gmp/src/biginteger.h0000644000175000017500000001657413667642073014301 0ustar nileshnilesh/*! \file biginteger.h * \brief Description of class biginteger * * \date Created: 2004 * \date Last modified: Time-stamp: <2010-04-10 19:09:32 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() : na(true) {mpz_init(value);} /** * 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_) : na(false) { if(value_ == NA_INTEGER) {mpz_init(value); na = true ;} else mpz_init_set_si(value, value_);} /** * Construct a biginteger from a long value. */ biginteger(const long int value_) : na(false) { 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(const unsigned long int value_) : na(false) { 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(const double value_) : na(false) { if( R_FINITE(value_) ) mpz_init_set_d(value, value_); else {mpz_init(value); na = true ;} } /** * Construct a biginteger from a string value. */ biginteger(const std::string& value_) : na(false) { /* 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(const biginteger& rhs) : na(rhs.na) { mpz_init_set(value, rhs.getValueTemp()); } /** * Free the owned mpz_t structs */ virtual ~biginteger() {mpz_clear(value);} /** * Set the biginteger to state "NA". */ void setValue() {mpz_set_si(value, 0); na = true;} /** * Set the biginteger to a specific value. */ void setValue(const mpz_t & value_ ) { mpz_set(value, value_); na = false; } /** \brief set value from an integer */ 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 */ 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 */ 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 */ 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. */ const mpz_t& getValueTemp() const {return value;} /** \brief accessor on value */ mpz_t & getValue() { 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 true, if the value is 0. */ 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). */ long as_long() const {return mpz_get_si(value);} /** * \brief Convert the biginteger into a double value * (you may loose precision) */ 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); }; /** \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/bigvec_q.cc0000644000175000017500000000417213657742032014061 0ustar nileshnilesh#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.value.size()), nrow(rhs.nrow) { for(unsigned int i=0; i< rhs.size(); ++i) { value[i].setValue(rhs.value[i]); } } 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) { return (*this)[row + col*nrow]; } void bigvec_q::set(unsigned int row, unsigned int col, const bigrational & val) { set( row + col*nrow,val); } void bigvec_q::set(unsigned int i,const bigrational & val) { //DEBUG !! if(i>=value.size()) { Rprintf("t nul a bigvec_q_set\n"); return; } value[i] = val; } void bigvec_q::set(unsigned int i,const mpq_t & val) { if(i>=value.size()) { Rprintf("t nul a 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/bigrational.h0000644000175000017500000001711613667642073014446 0ustar nileshnilesh/*! \file bigrational.h * \brief Description of class bigrational * * \date Created: 22/05/06 * \date Last modified: Time-stamp: <2009-10-27 17:28:06 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 "Rgmp.h" #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() : value(), na(true) {mpq_init(value);} /** * 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_) : value(), na(false) { mpq_init(value); mpq_set(value, value_); } /** * \brief create a rational from an [big] integer */ bigrational(const mpz_t& value_) : value(), na(false) { mpq_init(value); mpq_set_z(value, value_); } /** * Construct a bigrational from a long value. */ bigrational(int value_) : value(), na(false) { mpq_init(value); if(value_ == NA_INTEGER) na = true ; else mpq_set_si(value, value_,1); } /** * Construct a bigrational from a long value. */ bigrational(int num_, int den_) : value(), na(false) { 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(double value_) : value(), na(false) { 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(const std::string& value_) : value(), na(false) { 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(const bigrational & rhs) : value(), na(rhs.na) { mpq_init(value); mpq_set(value, rhs.value); } /** * Free the owned mpz_t structs */ virtual ~bigrational() {mpq_clear(value);} /** \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/factor.cc0000644000175000017500000000177113667642073013567 0ustar nileshnilesh/*! \file factor.cc * \brief C function used for factorization * * \version 1 * * \date Created: 04/12/04 * \date Last modified: Time-stamp: <2013-06-08 22:47:18 antoine> * * \author Antoine Lucas (help from Immanuel Scholz) (R adaptation) * Original C code from libgmp. * * \note Licence: GPL (>= 2) */ #include "Rgmp.h" #include "factorize.h" using namespace std; #include "factor.h" // // \brief function that gets values from R and send to functions // factor // SEXP factorR (SEXP n) { 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) error(_("Cannot factorize 0")); if(sgn<0) { mpz_abs(val,val); result.value.push_back(biginteger(-1)); } // // function from gmplib, in demo/factorize.c // factor(val,result); } return bigintegerR::create_SEXP(result); } gmp/Changes0000644000175000017500000000656213033764662012505 0ustar nileshnileshSat 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/tests/0000755000175000017500000000000013735324616012343 5ustar nileshnileshgmp/tests/arith-ex.R0000644000175000017500000002367213735324616014221 0ustar nileshnileshlibrary(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.save0000644000175000017500000036577213667642073015743 0ustar nileshnilesh R Under development (unstable) (2020-06-04 r78645) -- "Unsuffered Consequences" Copyright (C) 2020 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 + ## FIXME res <- matrix(res, nr, n, dimnames = list(if(!unary) xlabs, xlabs)) + ## for now + res <- matrix(res, nr, n, dimnames = list(NULL, xlabs)) + + for(i in 1:nr) + for(j in 1:n) { + e <- if(unary) try(FUN(x[[j]]), silent = TRUE) else + try(FUN(x[[i]],x[[j]]), silent = TRUE) + if(inherits(e, "try-error")) + e <- error + else if(length(e) == 0) + e <- numeric() + + ## ## now, for some functions also compute the corresponding numeric values + ## d <- if(unary) try(FUN(as.numeric(x[[j]])), silent = TRUE) else + ## try(FUN(as.numeric(x[[i]]),as.numeric(x[[j]])), silent = TRUE) + + res[i,j] <- sortie(e)[1] + } + res ## for printing, the user may prefer as.data.frame(.) + }## end{test} > > > allfunctionid <- c("as.bigz","add.bigz","sub.bigz","mul.bigz", + "divq.bigz","div.bigz","mod.bigz","pow.bigz", + "inv.bigz", "gcd.bigz", "gcdex", "lcm.bigz", + "as.bigq", + "add.bigq","sub.bigq","div.bigq", "mul.bigq", "pow.bigq", + "chooseZ", + "max.bigq","max.bigz","min.bigq","min.bigz") > unaryfunctionid <- c("log.bigz","log2.bigz","log10.bigz","c.bigz", + "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 = 125) > > sapply(allfunctionid, numericFunName) as.bigz add.bigz sub.bigz mul.bigz divq.bigz div.bigz mod.bigz pow.bigz inv.bigz gcd.bigz gcdex "as.bigz" "+" "-" "*" "%/%" "/" "%%" "^" "inv.bigz" "gcd" "gcdex" lcm.bigz as.bigq add.bigq sub.bigq div.bigq mul.bigq pow.bigq chooseZ max.bigq max.bigz min.bigq "lcm" "as.bigq" "+" "-" "/" "*" "^" "choose" "max" "max" "min" min.bigz "min" > sapply(unaryfunctionid, numericFunName) log.bigz log2.bigz log10.bigz c.bigz isprime nextprime factorialZ sizeinbase fibnum "log" "log2" "log10" "c" "isprime" "nextprime" "factorial" "sizeinbase" "fibnum" fibnum2 lucnum lucnum2 factorize abs "fibnum2" "lucnum" "lucnum2" "factorize" "abs" > > > ex <- expression(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(.) is.null(.) || is.na(.) || + (is.finite(as.numeric(.)) && (!inherits(., "bigz") || is.null(modulus(.))))) > ## names(x) <- sapply(ex, format) > ## shorter & easier: > names(x) <- sapply(x, formatN) > str(x) List of 12 $ 23. : num 23 $ 25 : chr "25" $ 2.3 : num 2.3 $ -4. : num -4 $ 4L : int 4 $ 0. : num 0 $ 34_Z : 'bigz' raw 34 $ 32/7 : 'bigq' raw 32/7 ..- attr(*, "denominator")= raw [1:16] 01 00 00 00 ... $ (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, "\n\n", sep="") + 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) + cat("\n-> all.equal(target = res, current = F()):\n") + nres <- test(FUN, nx, out = "numeric") + # print(all.equal(res, nres)) + } 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()): 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 (0 %% 23) (23 %% 25) (1 %% 2) (3 %% -4) (3 %% 4) error (23 %% 34) (23 %% 32) (23 %% 31) 23 23 (2 %% -3) 2 (2 %% 23) (0 %% 25) (1 %% 2) (1 %% -4) (1 %% 4) error (25 %% 34) (25 %% 32) (25 %% 31) 25 25 (1 %% -3) 3 (2 %% 23) (2 %% 25) (0 %% 2) (2 %% -4) (2 %% 4) error (2 %% 34) (2 %% 32) (2 %% 31) 2 2 (2 %% -3) 4 (19 %% 23) (21 %% 25) (0 %% 2) (0 %% -4) (0 %% 4) error (30 %% 34) (28 %% 32) (27 %% 31) -4 -4 (2 %% -3) 5 (4 %% 23) (4 %% 25) (0 %% 2) (0 %% -4) (0 %% 4) error (4 %% 34) (4 %% 32) (4 %% 31) 4 4 (1 %% -3) 6 (0 %% 23) (0 %% 25) (0 %% 2) (0 %% -4) (0 %% 4) error (0 %% 34) (0 %% 32) (0 %% 31) 0 0 (0 %% -3) 7 (11 %% 23) (9 %% 25) (0 %% 2) (2 %% -4) (2 %% 4) error (0 %% 34) (2 %% 32) (3 %% 31) 34 34 (1 %% -3) 8 (4 %% 23) (4 %% 25) (0 %% 2) (0 %% -4) (0 %% 4) error (4 %% 34) (4 %% 32) (4 %% 31) 4 4 (1 %% -3) 9 (8 %% 23) (6 %% 25) (1 %% 2) (3 %% -4) (3 %% 4) error (31 %% 34) (31 %% 32) (0 %% 31) 31 31 (1 %% -3) 10 11 NA NA NA NA NA error NA NA NA NA NA NA 12 (20 %% 23) (22 %% 25) (1 %% 2) (1 %% -4) (1 %% 4) error (31 %% 34) (29 %% 32) (28 %% 31) -3 -3 (0 %% -3) ------------------------------------------ add.bigz -> num.fn.: + -> all.equal(target = res, current = F()): 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) 1 46 48 25 19 27 23 57 193/7 (9 %% 45) 2 48 50 27 21 29 25 59 207/7 (11 %% 45) 3 25 27 4 -2 6 2 36 54155785519130213/7881299347898368 (33 %% 45) 4 19 21 -2 -8 0 -4 30 4/7 (27 %% 45) 5 27 29 6 0 8 4 38 60/7 (35 %% 45) 6 23 25 2 -4 4 0 34 32/7 (31 %% 45) 7 57 59 36 30 38 34 68 270/7 (20 %% 45) 8 55 57 34 28 36 32 66 64/7 (18 %% 45) 9 (9 %% 45) (11 %% 45) (33 %% 45) (27 %% 45) (35 %% 45) (31 %% 45) (20 %% 45) 249/7 (17 %% 45) 10 11 NA NA NA NA NA NA NA NA NA 12 20 22 -1 -7 1 -3 31 11/7 (28 %% 45) NULL NA -3L 1 NA 20 2 NA 22 3 NA -1 4 NA -7 5 NA 1 6 NA -3 7 NA 31 8 NA 29 9 NA (28 %% 45) 10 11 NA NA 12 NA -6 ------------------------------------------ sub.bigz -> num.fn.: - -> all.equal(target = res, current = F()): 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA 1 0 -2 21 27 19 23 -11 -9 (37 %% 45) -23 NA 2 2 0 23 29 21 25 -9 -7 (39 %% 45) -25 NA 3 -21 -23 0 6 -2 2 -32 -30 (16 %% 45) -2 NA 4 -27 -29 -6 0 -8 -4 -38 -36 (10 %% 45) 4 NA 5 -19 -21 2 8 0 4 -30 -28 (18 %% 45) -4 NA 6 -23 -25 -2 4 -4 0 -34 -32 (14 %% 45) 0 NA 7 11 9 32 38 30 34 0 2 (3 %% 45) -34 NA 8 9 7 30 36 28 32 -2 0 (1 %% 45) -32 NA 9 (8 %% 45) (6 %% 45) (29 %% 45) (35 %% 45) (27 %% 45) (31 %% 45) (42 %% 45) (44 %% 45) (0 %% 45) (14 %% 45) NA 10 11 NA NA NA NA NA NA NA NA NA NA NA 12 -26 -28 -5 1 -7 -3 -37 -35 (11 %% 45) 3 NA -3L 1 26 2 28 3 5 4 -1 5 7 6 3 7 37 8 35 9 (34 %% 45) 10 11 NA 12 0 ------------------------------------------ mul.bigz -> num.fn.: * -> all.equal(target = res, current = F()): 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) 1 529 575 46 -92 92 0 782 736/7 (38 %% 45) 2 575 625 50 -100 100 0 850 800/7 (10 %% 45) 3 46 50 4 -8 8 0 68 2589569785738035/246290604621824 (17 %% 45) 4 -92 -100 -8 16 -16 0 -136 -128/7 (11 %% 45) 5 92 100 8 -16 16 0 136 128/7 (34 %% 45) 6 0 0 0 0 0 0 0 0 (0 %% 45) 7 782 850 68 -136 136 0 1156 1088/7 (19 %% 45) 8 736 800 64 -128 128 0 1088 1024/49 (2 %% 45) 9 (38 %% 45) (10 %% 45) (17 %% 45) (11 %% 45) (34 %% 45) (0 %% 45) (19 %% 45) 992/7 (16 %% 45) 10 11 NA NA NA NA NA NA NA NA NA 12 -69 -75 -6 12 -12 0 -102 -96/7 (42 %% 45) NULL NA -3L 1 NA -69 2 NA -75 3 NA -6 4 NA 12 5 NA -12 6 NA 0 7 NA -102 8 NA -96 9 NA (42 %% 45) 10 11 NA NA 12 NA 9 ------------------------------------------ divq.bigz -> num.fn.: %/% -> all.equal(target = res, current = F()): 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 1 0 11 -6 5 NA 0 5 (0 %% 45) NA -8 2 1 1 12 -7 6 NA 0 6 (0 %% 45) NA -9 3 0 0 1 -1 0 NA 0 0 (0 %% 45) NA -1 4 -1 -1 -2 1 -1 NA -1 -1 (44 %% 45) NA 1 5 0 0 2 -1 1 NA 0 1 (0 %% 45) NA -2 6 0 0 0 0 0 NA 0 0 (0 %% 45) NA 0 7 1 1 17 -9 8 NA 1 8 (1 %% 45) NA -12 8 1 1 16 -8 8 NA 0 8 (1 %% 45) NA -11 9 (1 %% 45) (1 %% 45) (15 %% 45) (37 %% 45) (7 %% 45) NA (0 %% 45) (7 %% 45) (1 %% 45) NA (34 %% 45) 10 11 NA NA NA NA NA NA NA NA NA NA NA 12 -1 -1 -2 0 -1 NA -1 -1 (44 %% 45) NA 1 ------------------------------------------ div.bigz -> num.fn.: / -> all.equal(target = res, current = F()): 23. 25 2.3 1 1 23/25 25895697857380352/2589569785738035 2 25/23 1 5629499534213120/517913957147607 3 2589569785738035/25895697857380352 517913957147607/5629499534213120 1 4 -4/23 -4/25 -4503599627370496/2589569785738035 5 4/23 4/25 4503599627370496/2589569785738035 6 0 0 0 7 34/23 34/25 38280596832649216/2589569785738035 8 32/161 32/175 36028797018963968/18126988500166245 9 (17 %% 45) NA (38 %% 45) 10 11 NA NA NA 12 -3/23 -3/25 -1125899906842624/863189928579345 -4. 4L 0. 34_Z 1 -23/4 23/4 error 23/34 2 -25/4 25/4 error 25/34 3 -2589569785738035/4503599627370496 2589569785738035/4503599627370496 error 2589569785738035/38280596832649216 4 1 -1 error -2/17 5 -1 1 error 2/17 6 0 0 error 0 7 -17/2 17/2 error 1 8 -8/7 8/7 error 16/119 9 (26 %% 45) (19 %% 45) NA (34 %% 45) 10 11 NA NA NA NA 12 3/4 -3/4 error -3/34 32/7 (31 %% 45) NULL NA -3L 1 161/32 (8 %% 45) NA -23/3 2 175/32 (40 %% 45) NA -25/3 3 18126988500166245/36028797018963968 (32 %% 45) NA -863189928579345/1125899906842624 4 -7/8 (26 %% 45) NA 4/3 5 7/8 (19 %% 45) NA -4/3 6 0 (0 %% 45) NA 0 7 119/16 (4 %% 45) NA -34/3 8 1 (17 %% 45) NA -32/21 9 217/32 (1 %% 45) NA NA 10 11 NA NA NA NA 12 -21/32 (42 %% 45) NA 1 ------------------------------------------ mod.bigz -> num.fn.: %% -> all.equal(target = res, current = F()): 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 0 23 1 3 3 NA 23 3 (23 %% 31) NA 2 2 2 0 1 1 1 NA 25 1 (25 %% 31) NA 1 3 2 2 0 2 2 NA 2 2 (2 %% 31) NA 2 4 19 21 0 0 0 NA 30 0 (27 %% 31) NA 2 5 4 4 0 0 0 NA 4 0 (4 %% 31) NA 1 6 0 0 0 0 0 NA 0 0 (0 %% 31) NA 0 7 11 9 0 2 2 NA 0 2 (3 %% 31) NA 1 8 9 7 0 0 0 NA 32 0 (1 %% 31) NA 2 9 (8 %% 23) (6 %% 25) (1 %% 2) (3 %% -4) (3 %% 4) NA (31 %% 34) (3 %% 4) (0 %% 31) NA (1 %% -3) 10 11 NA NA NA NA NA NA NA NA NA NA NA 12 20 22 1 1 1 NA 31 1 (28 %% 31) NA 0 ------------------------------------------ pow.bigz -> num.fn.: ^ -> all.equal(target = res, current = F()): 23. 25 2.3 1 20880467999847912034355032910567 11045767571919545466173812409689943 529 2 142108547152020037174224853515625 88817841970012523233890533447265625 625 3 8388608 33554432 4 4 -70368744177664 -1125899906842624 16 5 70368744177664 1125899906842624 16 6 0 0 0 7 167500108222301408246337399112597504 193630125104980427932766033374162714624 1156 8 41538374868278621028243970633760768 42535295865117307932921825928971026432 1024 9 (16 %% 45) (31 %% 45) (16 %% 45) 10 11 NA NA NA 12 -94143178827 -847288609443 9 -4. 1 1/279841 2 1/390625 3 1606938044258990275541962092341162602522202993782792835301376/44968714924347995877535679665554839525511318324676467468500625 4 1/256 5 1/256 6 error 7 1/1336336 8 2401/1048576 9 (16 %% 45) 10 11 NA 12 1/81 4L 0. 34_Z 32/7 (31 %% 45) NULL NA 1 279841 1 19895113660064588580108197261066338165074766609 error (32 %% 45) NA 2 390625 1 338813178901720135627329000271856784820556640625 error (25 %% 45) NA 3 16 1 17179869184 error (38 %% 45) NA 4 256 1 295147905179352825856 error (41 %% 45) NA 5 256 1 295147905179352825856 error (4 %% 45) NA 6 0 1 0 error (0 %% 45) NA 7 1336336 1 11756638905368616011414050501310355554617941909569536 error (34 %% 45) NA 8 1048576 1 1496577676626844588240573268701473812127674924007424 error (23 %% 45) NA 9 (31 %% 45) (1 %% 45) (31 %% 45) error (31 %% 45) NA 10 error 11 NA 1 NA error NA NA 12 81 1 16677181699666569 error (18 %% 45) NA -3L 1 1/12167 2 1/15625 3 1427247692705959881058285969449495136382746624/17365322677153409849313160265892197722207192875 4 -1/64 5 1/64 6 error 7 1/39304 8 343/32768 9 (1 %% 45) 10 11 NA 12 -1/27 ------------------------------------------ inv.bigz -> all.equal(target = res, current = F()): 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 NA 12 1 3 3 NA 3 7 (27 %% 45) NA 2 2 12 NA 1 1 1 NA 15 9 (5 %% 45) NA 1 3 12 13 NA NA NA NA NA NA (16 %% 45) NA 2 4 17 6 NA NA NA NA NA NA (23 %% 45) NA 2 5 6 19 NA NA NA NA NA NA (8 %% 45) NA 1 6 NA NA NA NA NA NA NA NA NA NA NA 7 21 14 NA NA NA NA NA NA (21 %% 45) NA 1 8 18 18 NA NA NA NA NA NA (1 %% 45) NA 2 9 (3 %% 45) (21 %% 45) (1 %% 45) (3 %% 45) (3 %% 45) NA (11 %% 45) (31 %% 45) NA NA (1 %% 45) 10 11 NA NA NA NA NA NA NA NA NA NA NA 12 15 8 1 1 1 NA 11 21 (10 %% 45) NA NA ------------------------------------------ gcd.bigz -> num.fn.: gcd -> all.equal(target = res, current = F()): 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 23 1 1 1 1 23 1 1 (1 %% 45) NA 1 2 1 25 1 1 1 25 1 1 (1 %% 45) NA 1 3 1 1 2 2 2 2 2 2 (1 %% 45) NA 1 4 1 1 2 4 4 4 2 4 (1 %% 45) NA 1 5 1 1 2 4 4 4 2 4 (1 %% 45) NA 1 6 23 25 2 4 4 0 34 32 (31 %% 45) NA 3 7 1 1 2 2 2 34 34 2 (1 %% 45) NA 1 8 1 1 2 4 4 32 2 32 (1 %% 45) NA 1 9 (1 %% 45) (1 %% 45) (1 %% 45) (1 %% 45) (1 %% 45) (31 %% 45) (1 %% 45) (1 %% 45) (31 %% 45) NA (1 %% 45) 10 11 NA NA NA NA NA NA NA NA NA NA NA 12 1 1 1 1 1 3 1 1 (1 %% 45) NA 3 ------------------------------------------ gcdex -> all.equal(target = res, current = F()): 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 23 1 1 1 1 23 1 1 1 23 1 2 1 25 1 1 1 25 1 1 1 25 1 3 1 1 2 2 2 2 2 2 1 2 1 4 1 1 2 4 4 4 2 4 1 4 1 5 1 1 2 4 4 4 2 4 1 4 1 6 23 25 2 4 4 0 34 32 31 0 3 7 1 1 2 2 2 34 34 2 1 34 1 8 1 1 2 4 4 32 2 32 1 32 1 9 1 1 1 1 1 31 1 1 31 31 1 10 11 23 25 2 4 4 0 34 32 31 0 3 12 1 1 1 1 1 3 1 1 1 3 3 ------------------------------------------ lcm.bigz -> num.fn.: lcm -> all.equal(target = res, current = F()): 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 23 575 46 92 92 0 782 736 (38 %% 45) NA 69 2 575 25 50 100 100 0 850 800 (10 %% 45) NA 75 3 46 50 2 4 4 0 34 32 (17 %% 45) NA 6 4 92 100 4 4 4 0 68 32 (34 %% 45) NA 12 5 92 100 4 4 4 0 68 32 (34 %% 45) NA 12 6 0 0 0 0 0 0 0 0 (0 %% 45) NA 0 7 782 850 34 68 68 0 34 544 (19 %% 45) NA 102 8 736 800 32 32 32 0 544 32 (2 %% 45) NA 96 9 (38 %% 45) (10 %% 45) (17 %% 45) (34 %% 45) (34 %% 45) (0 %% 45) (19 %% 45) (2 %% 45) (31 %% 45) NA (3 %% 45) 10 11 NA NA NA NA NA NA NA NA NA NA NA 12 69 75 6 12 12 0 102 96 (3 %% 45) NA 3 ------------------------------------------ as.bigq -> all.equal(target = res, current = F()): 23. 25 2.3 1 1 23/25 25895697857380352/2589569785738035 2 25/23 1 5629499534213120/517913957147607 3 2589569785738035/25895697857380352 517913957147607/5629499534213120 1 4 -4/23 -4/25 -4503599627370496/2589569785738035 5 4/23 4/25 4503599627370496/2589569785738035 6 0 0 0 7 34/23 34/25 38280596832649216/2589569785738035 8 32/161 32/175 36028797018963968/18126988500166245 9 31/23 31/25 34902897112121344/2589569785738035 10 11 NA NA NA 12 -3/23 -3/25 -1125899906842624/863189928579345 -4. 4L 0. 34_Z 1 -23/4 23/4 error 23/34 2 -25/4 25/4 error 25/34 3 -2589569785738035/4503599627370496 2589569785738035/4503599627370496 error 2589569785738035/38280596832649216 4 1 -1 error -2/17 5 -1 1 error 2/17 6 0 0 error 0 7 -17/2 17/2 error 1 8 -8/7 8/7 error 16/119 9 -31/4 31/4 error 31/34 10 11 NA NA NA NA 12 3/4 -3/4 error -3/34 32/7 (31 %% 45) NULL NA -3L 1 161/32 23/31 NA -23/3 2 175/32 25/31 NA -25/3 3 18126988500166245/36028797018963968 2589569785738035/34902897112121344 NA -863189928579345/1125899906842624 4 -7/8 -4/31 NA 4/3 5 7/8 4/31 NA -4/3 6 0 0 NA 0 7 119/16 34/31 NA -34/3 8 1 32/217 NA -32/21 9 217/32 1 NA -31/3 10 11 NA NA NA NA 12 -21/32 -3/31 NA 1 ------------------------------------------ add.bigq -> num.fn.: + -> all.equal(target = res, current = F()): 23. 25 2.3 1 46 48 28485267643118387/1125899906842624 2 48 50 30737067456803635/1125899906842624 3 28485267643118387/1125899906842624 30737067456803635/1125899906842624 2589569785738035/562949953421312 4 19 21 -1914029841632461/1125899906842624 5 27 29 7093169413108531/1125899906842624 6 23 25 2589569785738035/1125899906842624 7 57 59 40870166618387251/1125899906842624 8 193/7 207/7 54155785519130213/7881299347898368 9 54 56 37492466897859379/1125899906842624 10 11 NA NA NA 12 20 22 -788129934789837/1125899906842624 -4. 4L 0. 1 19 27 23 2 21 29 25 3 -1914029841632461/1125899906842624 7093169413108531/1125899906842624 2589569785738035/1125899906842624 4 -8 0 -4 5 0 8 4 6 -4 4 0 7 30 38 34 8 4/7 60/7 32/7 9 27 35 31 10 11 NA NA NA 12 -7 1 -3 34_Z 32/7 (31 %% 45) NULL NA 1 57 193/7 54 NA 2 59 207/7 56 NA 3 40870166618387251/1125899906842624 54155785519130213/7881299347898368 37492466897859379/1125899906842624 NA 4 30 4/7 27 NA 5 38 60/7 35 NA 6 34 32/7 31 NA 7 68 270/7 65 NA 8 270/7 64/7 249/7 NA 9 65 249/7 62 NA 10 11 NA NA NA NA 12 31 11/7 28 NA -3L 1 20 2 22 3 -788129934789837/1125899906842624 4 -7 5 1 6 -3 7 31 8 11/7 9 28 10 11 NA 12 -6 ------------------------------------------ sub.bigq -> num.fn.: - -> all.equal(target = res, current = F()): 23. 25 2.3 1 0 -2 23306128071642317/1125899906842624 2 2 0 25557927885327565/1125899906842624 3 -23306128071642317/1125899906842624 -25557927885327565/1125899906842624 0 4 -27 -29 -7093169413108531/1125899906842624 5 -19 -21 1914029841632461/1125899906842624 6 -23 -25 -2589569785738035/1125899906842624 7 11 9 35691027046911181/1125899906842624 8 -129/7 -143/7 17901808518797723/7881299347898368 9 8 6 32313327326383309/1125899906842624 10 11 NA NA NA 12 -26 -28 -5967269506265907/1125899906842624 -4. 4L 0. 1 27 19 23 2 29 21 25 3 7093169413108531/1125899906842624 -1914029841632461/1125899906842624 2589569785738035/1125899906842624 4 0 -8 -4 5 8 0 4 6 4 -4 0 7 38 30 34 8 60/7 4/7 32/7 9 35 27 31 10 11 NA NA NA 12 1 -7 -3 34_Z 32/7 (31 %% 45) 1 -11 129/7 -8 2 -9 143/7 -6 3 -35691027046911181/1125899906842624 -17901808518797723/7881299347898368 -32313327326383309/1125899906842624 4 -38 -60/7 -35 5 -30 -4/7 -27 6 -34 -32/7 -31 7 0 206/7 3 8 -206/7 0 -185/7 9 -3 185/7 0 10 11 NA NA NA 12 -37 -53/7 -34 NULL NA -3L 1 -23 NA 26 2 -25 NA 28 3 -2589569785738035/1125899906842624 NA 5967269506265907/1125899906842624 4 4 NA -1 5 -4 NA 7 6 0 NA 3 7 -34 NA 37 8 -32/7 NA 53/7 9 -31 NA 34 10 11 NA NA NA 12 3 NA 0 ------------------------------------------ div.bigq -> num.fn.: / -> all.equal(target = res, current = F()): 23. 25 2.3 1 1 23/25 25895697857380352/2589569785738035 2 25/23 1 5629499534213120/517913957147607 3 2589569785738035/25895697857380352 517913957147607/5629499534213120 1 4 -4/23 -4/25 -4503599627370496/2589569785738035 5 4/23 4/25 4503599627370496/2589569785738035 6 0 0 0 7 34/23 34/25 38280596832649216/2589569785738035 8 32/161 32/175 36028797018963968/18126988500166245 9 31/23 31/25 34902897112121344/2589569785738035 10 11 NA NA NA 12 -3/23 -3/25 -1125899906842624/863189928579345 -4. 4L 0. 34_Z 1 -23/4 23/4 error 23/34 2 -25/4 25/4 error 25/34 3 -2589569785738035/4503599627370496 2589569785738035/4503599627370496 error 2589569785738035/38280596832649216 4 1 -1 error -2/17 5 -1 1 error 2/17 6 0 0 error 0 7 -17/2 17/2 error 1 8 -8/7 8/7 error 16/119 9 -31/4 31/4 error 31/34 10 11 NA NA NA NA 12 3/4 -3/4 error -3/34 32/7 (31 %% 45) NULL NA -3L 1 161/32 23/31 NA -23/3 2 175/32 25/31 NA -25/3 3 18126988500166245/36028797018963968 2589569785738035/34902897112121344 NA -863189928579345/1125899906842624 4 -7/8 -4/31 NA 4/3 5 7/8 4/31 NA -4/3 6 0 0 NA 0 7 119/16 34/31 NA -34/3 8 1 32/217 NA -32/21 9 217/32 1 NA -31/3 10 11 NA NA NA NA 12 -21/32 -3/31 NA 1 ------------------------------------------ mul.bigq -> num.fn.: * -> all.equal(target = res, current = F()): 23. 25 1 529 575 2 575 625 3 59560105071974805/1125899906842624 64739244643450875/1125899906842624 4 -92 -100 5 92 100 6 0 0 7 782 850 8 736/7 800/7 9 713 775 10 11 NA NA 12 -69 -75 2.3 -4. 1 59560105071974805/1125899906842624 -92 2 64739244643450875/1125899906842624 -100 3 6705871675207332498089645661225/1267650600228229401496703205376 -2589569785738035/281474976710656 4 -2589569785738035/281474976710656 16 5 2589569785738035/281474976710656 -16 6 0 0 7 44022686357546595/562949953421312 -136 8 2589569785738035/246290604621824 -128/7 9 80276663357879085/1125899906842624 -124 10 11 NA NA 12 -7768709357214105/1125899906842624 12 4L 0. 34_Z 32/7 1 92 0 782 736/7 2 100 0 850 800/7 3 2589569785738035/281474976710656 0 44022686357546595/562949953421312 2589569785738035/246290604621824 4 -16 0 -136 -128/7 5 16 0 136 128/7 6 0 0 0 0 7 136 0 1156 1088/7 8 128/7 0 1088/7 1024/49 9 124 0 1054 992/7 10 11 NA NA NA NA 12 -12 0 -102 -96/7 (31 %% 45) NULL NA -3L 1 713 NA -69 2 775 NA -75 3 80276663357879085/1125899906842624 NA -7768709357214105/1125899906842624 4 -124 NA 12 5 124 NA -12 6 0 NA 0 7 1054 NA -102 8 992/7 NA -96/7 9 961 NA -93 10 11 NA NA NA 12 -93 NA 9 ------------------------------------------ pow.bigq -> num.fn.: ^ -> all.equal(target = res, current = F()): 23. 1 20880467999847912034355032910567 2 142108547152020037174224853515625 3 3193267066726519048024192216637055127345435527507969872464125269470059286635690056577798125781909527810376124991657578351679738651102730620756661966927725302014424563645174067521149296951817172162659710933905232201861139535639770451240923886107589858621996997021980283938508630500856543753576433647630287667125834181740141064461894579190528392791748046875/15293081873211767368008098429801431702283953435860199762548849392729924449022989580446715984539492948078961126718377261636114752088759037662583404222552656421516118242870155513277445799253988599903013203035456980522029444518708424647262033039075005711224960492468690967906200650878912999528261427142481809365636558292208635816169529602354261786624 4 -70368744177664 5 70368744177664 6 0 7 167500108222301408246337399112597504 8 41538374868278621028243970633760768/27368747340080916343 9 20013311644049280264138724244295391 10 11 NA 12 -94143178827 25 1 11045767571919545466173812409689943 2 88817841970012523233890533447265625 3 21413639174133767093505199715038044466889478084427543014054373353606799973999555952463354291023438787520381906929026918045391637112947382715526121906606283112604854466945907623131972373435188891715298513556332721312474275624288596793752238253786597460093767539962333897980041388322455011164388818122854663154832902275480961648169795509698874173270150359260851124999167621135711669921875/19386284415916351754079089178450564925773557736103804419411555585271880141782314140372424277909703897018770899538474171965166118458515899084769015397275464167677107284570523250425575952346592304246424549348074591181601727656179068362270484463196732647218460003493653290976614849694549301017494559084845337731890794268139677171965009511882361078407710175469865837534369361690624 4 -1125899906842624 5 1125899906842624 6 0 7 193630125104980427932766033374162714624 8 42535295865117307932921825928971026432/1341068619663964900807 9 19232792489931358333837313998767870751 10 11 NA 12 -847288609443 2.3 1 error 2 error 3 error 4 error 5 error 6 error 7 error 8 error 9 error 10 error 11 error 12 error -4. 1 1/279841 2 1/390625 3 1606938044258990275541962092341162602522202993782792835301376/44968714924347995877535679665554839525511318324676467468500625 4 1/256 5 1/256 6 error 7 1/1336336 8 2401/1048576 9 1/923521 10 11 NA 12 1/81 4L 1 279841 2 390625 3 44968714924347995877535679665554839525511318324676467468500625/1606938044258990275541962092341162602522202993782792835301376 4 256 5 256 6 0 7 1336336 8 1048576/2401 9 923521 10 11 NA 12 81 0. 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 11 1 12 1 34_Z 1 19895113660064588580108197261066338165074766609 2 338813178901720135627329000271856784820556640625 3 112134448995806412223041531252325689689434241773129463856194924775065849993758927138248448857451881852778079174438072439871541372725357277611100220662048533548249623049759821537528960265127944408702031659222970104299168038907323334285583711071763179197558648442268059107299162467637345454729356013444236833673458037376330404465353413816666461156176812757297147723235699476344863071169788486411354939505382833362638884485793706579289250006900870855295005402423945646154983524016500090061373872294270927668549120426177978515625/56362808934785782620655415167470525914030964411108314940402423418609289689068355355971379591897745173403010078263747529856646401949852539644969848434700186501722593132609102394906926373262117075563330306831364144677433787178189964179613588058505555939250641616528896329618001580624087604790707070002646363767810376024580461947390375276158858357529962546338406854636102805723631292609311399696875316557143945391102311532165688506692261634047197324706752950818927815472385992693228752306187618995383028460736741376 4 295147905179352825856 5 295147905179352825856 6 0 7 11756638905368616011414050501310355554617941909569536 8 1496577676626844588240573268701473812127674924007424/54116956037952111668959660849 9 508507766528375922442969666478706045897328683433921 10 11 NA 12 16677181699666569 32/7 1 error 2 error 3 error 4 error 5 error 6 error 7 error 8 error 9 error 10 error 11 error 12 error (31 %% 45) 1 1635170022196481349560959748587682926364327 2 21684043449710088680149056017398834228515625 3 6457377791392006557478029861340380899980883396368749497071832981130275005352780281695929173658945727227744211636413193439375434941648200428740338769083266862010019025750071845902931188020684290332892454276403765729426560499995092449502754877647053541693992616699747606257147008431498447928301034336091380849646794283682340353822227453060517405971707864776112424801887309632528462559345195432215569765847613620879506822246726376929203559303019591376134041431359946727752685546875/39490558802674197931296630473167898425951735774342167779076915840045177103840103639762289034974757677685944586746069070444337839780576597196302139193602451889442215352428547682644493564603293690705437378762962043823674914535908951809415366608478338498524211467752254302281291452934019947098835582448203700148125189885486562395000537277444234446120215967349161881024795172481378405277942805379045378986156134350730656132398629069223417026989801256665165993399365402624 4 -4611686018427387904 5 4611686018427387904 6 0 7 299120672332806228664106719451209941853702979584 8 45671926166590716193865151022383844364247891968/157775382034845806615042743 9 17069174130723235958610643029059314756044734431 10 11 NA 12 -617673396283947 NULL NA -3L 1 NA 1/12167 2 NA 1/15625 3 NA 1427247692705959881058285969449495136382746624/17365322677153409849313160265892197722207192875 4 NA -1/64 5 NA 1/64 6 NA error 7 NA 1/39304 8 NA 343/32768 9 NA 1/29791 10 11 NA NA 12 NA -1/27 ------------------------------------------ chooseZ -> num.fn.: choose -> all.equal(target = res, current = F()): 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 1 0 253 0 8855 1 0 8855 0 0 0 2 300 1 300 0 12650 1 0 12650 0 0 0 3 0 0 1 0 0 1 0 0 0 0 0 4 -2600 -3276 10 0 35 1 7770 35 -5984 0 0 5 0 0 6 0 1 1 0 1 0 0 0 6 0 0 0 0 0 1 0 0 0 0 0 7 286097760 52451256 561 0 46376 1 1 46376 5984 0 0 8 28048800 3365856 496 0 35960 1 0 35960 32 0 0 9 7888725 736281 465 0 31465 1 0 31465 1 0 0 10 11 0 0 0 0 0 1 0 0 0 0 0 12 -300 -351 6 0 15 1 630 15 -528 0 0 ------------------------------------------ max.bigq -> num.fn.: max -> all.equal(target = res, current = F()): 23. 25 2.3 -4. 4L 0. 34_Z 1 23 25 23 23 23 23 34 2 25 25 25 25 25 25 34 3 23 25 2589569785738035/1125899906842624 2589569785738035/1125899906842624 4 2589569785738035/1125899906842624 34 4 23 25 2589569785738035/1125899906842624 -4 4 0 34 5 23 25 4 4 4 4 34 6 23 25 2589569785738035/1125899906842624 0 4 0 34 7 34 34 34 34 34 34 34 8 23 25 32/7 32/7 32/7 32/7 34 9 31 31 31 31 31 31 34 10 23 25 2589569785738035/1125899906842624 -4 4 0 34 11 23 25 2589569785738035/1125899906842624 -4 4 0 34 12 23 25 2589569785738035/1125899906842624 -3 4 0 34 32/7 (31 %% 45) NULL NA -3L 1 23 31 23 23 2 25 31 25 25 3 32/7 31 2589569785738035/1125899906842624 2589569785738035/1125899906842624 4 32/7 31 -4 -3 5 32/7 31 4 4 6 32/7 31 0 0 7 34 34 34 34 8 32/7 31 32/7 32/7 9 31 31 31 31 10 32/7 31 NA -3 11 32/7 31 NA -3 12 32/7 31 -3 -3 ------------------------------------------ max.bigz -> num.fn.: max -> all.equal(target = res, current = F()): 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 23 25 23 23 23 23 34 23 31 23 23 2 25 25 25 25 25 25 34 25 31 25 25 3 23 25 2 2 4 2 34 32/7 31 2 2 4 23 25 2 -4 4 0 34 32/7 31 -4 -3 5 23 25 4 4 4 4 34 32/7 31 4 4 6 23 25 2 0 4 0 34 32/7 31 0 0 7 34 34 34 34 34 34 34 34 34 34 34 8 23 25 32/7 32/7 32/7 32/7 34 32/7 31 32/7 32/7 9 (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) (34 %% 45) 31 (31 %% 45) (31 %% 45) (31 %% 45) 10 23 25 2 -4 4 0 34 32/7 (31 %% 45) NA -3 11 23 25 2 -4 4 0 34 32/7 31 NA -3 12 23 25 2 -3 4 0 34 32/7 31 -3 -3 ------------------------------------------ min.bigq -> num.fn.: min -> all.equal(target = res, current = F()): 23. 25 2.3 -4. 1 23 23 2589569785738035/1125899906842624 -4 2 23 25 2589569785738035/1125899906842624 -4 3 2589569785738035/1125899906842624 2589569785738035/1125899906842624 2589569785738035/1125899906842624 -4 4 -4 -4 -4 -4 5 4 4 2589569785738035/1125899906842624 -4 6 0 0 0 -4 7 23 25 2589569785738035/1125899906842624 -4 8 32/7 32/7 2589569785738035/1125899906842624 -4 9 23 25 2589569785738035/1125899906842624 -4 10 23 25 2589569785738035/1125899906842624 -4 11 23 25 2589569785738035/1125899906842624 -4 12 -3 -3 -3 -4 4L 0. 34_Z 32/7 1 4 0 23 32/7 2 4 0 25 32/7 3 2589569785738035/1125899906842624 0 2589569785738035/1125899906842624 2589569785738035/1125899906842624 4 -4 -4 -4 -4 5 4 0 4 4 6 0 0 0 0 7 4 0 34 32/7 8 4 0 32/7 32/7 9 4 0 31 32/7 10 4 0 34 32/7 11 4 0 34 32/7 12 -3 -3 -3 -3 (31 %% 45) NULL NA -3L 1 23 23 -3 2 25 25 -3 3 2589569785738035/1125899906842624 2589569785738035/1125899906842624 -3 4 -4 -4 -4 5 4 4 -3 6 0 0 -3 7 31 34 -3 8 32/7 32/7 -3 9 31 31 -3 10 31 NA -3 11 31 NA -3 12 -3 -3 -3 ------------------------------------------ min.bigz -> num.fn.: min -> all.equal(target = res, current = F()): 23. 25 2.3 -4. 4L 0. 34_Z 1 23 23 2 -4 4 0 23 2 23 25 2 -4 4 0 25 3 2 2 2 -4 2 0 2 4 -4 -4 -4 -4 -4 -4 -4 5 4 4 2 -4 4 0 4 6 0 0 0 -4 0 0 0 7 23 25 2 -4 4 0 34 8 32/7 32/7 2589569785738035/1125899906842624 -4 4 0 32/7 9 (23 %% 45) (25 %% 45) (2 %% 45) (-4 %% 45) (4 %% 45) (0 %% 45) (31 %% 45) 10 23 25 2 -4 4 0 34 11 23 25 2 -4 4 0 34 12 -3 -3 -3 -4 -3 -3 -3 32/7 (31 %% 45) NULL NA -3L 1 32/7 23 23 -3 2 32/7 25 25 -3 3 2589569785738035/1125899906842624 2 2 -3 4 -4 -4 -4 -4 5 4 4 4 -3 6 0 0 0 -3 7 32/7 31 34 -3 8 32/7 32/7 32/7 -3 9 32/7 (31 %% 45) (31 %% 45) (-3 %% 45) 10 32/7 (31 %% 45) NA -3 11 32/7 31 NA -3 12 -3 -3 -3 -3 There were 50 or more warnings (use warnings() to see the first 50) > > ##============================================================================== > > 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.bigz 23. 25 2.3 -4. 4L 0. 34_Z 32/7 1 3.13549421592915 3.2188758248682 0.693147180559945 NaN 1.38629436111989 -Inf 3.52636052461616 3.46573590279973 (31 %% 45) NULL NA -3L 1 3.43398720448515 -Inf NaN ------------------------------------------ log2.bigz 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 4.52356195605701 4.64385618977472 1 NaN 2 -Inf 5.08746284125034 5 4.95419631038687 -Inf NaN ------------------------------------------ log10.bigz 23. 25 2.3 -4. 4L 0. 34_Z 32/7 1 1.36172783601759 1.39794000867204 0.301029995663981 NaN 0.602059991327962 -Inf 1.53147891704225 1.50514997831991 (31 %% 45) NULL NA -3L 1 1.49136169383427 -Inf NaN ------------------------------------------ c.bigz 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 23 25 2 -4 4 0 34 32/7 (31 %% 45) NA -3 ------------------------------------------ isprime 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 2 0 2 0 0 0 0 0 2 0 2 ------------------------------------------ nextprime 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 29 29 3 2 5 2 37 37 37 2 2 ------------------------------------------ factorialZ 23. 25 2.3 -4. 4L 0. 34_Z 32/7 1 25852016738884976640000 15511210043330985984000000 2 0 24 1 295232799039604140847618609643520000000 24 (31 %% 45) NULL NA -3L 1 8222838654177922817725562880000000 0 0 ------------------------------------------ sizeinbase 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 2 2 1 1 1 1 2 2 2 1 1 ------------------------------------------ fibnum 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 28657 75025 1 error 3 0 5702887 3 1346269 error error ------------------------------------------ fibnum2 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 17711 46368 1 error 2 1 3524578 2 832040 error error error ------------------------------------------ lucnum 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 64079 167761 3 error 7 2 12752043 7 3010349 error error ------------------------------------------ lucnum2 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 39603 103682 1 error 4 -1 7881196 4 1860498 error error error ------------------------------------------ factorize 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 23 5 2 -1 2 error 2 2 31 error -1 ------------------------------------------ abs 23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA -3L 1 23 error 2.3 4 4 0 34 32/7 (31 %% 45) error 3 > > ##============================================================================== > > ###----------- 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 > > proc.time() user system elapsed 0.380 0.069 0.487 gmp/tests/basic-ex.R0000644000175000017500000001635413735324616014172 0ustar nileshnileshlibrary(gmp) ## From ~/R/Pkgs/Matrix/inst/test-tools-1.R -- only for R <= 3.0.1 -- ##' @title Ensure evaluating 'expr' signals an error ##' @param expr ##' @return the caught error, invisibly ##' @author Martin Maechler assertError <- function(expr, verbose=getOption("verbose")) { d.expr <- deparse(substitute(expr)) t.res <- tryCatch(expr, error = function(e) e) if(!inherits(t.res, "error")) stop(d.expr, "\n\t did not give an error", call. = FALSE) if(verbose) cat("Asserted Error:", conditionMessage(t.res),"\n") invisible(t.res) } 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)) gmp/tests/gmp-test.R0000644000175000017500000001340513667642073014235 0ustar nileshnileshlibrary(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 ## FIXME res <- matrix(res, nr, n, dimnames = list(if(!unary) xlabs, xlabs)) ## for now res <- matrix(res, nr, n, dimnames = list(NULL, xlabs)) for(i in 1:nr) for(j in 1:n) { e <- if(unary) try(FUN(x[[j]]), silent = TRUE) else try(FUN(x[[i]],x[[j]]), silent = TRUE) if(inherits(e, "try-error")) e <- error else if(length(e) == 0) e <- numeric() ## ## now, for some functions also compute the corresponding numeric values ## d <- if(unary) try(FUN(as.numeric(x[[j]])), silent = TRUE) else ## try(FUN(as.numeric(x[[i]]),as.numeric(x[[j]])), silent = TRUE) res[i,j] <- sortie(e)[1] } res ## for printing, the user may prefer as.data.frame(.) }## end{test} allfunctionid <- c("as.bigz","add.bigz","sub.bigz","mul.bigz", "divq.bigz","div.bigz","mod.bigz","pow.bigz", "inv.bigz", "gcd.bigz", "gcdex", "lcm.bigz", "as.bigq", "add.bigq","sub.bigq","div.bigq", "mul.bigq", "pow.bigq", "chooseZ", "max.bigq","max.bigz","min.bigq","min.bigz") unaryfunctionid <- c("log.bigz","log2.bigz","log10.bigz","c.bigz", "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 = 125) sapply(allfunctionid, numericFunName) sapply(unaryfunctionid, numericFunName) ex <- expression(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(.) is.null(.) || is.na(.) || (is.finite(as.numeric(.)) && (!inherits(., "bigz") || is.null(modulus(.))))) ## names(x) <- sapply(ex, format) ## shorter & easier: 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, "\n\n", sep="") 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) cat("\n-> all.equal(target = res, current = F()):\n") nres <- test(FUN, nx, out = "numeric") # print(all.equal(res, nres)) } else cat("\n\n") print(as.data.frame(rc)); cat("\n") ## ^^^^^^^^^^^^^ (for now, to diminuish difference to last version ) } ##============================================================================== 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) gmp/ChangeLog0000644000175000017500000001507613775600636012767 0ustar nileshnilesh2021-01-07 Martin Maechler * configure.ac: add definitions of CFLAGS etc as from R, from a suggestion by Kaspar Daniel Hansen. 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/configure0000755000175000017500000043373514140270010013102 0ustar nileshnilesh#! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.71. # # # Copyright (C) 1992-1996, 1998-2017, 2020-2021 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 as_nop=: if test ${ZSH_VERSION+y} && (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 $as_nop case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi # Reset variables that may have inherited troublesome values from # the environment. # IFS needs to be set, to space, tab, and newline, in precisely that order. # (If _AS_PATH_WALK were called with IFS unset, it would have the # side effect of setting IFS to empty, thus disabling word splitting.) # Quoting is to prevent editors from complaining about space-tab. as_nl=' ' export as_nl IFS=" "" $as_nl" PS1='$ ' PS2='> ' PS4='+ ' # Ensure predictable behavior from utilities with locale-dependent output. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # We cannot yet rely on "unset" to work, but we need these variables # to be unset--not just set to an empty or harmless value--now, to # avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct # also avoids known problems related to "unset" and subshell syntax # in other old shells (e.g. bash 2.01 and pdksh 5.2.14). for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH do eval test \${$as_var+y} \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done # Ensure that fds 0, 1, and 2 are open. if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi if (exec 3>&2) ; then :; else exec 2>/dev/null; fi # The user is always right. if ${PATH_SEPARATOR+false} :; 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 # 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 case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac 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 printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # 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'. printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 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="as_nop=: if test \${ZSH_VERSION+y} && (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 \$as_nop 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 \$as_nop exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 blah=\$(echo \$(echo blah)) test x\"\$blah\" = xblah || 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" if (eval "$as_required") 2>/dev/null then : as_have_required=yes else $as_nop as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null then : else $as_nop 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 case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac 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_run=a "$as_shell" -c "$as_bourne_compatible""$as_required" 2>/dev/null then : CONFIG_SHELL=$as_shell as_have_required=yes if as_run=a "$as_shell" -c "$as_bourne_compatible""$as_suggested" 2>/dev/null then : break 2 fi fi done;; esac as_found=false done IFS=$as_save_IFS if $as_found then : else $as_nop if { test -f "$SHELL" || test -f "$SHELL.exe"; } && as_run=a "$SHELL" -c "$as_bourne_compatible""$as_required" 2>/dev/null then : CONFIG_SHELL=$SHELL as_have_required=yes fi fi 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'. printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi if test x$as_have_required = xno then : printf "%s\n" "$0: This script requires a shell more modern than all" printf "%s\n" "$0: the shells that I found on your system." if test ${ZSH_VERSION+y} ; then printf "%s\n" "$0: In particular, zsh $ZSH_VERSION has bugs and should" printf "%s\n" "$0: be upgraded to zsh 4.3.4 or later." else printf "%s\n" "$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_nop # --------- # Do nothing but, unlike ":", preserve the value of $?. as_fn_nop () { return $? } as_nop=as_fn_nop # 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=`printf "%s\n" "$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 || printf "%s\n" 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_nop 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_nop as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith # as_fn_nop # --------- # Do nothing but, unlike ":", preserve the value of $?. as_fn_nop () { return $? } as_nop=as_fn_nop # 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 printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi printf "%s\n" "$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 || printf "%s\n" 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" || { printf "%s\n" "$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 } # Determine whether it's possible to make 'echo' print without a newline. # These variables are no longer used directly by Autoconf, but are AC_SUBSTed # for compatibility with existing Makefiles. 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 # For backward compatibility with old third-party macros, we provide # the shell variables $as_echo and $as_echo_n. New code should use # AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. as_echo='printf %s\n' as_echo_n='printf %s' 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" ac_subst_vars='LTLIBOBJS LIBOBJS PKG_LIBS PKG_CPPFLAGS 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 ' 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 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=`printf "%s\n" "$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=`printf "%s\n" "$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=`printf "%s\n" "$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=`printf "%s\n" "$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. printf "%s\n" "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && printf "%s\n" "$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" ;; *) printf "%s\n" "$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 || printf "%s\n" 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 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=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`printf "%s\n" "$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 configure.gnu first; this name is used for a wrapper for # Metaconfig's "Configure" on case-insensitive file systems. 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 printf "%s\n" "$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.71 Copyright (C) 2021 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 conftest.beam 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\"" printf "%s\n" "$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 printf "%s\n" "$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_nop printf "%s\n" "$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\"" printf "%s\n" "$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 printf "%s\n" "$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_nop printf "%s\n" "$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 conftest.beam 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\"" printf "%s\n" "$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 printf "%s\n" "$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_nop printf "%s\n" "$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_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.beam 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\"" printf "%s\n" "$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 printf "%s\n" "$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_nop printf "%s\n" "$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 ac_configure_args_raw= for ac_arg do case $ac_arg in *\'*) ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac as_fn_append ac_configure_args_raw " '$ac_arg'" done case $ac_configure_args_raw in *$as_nl*) ac_safe_unquote= ;; *) ac_unsafe_z='|&;<>()$`\\"*?[ '' ' # This string ends in space, tab. ac_unsafe_a="$ac_unsafe_z#~" ac_safe_unquote="s/ '\\([^$ac_unsafe_a][^$ac_unsafe_z]*\\)'/ \\1/g" ac_configure_args_raw=` printf "%s\n" "$ac_configure_args_raw" | sed "$ac_safe_unquote"`;; esac 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.71. Invocation command line was $ $0$ac_configure_args_raw _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 case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac printf "%s\n" "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=`printf "%s\n" "$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=$? # Sanitize IFS. IFS=" "" $as_nl" # Save into config.log some information that might help in debugging. { echo printf "%s\n" "## ---------------- ## ## 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_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 printf "%s\n" "$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 printf "%s\n" "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac printf "%s\n" "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then printf "%s\n" "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac printf "%s\n" "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then printf "%s\n" "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && printf "%s\n" "$as_me: caught signal $ac_signal" printf "%s\n" "$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 printf "%s\n" "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. printf "%s\n" "#define PACKAGE_NAME \"$PACKAGE_NAME\"" >>confdefs.h printf "%s\n" "#define PACKAGE_TARNAME \"$PACKAGE_TARNAME\"" >>confdefs.h printf "%s\n" "#define PACKAGE_VERSION \"$PACKAGE_VERSION\"" >>confdefs.h printf "%s\n" "#define PACKAGE_STRING \"$PACKAGE_STRING\"" >>confdefs.h printf "%s\n" "#define PACKAGE_BUGREPORT \"$PACKAGE_BUGREPORT\"" >>confdefs.h printf "%s\n" "#define PACKAGE_URL \"$PACKAGE_URL\"" >>confdefs.h # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. if test -n "$CONFIG_SITE"; then ac_site_files="$CONFIG_SITE" elif test "x$prefix" != xNONE; then ac_site_files="$prefix/share/config.site $prefix/etc/config.site" else ac_site_files="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" fi for ac_site_file in $ac_site_files do case $ac_site_file in #( */*) : ;; #( *) : ac_site_file=./$ac_site_file ;; esac if test -f "$ac_site_file" && test -r "$ac_site_file"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 printf "%s\n" "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 printf "%s\n" "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 printf "%s\n" "$as_me: creating cache $cache_file" >&6;} >$cache_file fi # Test code for whether the C compiler supports C89 (global declarations) ac_c_conftest_c89_globals=' /* Does the compiler advertise C89 conformance? Do not test the value of __STDC__, because some compilers set it to 0 while being otherwise adequately conformant. */ #if !defined __STDC__ # error "Compiler does not advertise C89 conformance" #endif #include #include struct stat; /* Most of the following tests are stolen from RCS 5.7 src/conf.sh. */ struct buf { int x; }; struct buf * (*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 do not provoke an error unfortunately, instead are silently treated as an "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 is necessary to write \x00 == 0 to get something that is 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 **, int *(*)(struct buf *, struct stat *, int), int, int);' # Test code for whether the C compiler supports C89 (body of main). ac_c_conftest_c89_main=' ok |= (argc == 0 || f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]); ' # Test code for whether the C compiler supports C99 (global declarations) ac_c_conftest_c99_globals=' // Does the compiler advertise C99 conformance? #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L # error "Compiler does not advertise C99 conformance" #endif #include extern int puts (const char *); extern int printf (const char *, ...); extern int dprintf (int, const char *, ...); extern void *malloc (size_t); // Check varargs macros. These examples are taken from C99 6.10.3.5. // dprintf is used instead of fprintf to avoid needing to declare // FILE and stderr. #define debug(...) dprintf (2, __VA_ARGS__) #define showlist(...) puts (#__VA_ARGS__) #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__)) static void test_varargs_macros (void) { int x = 1234; int y = 5678; debug ("Flag"); debug ("X = %d\n", x); showlist (The first, second, and third items.); report (x>y, "x is %d but y is %d", x, y); } // Check long long types. #define BIG64 18446744073709551615ull #define BIG32 4294967295ul #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0) #if !BIG_OK #error "your preprocessor is broken" #endif #if BIG_OK #else #error "your preprocessor is broken" #endif static long long int bignum = -9223372036854775807LL; static unsigned long long int ubignum = BIG64; struct incomplete_array { int datasize; double data[]; }; struct named_init { int number; const wchar_t *name; double average; }; typedef const char *ccp; static inline int test_restrict (ccp restrict text) { // See if C++-style comments work. // Iterate through items via the restricted pointer. // Also check for declarations in for loops. for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i) continue; return 0; } // Check varargs and va_copy. static bool test_varargs (const char *format, ...) { va_list args; va_start (args, format); va_list args_copy; va_copy (args_copy, args); const char *str = ""; int number = 0; float fnumber = 0; while (*format) { switch (*format++) { case '\''s'\'': // string str = va_arg (args_copy, const char *); break; case '\''d'\'': // int number = va_arg (args_copy, int); break; case '\''f'\'': // float fnumber = va_arg (args_copy, double); break; default: break; } } va_end (args_copy); va_end (args); return *str && number && fnumber; } ' # Test code for whether the C compiler supports C99 (body of main). ac_c_conftest_c99_main=' // Check bool. _Bool success = false; success |= (argc != 0); // Check restrict. if (test_restrict ("String literal") == 0) success = true; char *restrict newvar = "Another string"; // Check varargs. success &= test_varargs ("s, d'\'' f .", "string", 65, 34.234); test_varargs_macros (); // Check flexible array members. struct incomplete_array *ia = malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10)); ia->datasize = 10; for (int i = 0; i < ia->datasize; ++i) ia->data[i] = i * 1.234; // Check named initializers. struct named_init ni = { .number = 34, .name = L"Test wide string", .average = 543.34343, }; ni.number = 58; int dynamic_array[ni.number]; dynamic_array[0] = argv[0][0]; dynamic_array[ni.number - 1] = 543; // work around unused variable warnings ok |= (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == '\''x'\'' || dynamic_array[ni.number - 1] != 543); ' # Test code for whether the C compiler supports C11 (global declarations) ac_c_conftest_c11_globals=' // Does the compiler advertise C11 conformance? #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L # error "Compiler does not advertise C11 conformance" #endif // Check _Alignas. char _Alignas (double) aligned_as_double; char _Alignas (0) no_special_alignment; extern char aligned_as_int; char _Alignas (0) _Alignas (int) aligned_as_int; // Check _Alignof. enum { int_alignment = _Alignof (int), int_array_alignment = _Alignof (int[100]), char_alignment = _Alignof (char) }; _Static_assert (0 < -_Alignof (int), "_Alignof is signed"); // Check _Noreturn. int _Noreturn does_not_return (void) { for (;;) continue; } // Check _Static_assert. struct test_static_assert { int x; _Static_assert (sizeof (int) <= sizeof (long int), "_Static_assert does not work in struct"); long int y; }; // Check UTF-8 literals. #define u8 syntax error! char const utf8_literal[] = u8"happens to be ASCII" "another string"; // Check duplicate typedefs. typedef long *long_ptr; typedef long int *long_ptr; typedef long_ptr long_ptr; // Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1. struct anonymous { union { struct { int i; int j; }; struct { int k; long int l; } w; }; int m; } v1; ' # Test code for whether the C compiler supports C11 (body of main). ac_c_conftest_c11_main=' _Static_assert ((offsetof (struct anonymous, i) == offsetof (struct anonymous, w.k)), "Anonymous union alignment botch"); v1.i = 2; v1.w.k = 5; ok |= v1.i != 5; ' # Test code for whether the C compiler supports C11 (complete). ac_c_conftest_c11_program="${ac_c_conftest_c89_globals} ${ac_c_conftest_c99_globals} ${ac_c_conftest_c11_globals} int main (int argc, char **argv) { int ok = 0; ${ac_c_conftest_c89_main} ${ac_c_conftest_c99_main} ${ac_c_conftest_c11_main} return ok; } " # Test code for whether the C compiler supports C99 (complete). ac_c_conftest_c99_program="${ac_c_conftest_c89_globals} ${ac_c_conftest_c99_globals} int main (int argc, char **argv) { int ok = 0; ${ac_c_conftest_c89_main} ${ac_c_conftest_c99_main} return ok; } " # Test code for whether the C compiler supports C89 (complete). ac_c_conftest_c89_program="${ac_c_conftest_c89_globals} int main (int argc, char **argv) { int ok = 0; ${ac_c_conftest_c89_main} return ok; } " # Test code for whether the C++ compiler supports C++98 (global declarations) ac_cxx_conftest_cxx98_globals=' // Does the compiler advertise C++98 conformance? #if !defined __cplusplus || __cplusplus < 199711L # error "Compiler does not advertise C++98 conformance" #endif // These inclusions are to reject old compilers that // lack the unsuffixed header files. #include #include // and are *not* freestanding headers in C++98. extern void assert (int); namespace std { extern int strcmp (const char *, const char *); } // Namespaces, exceptions, and templates were all added after "C++ 2.0". using std::exception; using std::strcmp; namespace { void test_exception_syntax() { try { throw "test"; } catch (const char *s) { // Extra parentheses suppress a warning when building autoconf itself, // due to lint rules shared with more typical C programs. assert (!(strcmp) (s, "test")); } } template struct test_template { T const val; explicit test_template(T t) : val(t) {} template T add(U u) { return static_cast(u) + val; } }; } // anonymous namespace ' # Test code for whether the C++ compiler supports C++98 (body of main) ac_cxx_conftest_cxx98_main=' assert (argc); assert (! argv[0]); { test_exception_syntax (); test_template tt (2.0); assert (tt.add (4) == 6.0); assert (true && !false); } ' # Test code for whether the C++ compiler supports C++11 (global declarations) ac_cxx_conftest_cxx11_globals=' // Does the compiler advertise C++ 2011 conformance? #if !defined __cplusplus || __cplusplus < 201103L # error "Compiler does not advertise C++11 conformance" #endif namespace cxx11test { constexpr int get_val() { return 20; } struct testinit { int i; double d; }; class delegate { public: delegate(int n) : n(n) {} delegate(): delegate(2354) {} virtual int getval() { return this->n; }; protected: int n; }; class overridden : public delegate { public: overridden(int n): delegate(n) {} virtual int getval() override final { return this->n * 2; } }; class nocopy { public: nocopy(int i): i(i) {} nocopy() = default; nocopy(const nocopy&) = delete; nocopy & operator=(const nocopy&) = delete; private: int i; }; // for testing lambda expressions template Ret eval(Fn f, Ret v) { return f(v); } // for testing variadic templates and trailing return types template auto sum(V first) -> V { return first; } template auto sum(V first, Args... rest) -> V { return first + sum(rest...); } } ' # Test code for whether the C++ compiler supports C++11 (body of main) ac_cxx_conftest_cxx11_main=' { // Test auto and decltype auto a1 = 6538; auto a2 = 48573953.4; auto a3 = "String literal"; int total = 0; for (auto i = a3; *i; ++i) { total += *i; } decltype(a2) a4 = 34895.034; } { // Test constexpr short sa[cxx11test::get_val()] = { 0 }; } { // Test initializer lists cxx11test::testinit il = { 4323, 435234.23544 }; } { // Test range-based for int array[] = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1}; for (auto &x : array) { x += 23; } } { // Test lambda expressions using cxx11test::eval; assert (eval ([](int x) { return x*2; }, 21) == 42); double d = 2.0; assert (eval ([&](double x) { return d += x; }, 3.0) == 5.0); assert (d == 5.0); assert (eval ([=](double x) mutable { return d += x; }, 4.0) == 9.0); assert (d == 5.0); } { // Test use of variadic templates using cxx11test::sum; auto a = sum(1); auto b = sum(1, 2); auto c = sum(1.0, 2.0, 3.0); } { // Test constructor delegation cxx11test::delegate d1; cxx11test::delegate d2(); cxx11test::delegate d3(45); } { // Test override and final cxx11test::overridden o1(55464); } { // Test nullptr char *c = nullptr; } { // Test template brackets test_template<::test_template> v(test_template(12)); } { // Unicode literals char const *utf8 = u8"UTF-8 string \u2500"; char16_t const *utf16 = u"UTF-8 string \u2500"; char32_t const *utf32 = U"UTF-32 string \u2500"; } ' # Test code for whether the C compiler supports C++11 (complete). ac_cxx_conftest_cxx11_program="${ac_cxx_conftest_cxx98_globals} ${ac_cxx_conftest_cxx11_globals} int main (int argc, char **argv) { int ok = 0; ${ac_cxx_conftest_cxx98_main} ${ac_cxx_conftest_cxx11_main} return ok; } " # Test code for whether the C compiler supports C++98 (complete). ac_cxx_conftest_cxx98_program="${ac_cxx_conftest_cxx98_globals} int main (int argc, char **argv) { int ok = 0; ${ac_cxx_conftest_cxx98_main} return ok; } " # 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,) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 printf "%s\n" "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 printf "%s\n" "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 printf "%s\n" "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 printf "%s\n" "$as_me: former value: \`$ac_old_val'" >&2;} { printf "%s\n" "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 printf "%s\n" "$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=`printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 printf "%s\n" "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`${MAKE-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 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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 else $as_nop 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 case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac 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" printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 printf "%s\n" "$CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_CC+y} then : printf %s "(cached) " >&6 else $as_nop 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 case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac 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" printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 printf "%s\n" "$ac_ct_CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 else $as_nop 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 case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac 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" printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 printf "%s\n" "$CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 else $as_nop 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 case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac 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" printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 printf "%s\n" "$CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 else $as_nop 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 case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac 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" printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 printf "%s\n" "$CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_CC+y} then : printf %s "(cached) " >&6 else $as_nop 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 case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac 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" printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 printf "%s\n" "$ac_ct_CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "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:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi fi fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}clang", so it can be a program name with args. set dummy ${ac_tool_prefix}clang; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 else $as_nop 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 case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac 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}clang" printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 printf "%s\n" "$CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_CC"; then ac_ct_CC=$CC # Extract the first word of "clang", so it can be a program name with args. set dummy clang; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_CC+y} then : printf %s "(cached) " >&6 else $as_nop 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 case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac 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="clang" printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 printf "%s\n" "$ac_ct_CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$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 fi test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$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. printf "%s\n" "$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 -version; 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\"" printf "%s\n" "$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 printf "%s\n" "$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 (void) { ; 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. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 printf %s "checking whether the C compiler works... " >&6; } ac_link_default=`printf "%s\n" "$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\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? printf "%s\n" "$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+y} && 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 $as_nop ac_file='' fi if test -z "$ac_file" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$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_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 printf %s "checking for C compiler default output file name... " >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 printf %s "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\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? printf "%s\n" "$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_nop { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 printf "%s\n" "$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 (void) { 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. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 printf %s "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\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? printf "%s\n" "$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\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? printf "%s\n" "$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 { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot run C compiled programs. If you meant to cross compile, use \`--host'. See \`config.log' for more details" "$LINENO" 5; } fi fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 printf "%s\n" "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out ac_clean_files=$ac_clean_files_save { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 printf %s "checking for suffix of object files... " >&6; } if test ${ac_cv_objext+y} then : printf %s "(cached) " >&6 else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; 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\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? printf "%s\n" "$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_nop printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 printf "%s\n" "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C" >&5 printf %s "checking whether the compiler supports GNU C... " >&6; } if test ${ac_cv_c_compiler_gnu+y} then : printf %s "(cached) " >&6 else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : ac_compiler_gnu=yes else $as_nop ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; } ac_compiler_gnu=$ac_cv_c_compiler_gnu if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi ac_test_CFLAGS=${CFLAGS+y} ac_save_CFLAGS=$CFLAGS { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 printf %s "checking whether $CC accepts -g... " >&6; } if test ${ac_cv_prog_cc_g+y} then : printf %s "(cached) " >&6 else $as_nop 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 (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_g=yes else $as_nop CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : else $as_nop ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; 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.beam conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 printf "%s\n" "$ac_cv_prog_cc_g" >&6; } if test $ac_test_CFLAGS; 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 ac_prog_cc_stdc=no if test x$ac_prog_cc_stdc = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C11 features" >&5 printf %s "checking for $CC option to enable C11 features... " >&6; } if test ${ac_cv_prog_cc_c11+y} then : printf %s "(cached) " >&6 else $as_nop ac_cv_prog_cc_c11=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_c_conftest_c11_program _ACEOF for ac_arg in '' -std=gnu11 do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_c11=$ac_arg fi rm -f core conftest.err conftest.$ac_objext conftest.beam test "x$ac_cv_prog_cc_c11" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC fi if test "x$ac_cv_prog_cc_c11" = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 printf "%s\n" "unsupported" >&6; } else $as_nop if test "x$ac_cv_prog_cc_c11" = x then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 printf "%s\n" "none needed" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5 printf "%s\n" "$ac_cv_prog_cc_c11" >&6; } CC="$CC $ac_cv_prog_cc_c11" fi ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11 ac_prog_cc_stdc=c11 fi fi if test x$ac_prog_cc_stdc = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C99 features" >&5 printf %s "checking for $CC option to enable C99 features... " >&6; } if test ${ac_cv_prog_cc_c99+y} then : printf %s "(cached) " >&6 else $as_nop ac_cv_prog_cc_c99=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_c_conftest_c99_program _ACEOF for ac_arg in '' -std=gnu99 -std=c99 -c99 -qlanglvl=extc1x -qlanglvl=extc99 -AC99 -D_STDC_C99= do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_c99=$ac_arg fi rm -f core conftest.err conftest.$ac_objext conftest.beam test "x$ac_cv_prog_cc_c99" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC fi if test "x$ac_cv_prog_cc_c99" = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 printf "%s\n" "unsupported" >&6; } else $as_nop if test "x$ac_cv_prog_cc_c99" = x then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 printf "%s\n" "none needed" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5 printf "%s\n" "$ac_cv_prog_cc_c99" >&6; } CC="$CC $ac_cv_prog_cc_c99" fi ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99 ac_prog_cc_stdc=c99 fi fi if test x$ac_prog_cc_stdc = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C89 features" >&5 printf %s "checking for $CC option to enable C89 features... " >&6; } if test ${ac_cv_prog_cc_c89+y} then : printf %s "(cached) " >&6 else $as_nop ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_c_conftest_c89_program _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 conftest.beam test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC fi if test "x$ac_cv_prog_cc_c89" = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 printf "%s\n" "unsupported" >&6; } else $as_nop if test "x$ac_cv_prog_cc_c89" = x then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 printf "%s\n" "none needed" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 printf "%s\n" "$ac_cv_prog_cc_c89" >&6; } CC="$CC $ac_cv_prog_cc_c89" fi ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89 ac_prog_cc_stdc=c89 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 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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 printf %s "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 test ${ac_cv_prog_CPP+y} then : printf %s "(cached) " >&6 else $as_nop # Double quotes because $CC needs to be expanded for CPP in "$CC -E" "$CC -E -traditional-cpp" 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. # 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. */ #include Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO" then : else $as_nop # 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 $as_nop # 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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 printf "%s\n" "$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. # 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. */ #include Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO" then : else $as_nop # 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 $as_nop # 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_nop { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$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 clang++ 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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CXX+y} then : printf %s "(cached) " >&6 else $as_nop 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 case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac 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" printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5 printf "%s\n" "$CXX" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "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 clang++ do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_CXX+y} then : printf %s "(cached) " >&6 else $as_nop 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 case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac 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" printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5 printf "%s\n" "$ac_ct_CXX" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "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:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$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. printf "%s\n" "$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\"" printf "%s\n" "$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 printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C++" >&5 printf %s "checking whether the compiler supports GNU C++... " >&6; } if test ${ac_cv_cxx_compiler_gnu+y} then : printf %s "(cached) " >&6 else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_cxx_try_compile "$LINENO" then : ac_compiler_gnu=yes else $as_nop ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_cv_cxx_compiler_gnu=$ac_compiler_gnu fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5 printf "%s\n" "$ac_cv_cxx_compiler_gnu" >&6; } ac_compiler_gnu=$ac_cv_cxx_compiler_gnu if test $ac_compiler_gnu = yes; then GXX=yes else GXX= fi ac_test_CXXFLAGS=${CXXFLAGS+y} ac_save_CXXFLAGS=$CXXFLAGS { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5 printf %s "checking whether $CXX accepts -g... " >&6; } if test ${ac_cv_prog_cxx_g+y} then : printf %s "(cached) " >&6 else $as_nop 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 (void) { ; return 0; } _ACEOF if ac_fn_cxx_try_compile "$LINENO" then : ac_cv_prog_cxx_g=yes else $as_nop CXXFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_cxx_try_compile "$LINENO" then : else $as_nop ac_cxx_werror_flag=$ac_save_cxx_werror_flag CXXFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; 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.beam conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_cxx_werror_flag=$ac_save_cxx_werror_flag fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5 printf "%s\n" "$ac_cv_prog_cxx_g" >&6; } if test $ac_test_CXXFLAGS; 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_prog_cxx_stdcxx=no if test x$ac_prog_cxx_stdcxx = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++11 features" >&5 printf %s "checking for $CXX option to enable C++11 features... " >&6; } if test ${ac_cv_prog_cxx_11+y} then : printf %s "(cached) " >&6 else $as_nop ac_cv_prog_cxx_11=no ac_save_CXX=$CXX cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_cxx_conftest_cxx11_program _ACEOF for ac_arg in '' -std=gnu++11 -std=gnu++0x -std=c++11 -std=c++0x -qlanglvl=extended0x -AA do CXX="$ac_save_CXX $ac_arg" if ac_fn_cxx_try_compile "$LINENO" then : ac_cv_prog_cxx_cxx11=$ac_arg fi rm -f core conftest.err conftest.$ac_objext conftest.beam test "x$ac_cv_prog_cxx_cxx11" != "xno" && break done rm -f conftest.$ac_ext CXX=$ac_save_CXX fi if test "x$ac_cv_prog_cxx_cxx11" = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 printf "%s\n" "unsupported" >&6; } else $as_nop if test "x$ac_cv_prog_cxx_cxx11" = x then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 printf "%s\n" "none needed" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_cxx11" >&5 printf "%s\n" "$ac_cv_prog_cxx_cxx11" >&6; } CXX="$CXX $ac_cv_prog_cxx_cxx11" fi ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx11 ac_prog_cxx_stdcxx=cxx11 fi fi if test x$ac_prog_cxx_stdcxx = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++98 features" >&5 printf %s "checking for $CXX option to enable C++98 features... " >&6; } if test ${ac_cv_prog_cxx_98+y} then : printf %s "(cached) " >&6 else $as_nop ac_cv_prog_cxx_98=no ac_save_CXX=$CXX cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_cxx_conftest_cxx98_program _ACEOF for ac_arg in '' -std=gnu++98 -std=c++98 -qlanglvl=extended -AA do CXX="$ac_save_CXX $ac_arg" if ac_fn_cxx_try_compile "$LINENO" then : ac_cv_prog_cxx_cxx98=$ac_arg fi rm -f core conftest.err conftest.$ac_objext conftest.beam test "x$ac_cv_prog_cxx_cxx98" != "xno" && break done rm -f conftest.$ac_ext CXX=$ac_save_CXX fi if test "x$ac_cv_prog_cxx_cxx98" = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 printf "%s\n" "unsupported" >&6; } else $as_nop if test "x$ac_cv_prog_cxx_cxx98" = x then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 printf "%s\n" "none needed" >&6; } else $as_nop { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_cxx98" >&5 printf "%s\n" "$ac_cv_prog_cxx_cxx98" >&6; } CXX="$CXX $ac_cv_prog_cxx_cxx98" fi ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx98 ac_prog_cxx_stdcxx=cxx98 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 if test /usr/local != "$exec_prefix" -a /usr/local != "$prefix" ; then CPPFLAGS="$CPPFLAGS -I/usr/local/include" LDFLAGS="$LDFLAGS -L/usr/local/lib" fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __gmpz_ui_sub in -lgmp" >&5 printf %s "checking for __gmpz_ui_sub in -lgmp... " >&6; } if test ${ac_cv_lib_gmp___gmpz_ui_sub+y} then : printf %s "(cached) " >&6 else $as_nop 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. */ char __gmpz_ui_sub (); int main (void) { return __gmpz_ui_sub (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : ac_cv_lib_gmp___gmpz_ui_sub=yes else $as_nop ac_cv_lib_gmp___gmpz_ui_sub=no fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gmp___gmpz_ui_sub" >&5 printf "%s\n" "$ac_cv_lib_gmp___gmpz_ui_sub" >&6; } if test "x$ac_cv_lib_gmp___gmpz_ui_sub" = xyes then : printf "%s\n" "#define HAVE_LIBGMP 1" >>confdefs.h LIBS="-lgmp $LIBS" else $as_nop as_fn_error $? "GNU MP not found, or not 4.1.4 or up, see http://gmplib.org" "$LINENO" 5 fi PKG_CPPFLAGS="${PKG_CPPFLAGS} -I/usr/local/include/ " PKG_LIBS="${PKG_LIBS} -L/usr/local/lib/ -lgmp" 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_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 printf "%s\n" "$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+y} || &/ 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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 printf "%s\n" "$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=`printf "%s\n" "$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" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 printf "%s\n" "$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 as_nop=: if test ${ZSH_VERSION+y} && (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 $as_nop case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi # Reset variables that may have inherited troublesome values from # the environment. # IFS needs to be set, to space, tab, and newline, in precisely that order. # (If _AS_PATH_WALK were called with IFS unset, it would have the # side effect of setting IFS to empty, thus disabling word splitting.) # Quoting is to prevent editors from complaining about space-tab. as_nl=' ' export as_nl IFS=" "" $as_nl" PS1='$ ' PS2='> ' PS4='+ ' # Ensure predictable behavior from utilities with locale-dependent output. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # We cannot yet rely on "unset" to work, but we need these variables # to be unset--not just set to an empty or harmless value--now, to # avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct # also avoids known problems related to "unset" and subshell syntax # in other old shells (e.g. bash 2.01 and pdksh 5.2.14). for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH do eval test \${$as_var+y} \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done # Ensure that fds 0, 1, and 2 are open. if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi if (exec 3>&2) ; then :; else exec 2>/dev/null; fi # The user is always right. if ${PATH_SEPARATOR+false} :; 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 # 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 case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac 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 printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # 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 printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi printf "%s\n" "$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_nop 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_nop 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 || printf "%s\n" 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 # Determine whether it's possible to make 'echo' print without a newline. # These variables are no longer used directly by Autoconf, but are AC_SUBSTed # for compatibility with existing Makefiles. 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 # For backward compatibility with old third-party macros, we provide # the shell variables $as_echo and $as_echo_n. New code should use # AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. as_echo='printf %s\n' as_echo_n='printf %s' 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=`printf "%s\n" "$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 || printf "%s\n" 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.71. 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 ac_cs_config=`printf "%s\n" "$ac_configure_args" | sed "$ac_safe_unquote"` ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\''/g"` cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ config.status configured by $0, generated by GNU Autoconf 2.71, with options \\"\$ac_cs_config\\" Copyright (C) 2021 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 ) printf "%s\n" "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) printf "%s\n" "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --file | --fil | --fi | --f ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`printf "%s\n" "$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 ) printf "%s\n" "$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 \printf "%s\n" "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 printf "%s\n" "$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+y} || 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=`printf "%s\n" "$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 '` printf "%s\n" "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 printf "%s\n" "$as_me: creating $ac_file" >&6;} fi # Neutralize special characters interpreted by sed in replacement strings. case $configure_input in #( *\&* | *\|* | *\\* ) ac_sed_conf_input=`printf "%s\n" "$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 || printf "%s\n" 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=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`printf "%s\n" "$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@*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 printf "%s\n" "$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"; } && { printf "%s\n" "$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 printf "%s\n" "$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 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi gmp/R/0000755000175000017500000000000013735324616011402 5ustar nileshnileshgmp/R/matrixq.R0000644000175000017500000000242313436201353013201 0ustar nileshnileshmatrix.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(..., recursive = FALSE) .Call(bigrational_cbind, list(...)) rbind.bigq <- function(..., recursive = FALSE) .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.R0000644000175000017500000002711013735324616012450 0ustar nileshnilesh#---------------------------------------------------------- # # 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) { has.j <- !missing(j) if(!is.null(attr(x, "nrow"))) { ## matrix ## FIXME x[i,] vs. x[,j] vs. x[i] .Call(matrix_get_at_q, x, i,j) } else { ## non-matrix if(has.j) stop("invalid vector subsetting") ## ugly "workaround" r <- .Call(matrix_get_at_q, x, i, NULL) attr(r,"nrow") <- NULL r } } `[<-.bigq` <- function(x,i=NULL,j=NULL,value) { has.j <- !missing(j) if(!is.null(attr(x, "nrow"))) { ## matrix ## FIXME x[i,] vs. x[,j] vs. x[i] .Call(matrix_set_at_q, x, value,i,j ) } else { ## non-matrix -- ugly workaround: if(has.j) stop("invalid vector subsetting") r <- .Call(matrix_set_at_q, x, value,i,j ) # '1' or does NULL work ?? attr(r,"nrow") <- NULL 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) } gmp/R/matrixz.R0000644000175000017500000000661313640560135013222 0ustar nileshnileshmatrix <- 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(..., recursive = FALSE) .Call(biginteger_cbind, list(...)) rbind.bigz <- function(..., recursive = FALSE) .Call(biginteger_rbind, list(...)) 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.R0000644000175000017500000002127513735324616014333 0ustar nileshnilesh###--------- 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(length=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)) } gmp/R/zzz.R0000755000175000017500000000131113735324616012361 0ustar nileshnilesh## 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.R0000644000175000017500000003241513735324616013651 0ustar nileshnileshis.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) 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(all(target == current)) 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) has.j <- !missing(j) if(!is.null(attr(x, "nrow"))) { ## matrix ## FIXME x[i,] vs. x[,j] vs. x[i] .Call(matrix_get_at_z, x, i,j) } else { ## non-matrix if(has.j) stop("invalid vector subsetting") ## ugly "workaround" r <- .Call(matrix_get_at_z, x, i, NULL) attr(r,"nrow") <- NULL r } } `[<-.bigz` <- function(x, i=NULL, j=NULL, value) { has.j <- !missing(j) if(!is.null(attr(x, "nrow"))) { ## matrix ## FIXME x[i,] vs. x[,j] vs. x[i] .Call(matrix_set_at_z, x, value, i,j) } else { ## non-matrix -- ugly workaround: if(has.j) stop("invalid vector subsetting") r <- .Call(matrix_set_at_z, x, value, i, 1) # '1' or does NULL work ?? attr(r,"nrow") <- NULL r } } gmp/R/matrix-prods.R0000644000175000017500000001041513640560135014150 0ustar nileshnileshif(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/R/AllClasses-etc.R0000644000175000017500000000216413735324616014327 0ustar nileshnilesh ## 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/cleanup0000755000175000017500000000020714140270010012530 0ustar nileshnilesh#!/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/0000755000175000017500000000000013435522365012110 5ustar nileshnileshgmp/data/Oakley1.R0000644000175000017500000000067613433542142013542 0ustar nileshnilesh# 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/data/Oakley2.R0000644000175000017500000000077713433542131013543 0ustar nileshnilesh# 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/NAMESPACE0000644000175000017500000001603413735324616012424 0ustar nileshnileshuseDynLib(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", 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("[[",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) ## 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/TODO0000644000175000017500000001372113735324616011675 0ustar nileshnilesh * Remove full path in `configure.ac` script, with example of Rmpfr configure. -*-org-*- * Bug Fixes ** TODO Logical ops should work: 0=FALSE NA=NA, =TRUE *** !as.bigz(0:3) crashes R badly (!!), but should return !(0:3) (logical vector). terminate called after throwing an instance of 'std::length_error' what(): vector::_M_default_append \\ ...R: line 141: 25400 Aborted (core dumped) *** 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. ** TODO Not working column assignment : A[,j] <- vec does nothing, not warn, nothing -- but A[i,] <- val works ?? ** TODO 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 ** TODO 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 *** TODO want *different* M[1,] and M[1] for big[zq] matrices *** TODO 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.ac0000644000175000017500000000172714140267654013475 0ustar nileshnileshdnl Process this file with autoconf to produce a configure script. AC_INIT AC_CONFIG_SRCDIR([src/biginteger.cc]) 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 People often put stuff in /usr/local. if test /usr/local != "$exec_prefix" -a /usr/local != "$prefix" ; then CPPFLAGS="$CPPFLAGS -I/usr/local/include" LDFLAGS="$LDFLAGS -L/usr/local/lib" fi dnl Check for lib gmp 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])]) PKG_CPPFLAGS="${PKG_CPPFLAGS} -I/usr/local/include/ " PKG_LIBS="${PKG_LIBS} -L/usr/local/lib/ -lgmp" AC_SUBST(PKG_CPPFLAGS) AC_SUBST(PKG_LIBS) AC_CONFIG_FILES([src/Makevars]) AC_OUTPUT