Commit e41670bf authored by Martin Maechler's avatar Martin Maechler
Browse files

c(), max(), min() ... now all fixed for (<bigz>, <bigq>) arguments

parent 1cacced4
2020-03-02 Martin Mächler <maechler@stat.math.ethz.ch>
* 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
** Some fix
**Indexing/Subassignment:
*** Seg.faults in
......
Package: gmp
Version: 0.5-13.6
Date: 2020-01-05
Version: 0.5-14
Date: 2020-03-02
Title: Multiple Precision Arithmetic
Author: Antoine Lucas, Immanuel Scholz, Rainer Boehme <rb-gmp@reflex-studio.de>,
Sylvain Jasson <jasson@toulouse.inra.fr>,
......@@ -9,7 +9,7 @@ Maintainer: Antoine Lucas <antoinelucas@gmail.com>
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.0.0)
Depends: R (>= 3.4.0)
Imports: methods
Suggests: Rmpfr
SystemRequirements: gmp (>= 4.2.3)
......@@ -17,6 +17,3 @@ License: GPL
BuildResaveData: no
LazyDataNote: not available, as we use data/*.R *and* our classes
NeedsCompilation: yes
Packaged: 2020-01-05 18:36:28 UTC; antoine
Repository: CRAN
Date/Publication: 2019-03-11 16:00:02 UTC
......@@ -216,4 +216,3 @@ 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)
......@@ -200,8 +200,14 @@ 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) {
if(digits == 0) x
else stop("digits != 0 is not yet implemented")
## 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)
......@@ -231,12 +237,19 @@ log10.bigz <- function(x) ln.bigz(x) / log(10)
max.bigz <- function(...,na.rm=FALSE)
{
.Call(biginteger_max, c.bigz(...), na.rm)
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)
{
.Call(biginteger_min, c.bigz(...), na.rm)
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()
......@@ -244,13 +257,17 @@ min.bigz <- function(...,na.rm=FALSE)
prod.bigz <- function(..., na.rm = FALSE)
{
X <- c.bigz(...)
.Call(biginteger_prod, if(na.rm) X[!is.na(X)] else X)
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(...)
.Call(biginteger_sum, if(na.rm) X[!is.na(X)] else X)
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}------------------------------------
......@@ -260,7 +277,10 @@ setMethod("which.min", "bigz", function(x) which.max(x == min(x)))
c.bigz <- function(..., recursive = FALSE)
{
.Call(biginteger_c, list(...))
argL <- list(...)
if(any(vapply(argL, inherits, NA, what="bigq")))
.Call(bigrational_c, argL)
else .Call(biginteger_c, argL)
}
## This is practically identical to grid :: rep.unit :
......
......@@ -153,12 +153,21 @@ abs.bigq <- function(x) {
sign.bigq <- function(x) sign(numerator(x))
## TODO
trunc.bigq <- function(x, ...) .NotYetImplemented()
floor.bigq <- function(x) .NotYetImplemented()
ceiling.bigq <- function(x) .NotYetImplemented()
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)
round.bigq <- function(x, digits = 0) {
.NotYetImplemented()
## round(x * 10^d) / 10^d
bigq_half <- as.bigq(1, 2)
round0 <- function(x) as.bigz.bigq(x + bigq_half)
stopifnot(length(digits) == 1L)
if(digits == 0)
round0(x)
else {
p10 <- as.bigz(10) ^ digits # bigz iff digits >= 0, bigq otherwise
round0(x * p10) / p10
}
}
cumsum.bigq <- function(x) .Call(bigrational_cumsum, x)
......
R Under development (unstable) (2019-12-09 r77545) -- "Unsuffered Consequences"
Copyright (C) 2019 The R Foundation for Statistical Computing
R version 3.6.3 Patched (2020-02-29 r77878) -- "Holding the Windsock"
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.
......@@ -885,32 +885,19 @@ max.bigq -> num.fn.: max
------------------------------------------
max.bigz -> num.fn.: max
-> all.equal(target = res, current = F(<numeric x>)):
23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA
1 23 25 23 23 23 23 34 32 31 23 <NA>
2 25 25 25 25 25 25 34 32 31 25 <NA>
3 23 25 2 2 4 2 34 32 31 2 <NA>
4 23 25 2 -4 4 0 34 32 31 -4 <NA>
5 23 25 4 4 4 4 34 32 31 4 <NA>
6 23 25 2 0 4 0 34 32 31 0 <NA>
7 34 34 34 34 34 34 34 34 34 34 <NA>
8 32 32 32 32 32 32 34 32 32 32 <NA>
9 (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) (34 %% 45) (32 %% 45) (31 %% 45) (31 %% 45) <NA>
10 23 25 2 -4 4 0 34 32 (31 %% 45) <NA> NA
11 23 25 2 -4 4 0 34 32 31 NA <NA>
12 23 25 2 -3 4 0 34 32 31 -3 <NA>
-3L
1 23
2 25
3 2
4 -3
5 4
6 0
7 34
8 32
9 (31 %% 45)
10 -3
11 -3
12 -3
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 <NA> 23
2 25 25 25 25 25 25 34 25 31 25 <NA> 25
3 23 25 2 2 4 2 34 32/7 31 2 <NA> 2
4 23 25 2 -4 4 0 34 32/7 31 -4 <NA> -3
5 23 25 4 4 4 4 34 32/7 31 4 <NA> 4
6 23 25 2 0 4 0 34 32/7 31 0 <NA> 0
7 34 34 34 34 34 34 34 34 34 34 <NA> 34
8 23 25 32/7 32/7 32/7 32/7 34 32/7 31 32/7 <NA> 32/7
9 (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) (34 %% 45) 31 (31 %% 45) (31 %% 45) <NA> (31 %% 45)
10 23 25 2 -4 4 0 34 32/7 (31 %% 45) <NA> NA -3
11 23 25 2 -4 4 0 34 32/7 31 NA <NA> -3
12 23 25 2 -3 4 0 34 32/7 31 -3 <NA> -3
------------------------------------------
min.bigq -> num.fn.: min
......@@ -958,32 +945,32 @@ min.bigq -> num.fn.: min
------------------------------------------
min.bigz -> num.fn.: min
-> all.equal(target = res, current = F(<numeric x>)):
23. 25 2.3 -4. 4L 0. 34_Z 32/7 (31 %% 45) NULL NA
1 23 23 2 -4 4 0 23 23 23 23 <NA>
2 23 25 2 -4 4 0 25 25 25 25 <NA>
3 2 2 2 -4 2 0 2 2 2 2 <NA>
4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 <NA>
5 4 4 2 -4 4 0 4 4 4 4 <NA>
6 0 0 0 -4 0 0 0 0 0 0 <NA>
7 23 25 2 -4 4 0 34 32 31 34 <NA>
8 23 25 2 -4 4 0 32 32 31 32 <NA>
9 (23 %% 45) (25 %% 45) (2 %% 45) (-4 %% 45) (4 %% 45) (0 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) (31 %% 45) <NA>
10 23 25 2 -4 4 0 34 32 (31 %% 45) <NA> NA
11 23 25 2 -4 4 0 34 32 31 NA <NA>
12 -3 -3 -3 -4 -3 -3 -3 -3 -3 -3 <NA>
-3L
1 -3
2 -3
3 -3
4 -4
5 -3
6 -3
7 -3
8 -3
9 (-3 %% 45)
10 -3
11 -3
12 -3
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 <NA> -3
2 32/7 25 25 <NA> -3
3 2589569785738035/1125899906842624 2 2 <NA> -3
4 -4 -4 -4 <NA> -4
5 4 4 4 <NA> -3
6 0 0 0 <NA> -3
7 32/7 31 34 <NA> -3
8 32/7 32/7 32/7 <NA> -3
9 32/7 (31 %% 45) (31 %% 45) <NA> (-3 %% 45)
10 32/7 (31 %% 45) <NA> NA -3
11 32/7 31 NA <NA> -3
12 -3 -3 -3 <NA> -3
There were 50 or more warnings (use warnings() to see the first 50)
>
......@@ -1018,7 +1005,7 @@ log10.bigz
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 (31 %% 45) <NA> NA -3
1 23 25 2 -4 4 0 34 32/7 (31 %% 45) <NA> NA -3
------------------------------------------
isprime
......@@ -1180,4 +1167,4 @@ Big Integer ('bigz') object of length 2:
>
> proc.time()
user system elapsed
1.424 0.055 1.479
0.487 0.084 0.563
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment