Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Maintenance - Mise à jour mensuelle Lundi 6 Février entre 7h00 et 9h00
Open sidebar
Sylvain Jasson
gmp
Commits
e41670bf
Commit
e41670bf
authored
Mar 02, 2020
by
Martin Maechler
Browse files
c(), max(), min() ... now all fixed for (<bigz>, <bigq>) arguments
parent
1cacced4
Changes
6
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
e41670bf
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
...
...
DESCRIPTION
View file @
e41670bf
Package: gmp
Version: 0.5-1
3.6
Date: 2020-0
1
-0
5
Version: 0.5-1
4
Date: 2020-0
3
-0
2
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
R/Stirling-n-etc.R
View file @
e41670bf
...
...
@@ -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
)
R/biginteger.R
View file @
e41670bf
...
...
@@ -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 :
...
...
R/bigq.R
View file @
e41670bf
...
...
@@ -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
)
...
...
tests/gmp-test.Rout.save
View file @
e41670bf
R
Under development (unstable) (2019-12-0
9 r77
545
) -- "
Unsuffered Consequences
"
Copyright (C) 20
19
The R Foundation for Statistical Computing
R
version 3.6.3 Patched (2020-02-2
9 r77
878
) -- "
Holding the Windsock
"
Copyright (C) 20
20
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
.4
24
0.0
55
1.479
0
.4
87
0.0
84
0.563
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment