useDynLib(Rmpfr, .registration=TRUE)

##-- From 'gmp' (on which we 'Depend' ------------------------------------------

## cheap, somewhat experimental -- hence the "."
export(.mpfr2bigz, .bigz2mpfr, .bigq2mpfr)

## Import all we need, but not more

importMethodsFrom("methods" ## as we define methods for them:
                , coerce, "coerce<-", show
                , Arith, Compare, Logic, Math, Math2, Ops, Summary
                  )
importFrom("methods",
	   as, "as<-",
	   callGeneric, callNextMethod,
           is, extends, new, validObject,
	   setClass, setClassUnion, setMethod, setOldClass, setValidity,
	   slot, "slot<-", .slotNames,
	   getDataPart, setDataPart, getClass, getClassDef,
	   signature, representation, prototype
           ## needed implicitly [or "bug" ..]:
           , loadMethod)

importFrom("utils", str)
importFrom("stats"  # import *and* rename -- we extend these :
	   ,stats__pnorm  = pnorm
	   ,stats__dnorm  = dnorm
	   ,stats__dpois  = dpois
	   ,stats__dbinom = dbinom
	   )

importClassesFrom("gmp", "bigz", "bigq")
importFrom("gmp"
           , asNumeric, as.bigz, as.bigq, .as.char.bigz, ..as.bigz
           , crossprod, tcrossprod# `%*%`, <- as we write (S4) methods for those
           , matrix, numerator, denominator, frexpZ, chooseZ
           , is.whole, formatN # because we add own S3 methods
	   )
if(packageVersion("gmp") >= "0.5.8")
    importFrom("gmp", is.matrixZQ, #-> R/gmp-convert.R
               which.min, which.max)# the generics
##------------------------------------------------------------------------------

exportClasses("mpfr1", "mpfr"
              , "mpfrArray"
              , "mpfrMatrix"

              , "atomicVector"
              , "array_or_vector"
              , "Mnumber"

              ## new, *not* containing "matrix" (which has -> "character"!):
              , "numericVector"
              , "mNumber"
)

## Standard (base, stats) functions which we made into S4 generics
export(mean,
       median,
       quantile)

export(.mpfr, .mpfr.
       ## ".Arith.codes"
       ## , ".Arith.mpfr.num"
       ## , ".Arith.num.mpfr"
       ## , ".Compare.codes"
       ## , ".Compare.codesRev"
       ## , ".Compare.mpfr.num"
       ## , ".Compare.num.mpfr"
       ## , ".Math.codes"
       ## , ".Math.gen"
       ## , ".Summary.codes"
       ## , ".abs.mpfr"
       ## , ".dimCheck"
       , .getPrec
       , .getSign
       , .mpfr.erange, .mpfr.erange.set, .mpfr.maxPrec, .mpfr.minPrec
       ## , ".mA.subAssign"
       ## , ".matmult.R"
       ## , ".mpfr.debug"
       , ".mpfr.negative"
       ## , ".mpfr.negative.R"
       ## , ".mpfr.repl"
       , ".mpfr.sign"
       ## , ".mpfr.subset"
       , ".mpfr2str"
       ## , ".mpfrA.subset"
       , .mpfrVersion, .mpfr.gmp.numbbits
       , .mpfr2list, mpfrImport, mpfrXport # <- experimental: for a possible save format
       ## , ".packageName"
       ## , ".print.mpfr"
       ## , ".requireCachedGenerics"
       , "Ai"
       , "Bernoulli"
       , "Const"
       , "Ei"
       , "Li2"
       , "all.equal"
       , "aperm"
       , "apply" ## <- we make it S4 generic
       , "atan2"
       , "beta", "lbeta"
       ## S3 "c.mpfr"
       , "cbind"
       , "chooseMpfr", "chooseMpfr.all", "sumBinomMpfr"
       , "crossprod"
       , "dbinom", "dpois", "dnorm"
       , "erf", "erfc"
       , "factorial"
       , "factorialMpfr"
       , "format"
       , formatMpfr, formatBin, formatDec, formatHex
       , "getD"
       , "getPrec"
       , "hypot"
       , "integrateR"
       , "j0" , "j1" , "jn"
       , "mpfr"
       , mpfrIs0, .mpfr.is.whole # as substitutes of
       , "mpfr.is.0", "mpfr.is.integer" # <-- now (Aug. 2015) deprecated
       , "mpfr2array", "mpfrArray"
       , "mpfrVersion"
       , "mpfr_default_prec"
       , "optimizeR"
       , "hjkMpfr" ## <-- FIXME, rather part of an  optimR(...., method = "hjk")
       , "pbetaI"
       , "pmax", "pmin"
       , "pnorm"
       , "pochMpfr"
       , "rbind"
       , "roundMpfr"
       , "seqMpfr"
       , "t"
       , "tcrossprod"
       , "toNum"
       , "unique"
       , "unirootR"
       , "y0", "y1", "yn"
       , "zeta"
       )


exportMethods(##___ "own generics" ___
    "apply", "asNumeric"

    ##___ "other generics" ___

    ## Group Methods
  , Arith, Compare, Logic, Math, Math2, Ops, Summary

  , "abs", "log", "sign"
  , "Re", "Im", "Mod", "Arg", "Conj"
  , "all.equal", "aperm"
  , "as.vector", "as.integer", "as.numeric"
  , "coerce", "coerce<-"
  , "cbind", "rbind"
  , "diag", "diag<-"
  , "dim", "dim<-", "dimnames", "dimnames<-"
  , "atan2", "beta", "lbeta"
  , "factorial"
  , "is.finite", "is.infinite", "is.na", "is.nan"
  , "%*%", "crossprod", "tcrossprod", "t"
  , "format"
  , "mean", "pmax", "pmin"
  , "show", "unique"
  , "colSums", "colMeans"
  , "rowSums", "rowMeans", "norm"
  , "which.min", "which.max"
)

## Our own S3 generic  mpfr():
S3method(mpfr, default)
S3method(mpfr, bigz)
S3method(mpfr, bigq)
S3method(mpfr, mpfr)
S3method(mpfr, Bcharacter)
S3method(mpfr, Hcharacter)

S3method(c, mpfr)

S3method(as.array, mpfr)
S3method(as.matrix, mpfr)
## Would break the working of vapply(<mpfr>, FUN)  e.g. in pbetaI():
## S3method(as.list, mpfr1)
## S3method(as.list, mpfr)

S3method(determinant, mpfrMatrix)
S3method(scale, mpfrMatrix)

S3method(diff, mpfr)
S3method(str,  mpfr)

S3method(is.whole, mpfr)
#S3method(is.whole, mpfrArray)
S3method(formatN, mpfr)

S3method(print, mpfr)
S3method(print, mpfr1)
S3method(print, mpfrArray)
S3method(print, integrateR)
S3method(print, Bcharacter)
S3method(print, Hcharacter, print.Bcharacter)# use the same

S3method(matrix, mpfr)
## useful, to have  base::outer() work automatically:
S3method(rep, mpfr)
S3method(t, mpfr)
S3method(t, mpfrMatrix)
S3method(aperm, mpfrArray)

