gmp 0.5.41 → 0.5.47
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +21 -0
- data/FEATURES.html +37 -38
- data/README.html +511 -0
- data/README.markdown +494 -0
- data/benchmark/divide +0 -0
- data/benchmark/gcd +0 -0
- data/benchmark/multiply +0 -0
- data/benchmark/multiply.fnl +0 -0
- data/benchmark/multiply.gc +0 -0
- data/benchmark/pi +0 -0
- data/benchmark/rsa +0 -0
- data/benchmark/runbench +0 -0
- data/benchmark/srb.sh +0 -0
- data/ext/gmp.c +0 -42
- data/ext/gmpf.c +64 -33
- data/ext/gmpq.c +88 -1
- data/ext/gmpz.c +151 -19
- data/ext/ruby_gmp.h +16 -10
- data/manual.pdf +0 -0
- data/manual.tex +50 -14
- data/test/gmp_tgcd.rb +18 -18
- data/test/mpfr_tcbrt.rb +1 -1
- data/test/mpfr_tconst_euler.rb +10 -7
- data/test/mpfr_tisnan.rb +1 -1
- data/test/mpfr_trec_sqrt.rb +1 -1
- data/test/mpfr_tsqrt.rb +1 -1
- data/test/tc_cmp.rb +7 -2
- data/test/tc_constants.rb +1 -1
- data/test/tc_division.rb +1 -1
- data/test/tc_f_arithmetics_coersion.rb +1 -1
- data/test/tc_f_precision.rb +1 -1
- data/test/tc_fib_fac_nextprime.rb +1 -1
- data/test/tc_floor_ceil_truncate.rb +1 -1
- data/test/tc_hashes.rb +26 -1
- data/test/tc_logical_roots.rb +1 -1
- data/test/tc_mpfr_constants.rb +1 -1
- data/test/tc_mpfr_functions.rb +1 -1
- data/test/tc_mpfr_random.rb +1 -1
- data/test/tc_mpfr_rounding.rb +3 -3
- data/test/tc_q.rb +1 -1
- data/test/tc_q_basic.rb +1 -1
- data/test/tc_random.rb +1 -1
- data/test/tc_sgn_neg_abs.rb +1 -1
- data/test/tc_swap.rb +1 -1
- data/test/tc_z.rb +34 -1
- data/test/tc_z_addmul.rb +1 -1
- data/test/tc_z_basic.rb +1 -1
- data/test/tc_z_exponentiation.rb +1 -1
- data/test/tc_z_functional_mappings.rb +42 -6
- data/test/tc_z_gcd_lcm_invert.rb +1 -1
- data/test/tc_z_jac_leg_rem.rb +1 -1
- data/test/tc_z_logic.rb +1 -1
- data/test/tc_z_shifts_last_bits.rb +1 -1
- data/test/tc_z_submul.rb +1 -1
- data/test/tc_z_to_dis.rb +1 -1
- data/test/tc_zerodivisionexceptions.rb +1 -1
- data/test/test_helper.rb +2 -1
- data/test/unit_tests.rb +1 -1
- metadata +70 -89
- data/README.rdoc +0 -450
data/test/tc_z_gcd_lcm_invert.rb
CHANGED
data/test/tc_z_jac_leg_rem.rb
CHANGED
data/test/tc_z_logic.rb
CHANGED
data/test/tc_z_submul.rb
CHANGED
data/test/tc_z_to_dis.rb
CHANGED
data/test/test_helper.rb
CHANGED
data/test/unit_tests.rb
CHANGED
metadata
CHANGED
@@ -1,149 +1,130 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmp
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
- 41
|
10
|
-
version: 0.5.41
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.47
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Tomasz Wegrzanowski
|
14
9
|
- srawlins
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
date: 2010-11-17 00:00:00 -07:00
|
13
|
+
date: 2011-11-10 00:00:00.000000000 -07:00
|
20
14
|
default_executable:
|
21
15
|
dependencies: []
|
22
|
-
|
23
16
|
description: gmp - providing Ruby bindings to the GMP library.
|
24
|
-
email:
|
17
|
+
email:
|
25
18
|
- Tomasz.Wegrzanowski@gmail.com
|
26
19
|
- sam.rawlins@gmail.com
|
27
20
|
executables: []
|
28
|
-
|
29
|
-
extensions:
|
21
|
+
extensions:
|
30
22
|
- ext/extconf.rb
|
31
23
|
extra_rdoc_files: []
|
32
|
-
|
33
|
-
files:
|
34
|
-
- ext/gmp.c
|
24
|
+
files:
|
35
25
|
- ext/gmpbench_timing.c
|
36
|
-
- ext/gmpf.c
|
37
|
-
- ext/gmpq.c
|
38
26
|
- ext/gmprandstate.c
|
27
|
+
- ext/gmp.c
|
28
|
+
- ext/gmpq.c
|
39
29
|
- ext/gmpz.c
|
40
30
|
- ext/mprnd.c
|
41
|
-
- ext/gmpf.
|
42
|
-
- ext/gmpq.h
|
43
|
-
- ext/gmpz.h
|
44
|
-
- ext/mprnd.h
|
31
|
+
- ext/gmpf.c
|
45
32
|
- ext/ruby_gmp.h
|
46
33
|
- ext/takeover.h
|
34
|
+
- ext/gmpz.h
|
35
|
+
- ext/gmpf.h
|
36
|
+
- ext/mprnd.h
|
37
|
+
- ext/gmpq.h
|
47
38
|
- ext/extconf.rb
|
48
39
|
- lib/gmp.rb
|
49
|
-
- test/
|
50
|
-
- test/mpfr_tcbrt.rb
|
51
|
-
- test/mpfr_tconst_euler.rb
|
52
|
-
- test/mpfr_tisnan.rb
|
40
|
+
- test/tc_z_addmul.rb
|
53
41
|
- test/mpfr_trec_sqrt.rb
|
54
|
-
- test/
|
55
|
-
- test/tc_cmp.rb
|
56
|
-
- test/tc_constants.rb
|
57
|
-
- test/tc_division.rb
|
58
|
-
- test/tc_fib_fac_nextprime.rb
|
59
|
-
- test/tc_floor_ceil_truncate.rb
|
42
|
+
- test/tc_swap.rb
|
60
43
|
- test/tc_f_arithmetics_coersion.rb
|
61
|
-
- test/tc_f_precision.rb
|
62
|
-
- test/tc_hashes.rb
|
63
44
|
- test/tc_logical_roots.rb
|
64
|
-
- test/tc_mpfr_constants.rb
|
65
|
-
- test/tc_mpfr_functions.rb
|
66
|
-
- test/tc_mpfr_random.rb
|
67
|
-
- test/tc_mpfr_rounding.rb
|
68
|
-
- test/tc_q.rb
|
69
|
-
- test/tc_q_basic.rb
|
70
45
|
- test/tc_random.rb
|
71
|
-
- test/
|
72
|
-
- test/
|
46
|
+
- test/test-21.rb
|
47
|
+
- test/tc_z_submul.rb
|
48
|
+
- test/tc_constants.rb
|
49
|
+
- test/tc_mpfr_random.rb
|
50
|
+
- test/mpfr_tcbrt.rb
|
73
51
|
- test/tc_z.rb
|
74
52
|
- test/tc_zerodivisionexceptions.rb
|
75
|
-
- test/tc_z_addmul.rb
|
76
|
-
- test/tc_z_basic.rb
|
77
|
-
- test/tc_z_exponentiation.rb
|
78
|
-
- test/tc_z_functional_mappings.rb
|
79
|
-
- test/tc_z_gcd_lcm_invert.rb
|
80
|
-
- test/tc_z_jac_leg_rem.rb
|
81
|
-
- test/tc_z_logic.rb
|
82
53
|
- test/tc_z_shifts_last_bits.rb
|
83
|
-
- test/
|
84
|
-
- test/
|
54
|
+
- test/tc_mpfr_constants.rb
|
55
|
+
- test/test_helper.rb
|
56
|
+
- test/tc_cmp.rb
|
57
|
+
- test/tc_q.rb
|
58
|
+
- test/tc_z_functional_mappings.rb
|
59
|
+
- test/mpfr_tconst_euler.rb
|
85
60
|
- test/test-20.rb
|
86
|
-
- test/
|
61
|
+
- test/tc_z_to_dis.rb
|
62
|
+
- test/mpfr_tisnan.rb
|
63
|
+
- test/tc_z_jac_leg_rem.rb
|
64
|
+
- test/tc_hashes.rb
|
65
|
+
- test/tc_floor_ceil_truncate.rb
|
66
|
+
- test/tc_mpfr_rounding.rb
|
67
|
+
- test/tc_z_basic.rb
|
68
|
+
- test/gmp_tgcd.rb
|
69
|
+
- test/tc_z_exponentiation.rb
|
70
|
+
- test/tc_q_basic.rb
|
71
|
+
- test/mpfr_tsqrt.rb
|
87
72
|
- test/test-22.rb
|
73
|
+
- test/tc_sgn_neg_abs.rb
|
88
74
|
- test/test-23.rb
|
89
|
-
- test/test_helper.rb
|
90
75
|
- test/unit_tests.rb
|
76
|
+
- test/tc_mpfr_functions.rb
|
77
|
+
- test/tc_f_precision.rb
|
78
|
+
- test/tc_z_gcd_lcm_invert.rb
|
79
|
+
- test/tc_z_logic.rb
|
80
|
+
- test/tc_division.rb
|
81
|
+
- test/tc_fib_fac_nextprime.rb
|
91
82
|
- test/README
|
92
83
|
- test/test_unit/assertions.rb
|
93
|
-
- benchmark/
|
94
|
-
- benchmark/divide
|
95
|
-
- benchmark/gcd
|
84
|
+
- benchmark/rsa
|
96
85
|
- benchmark/gexpr.c
|
86
|
+
- benchmark/COPYING
|
97
87
|
- benchmark/multiply
|
98
|
-
- benchmark/multiply.fnl
|
99
|
-
- benchmark/multiply.gc
|
100
88
|
- benchmark/pi
|
89
|
+
- benchmark/version
|
90
|
+
- benchmark/srb.sh
|
91
|
+
- benchmark/gcd
|
92
|
+
- benchmark/divide
|
101
93
|
- benchmark/README
|
102
|
-
- benchmark/
|
94
|
+
- benchmark/multiply.gc
|
95
|
+
- benchmark/multiply.fnl
|
103
96
|
- benchmark/runbench
|
104
|
-
- benchmark/srb.sh
|
105
|
-
- benchmark/version
|
106
97
|
- CHANGELOG
|
107
98
|
- INSTALL
|
108
|
-
- README.
|
99
|
+
- README.html
|
100
|
+
- README.markdown
|
109
101
|
- manual.pdf
|
110
102
|
- manual.tex
|
111
103
|
- FEATURES.html
|
112
|
-
has_rdoc:
|
104
|
+
has_rdoc: true
|
113
105
|
homepage: http://github.com/srawlins/gmp
|
114
106
|
licenses: []
|
115
|
-
|
116
107
|
post_install_message:
|
117
108
|
rdoc_options: []
|
118
|
-
|
119
|
-
require_paths:
|
109
|
+
require_paths:
|
120
110
|
- lib
|
121
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
112
|
none: false
|
123
|
-
requirements:
|
124
|
-
- -
|
125
|
-
- !ruby/object:Gem::Version
|
126
|
-
hash: 59
|
127
|
-
segments:
|
128
|
-
- 1
|
129
|
-
- 8
|
130
|
-
- 6
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
131
116
|
version: 1.8.6
|
132
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
118
|
none: false
|
134
|
-
requirements:
|
135
|
-
- -
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
|
138
|
-
|
139
|
-
- 0
|
140
|
-
version: "0"
|
141
|
-
requirements:
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements:
|
142
124
|
- GMP compiled and working properly.
|
143
125
|
rubyforge_project:
|
144
|
-
rubygems_version: 1.
|
126
|
+
rubygems_version: 1.6.2
|
145
127
|
signing_key:
|
146
128
|
specification_version: 3
|
147
129
|
summary: Provides Ruby bindings to the GMP library.
|
148
130
|
test_files: []
|
149
|
-
|
data/README.rdoc
DELETED
@@ -1,450 +0,0 @@
|
|
1
|
-
=gmp
|
2
|
-
|
3
|
-
gmp is library providing Ruby bindings to GMP library. Here is the introduction
|
4
|
-
paragraph at http://gmplib.org/#WHAT :
|
5
|
-
|
6
|
-
* "GMP is a free library for arbitrary precision arithmetic, operating on
|
7
|
-
signed integers, rational numbers, and floating point numbers. There is no
|
8
|
-
practical limit to the precision except the ones implied by the available
|
9
|
-
memory in the machine GMP runs on. GMP has a rich set of functions, and the
|
10
|
-
functions have a regular interface.
|
11
|
-
|
12
|
-
* The main target applications for GMP are cryptography applications and
|
13
|
-
research, Internet security applications, algebra systems, computational
|
14
|
-
algebra research, etc.
|
15
|
-
|
16
|
-
* GMP is carefully designed to be as fast as possible, both for small operands
|
17
|
-
and for huge operands. The speed is achieved by using fullwords as the basic
|
18
|
-
arithmetic type, by using fast algorithms, with highly optimised assembly
|
19
|
-
code for the most common inner loops for a lot of CPUs, and by a general
|
20
|
-
emphasis on speed.
|
21
|
-
|
22
|
-
* GMP is faster than any other bignum library. The advantage for GMP increases
|
23
|
-
with the operand sizes for many operations, since GMP uses asymptotically
|
24
|
-
faster algorithms.
|
25
|
-
|
26
|
-
* The first GMP release was made in 1991. It is continually developed and
|
27
|
-
maintained, with a new release about once a year.
|
28
|
-
|
29
|
-
* GMP is distributed under the GNU LGPL. This license makes the library free to
|
30
|
-
use, share, and improve, and allows you to pass on the result. The license
|
31
|
-
gives freedoms, but also sets firm restrictions on the use with non-free
|
32
|
-
programs.
|
33
|
-
|
34
|
-
* GMP is part of the GNU project. For more information about the GNU project,
|
35
|
-
please see the official GNU web site.
|
36
|
-
|
37
|
-
* GMP's main target platforms are Unix-type systems, such as GNU/Linux,
|
38
|
-
Solaris, HP-UX, Mac OS X/Darwin, BSD, AIX, etc. It also is known to work on
|
39
|
-
Windoze in 32-bit mode.
|
40
|
-
|
41
|
-
* GMP is brought to you by a team listed in the manual.
|
42
|
-
|
43
|
-
* GMP is carefully developed and maintained, both technically and legally. We
|
44
|
-
of course inspect and test contributed code carefully, but equally
|
45
|
-
importantly we make sure we have the legal right to distribute the
|
46
|
-
contributions, meaning users can safely use GMP. To achieve this, we will ask
|
47
|
-
contributors to sign paperwork where they allow us to distribute their work."
|
48
|
-
|
49
|
-
Only GMP 4 or newer is supported. The following environments have been tested
|
50
|
-
by me: gmp gem 0.5.41 on:
|
51
|
-
+-----------------------------------------+--------------------+-------------------+
|
52
|
-
| Platform | Ruby | GMP (MPFR) |
|
53
|
-
+-----------------------------------------+--------------------+-------------------+
|
54
|
-
| Linux (Ubuntu NR 10.04) on x86 (32-bit) | (MRI) Ruby 1.8.7 | GMP 4.3.1 (2.4.2) |
|
55
|
-
| | (MRI) Ruby 1.8.7 | GMP 4.3.2 (2.4.2) |
|
56
|
-
| | (MRI) Ruby 1.8.7 | GMP 5.0.1 (3.0.0) |
|
57
|
-
| | (MRI) Ruby 1.9.1 | GMP 4.3.1 (2.4.2) |
|
58
|
-
| | (MRI) Ruby 1.9.1 | GMP 4.3.2 (2.4.2) |
|
59
|
-
| | (MRI) Ruby 1.9.1 | GMP 5.0.1 (3.0.0) |
|
60
|
-
| | (MRI) Ruby 1.9.2 | GMP 4.3.1 (2.4.2) |
|
61
|
-
| | (MRI) Ruby 1.8.7 | GMP 4.3.2 (2.4.2) |
|
62
|
-
| | (MRI) Ruby 1.8.7 | GMP 5.0.1 (3.0.0) |
|
63
|
-
+-----------------------------------------+--------------------+-------------------+
|
64
|
-
| Linux (Ubuntu 10.04) on x86_64 (64-bit) | (MRI) Ruby 1.8.7 | GMP 4.3.2 (2.4.2) |
|
65
|
-
| | (MRI) Ruby 1.8.7 | GMP 5.0.1 (3.0.0) |
|
66
|
-
| | (MRI) Ruby 1.9.1 | GMP 4.3.2 (2.4.2) |
|
67
|
-
| | (MRI) Ruby 1.9.1 | GMP 5.0.1 (3.0.0) |
|
68
|
-
| | (MRI) Ruby 1.9.2 | GMP 4.3.2 (2.4.2) |
|
69
|
-
| | (MRI) Ruby 1.9.2 | GMP 5.0.1 (3.0.0) |
|
70
|
-
| | (RBX) Rubinius 1.1 | GMP 4.3.2 (2.4.2) |
|
71
|
-
| | (RBX) Rubinius 1.1 | GMP 5.0.1 (3.0.0) |
|
72
|
-
+-----------------------------------------+--------------------+-------------------+
|
73
|
-
| Mac OS X 10.6.4 on x86_64 (64-bit) | (MRI) Ruby 1.8.7 | GMP 4.3.2 (2.4.2) |
|
74
|
-
| | (MRI) Ruby 1.8.7 | GMP 5.0.1 (3.0.0) |
|
75
|
-
| | (MRI) Ruby 1.9.1 | GMP 4.3.2 (2.4.2) |
|
76
|
-
| | (MRI) Ruby 1.9.1 | GMP 5.0.1 (3.0.0) |
|
77
|
-
| | (MRI) Ruby 1.9.2 | GMP 4.3.2 (2.4.2) |
|
78
|
-
| | (MRI) Ruby 1.9.2 | GMP 5.0.1 (3.0.0) |
|
79
|
-
| | (RBX) Rubinius 1.1 | GMP 4.3.2 (2.4.2) |
|
80
|
-
| | (RBX) Rubinius 1.1 | GMP 5.0.1 (3.0.0) |
|
81
|
-
+-----------------------------------------+--------------------+-------------------+
|
82
|
-
| Windows 7 on x86_64 (64-bit) | (MRI) Ruby 1.8.7 | GMP 4.3.2 (2.4.2) |
|
83
|
-
| | (MRI) Ruby 1.8.7 | GMP 5.0.1 (3.0.0) |
|
84
|
-
| | (MRI) Ruby 1.9.1 | GMP 4.3.2 (2.4.2) |
|
85
|
-
| | (MRI) Ruby 1.9.1 | GMP 5.0.1 (3.0.0) |
|
86
|
-
| | (MRI) Ruby 1.9.2 | GMP 4.3.2 (2.4.2) |
|
87
|
-
| | (MRI) Ruby 1.9.2 | GMP 5.0.1 (3.0.0) |
|
88
|
-
+-----------------------------------------+--------------------+-------------------+
|
89
|
-
| Windows XP on x86 (32-bit) | (MRI) Ruby 1.9.1 | GMP 4.3.2 (2.4.2) |
|
90
|
-
| | (MRI) Ruby 1.9.1 | GMP 5.0.1 (3.0.0) |
|
91
|
-
+-----------------------------------------+--------------------+-------------------+
|
92
|
-
|
93
|
-
=Authors
|
94
|
-
|
95
|
-
* Tomasz Wegrzanowski
|
96
|
-
* srawlins
|
97
|
-
|
98
|
-
=Constants
|
99
|
-
|
100
|
-
The GMP module includes the following constants. Mathematical constants, such
|
101
|
-
as pi, are defined under class methods of GMP::F, listed below.
|
102
|
-
|
103
|
-
GMP::GMP_VERSION #=> A string like "5.0.1"
|
104
|
-
GMP::GMP_CC #=> The compiler used to compile GMP
|
105
|
-
GMP::GMP_CFLAGS #=> The CFLAGS used to compile GMP
|
106
|
-
GMP::GMP_BITS_PER_LIMB #=> The number of bits per limb
|
107
|
-
GMP::GMP_NUMB_MAX #=> The maximum value that can be stored in the number part of a limb
|
108
|
-
(if MPFR is available)
|
109
|
-
GMP::MPFR_VERSION #=> A string like "2.4.2"
|
110
|
-
GMP::MPFR_PREC_MIN #=> The minimum precision available
|
111
|
-
GMP::MPFR_PREC_MAX #=> The maximum precision available
|
112
|
-
GMP::GMP_RNDN #=> The constant representing "round to nearest"
|
113
|
-
GMP::GMP_RNDZ #=> The constant representing "round toward zero"
|
114
|
-
GMP::GMP_RNDU #=> The constant representing "round toward plus infinity"
|
115
|
-
GMP::GMP_RNDD #=> The constant representing "round toward minus infinity"
|
116
|
-
New in MPFR 3.0.0:
|
117
|
-
GMP::MPFR_RNDN
|
118
|
-
GMP::MPFR_RNDZ
|
119
|
-
GMP::MPFR_RNDU
|
120
|
-
GMP::MPFR_RNDD
|
121
|
-
GMP::MPFR_RNDA #=> The constant representing "round away from zero"
|
122
|
-
|
123
|
-
=Classes
|
124
|
-
|
125
|
-
The GMP module is provided with following classes:
|
126
|
-
* GMP::Z - infinite precision integer numbers
|
127
|
-
* GMP::Q - infinite precision rational numbers
|
128
|
-
* GMP::F - arbitrary precision floating point numbers
|
129
|
-
* GMP::RandState - states of individual random number generators
|
130
|
-
|
131
|
-
Numbers are created by using new().
|
132
|
-
Constructors can take following arguments:
|
133
|
-
|
134
|
-
GMP::Z.new()
|
135
|
-
GMP::Z.new(GMP::Z)
|
136
|
-
GMP::Z.new(Fixnum)
|
137
|
-
GMP::Z.new(Bignum)
|
138
|
-
GMP::Z.new(String)
|
139
|
-
GMP::Q.new()
|
140
|
-
GMP::Q.new(GMP::Q)
|
141
|
-
GMP::Q.new(String)
|
142
|
-
GMP::Q.new(any GMP::Z initializer)
|
143
|
-
GMP::Q.new(any GMP::Z initializer, any GMP::Z initializer)
|
144
|
-
GMP::F.new()
|
145
|
-
GMP::F.new(GMP::Z, precision=0)
|
146
|
-
GMP::F.new(GMP::Q, precision=0)
|
147
|
-
GMP::F.new(GMP::F)
|
148
|
-
GMP::F.new(GMP::F, precision)
|
149
|
-
GMP::F.new(String, precision=0)
|
150
|
-
GMP::F.new(Fixnum, precision=0)
|
151
|
-
GMP::F.new(Bignum, precision=0)
|
152
|
-
GMP::F.new(Float, precision=0)
|
153
|
-
GMP::RandState.new([algorithm] [, algorithm_args])
|
154
|
-
|
155
|
-
You can also call them as:
|
156
|
-
GMP.Z(args)
|
157
|
-
GMP.Q(args)
|
158
|
-
GMP.F(args)
|
159
|
-
GMP.RandState()
|
160
|
-
|
161
|
-
=Methods
|
162
|
-
|
163
|
-
GMP::Z, GMP::Q and GMP::F
|
164
|
-
+ addition
|
165
|
-
- substraction
|
166
|
-
* multiplication
|
167
|
-
/ division
|
168
|
-
to_s convert to string. For GMP::Z, this method takes
|
169
|
-
one optional argument, a base. The base can be a
|
170
|
-
Fixnum in the ranges [2, 62] or [-36, -2] or a
|
171
|
-
Symbol: :bin, :oct, :dec, or :hex.
|
172
|
-
-@ negation
|
173
|
-
neg! in-place negation
|
174
|
-
abs absolute value
|
175
|
-
asb! in-place absolute value
|
176
|
-
coerce promotion of arguments
|
177
|
-
== equality test
|
178
|
-
<=>,>=,>,<=,< comparisions
|
179
|
-
class methods of GMP::Z
|
180
|
-
fac(n) factorial of n
|
181
|
-
fib(n) nth fibonacci number
|
182
|
-
pow(n,m) n to mth power
|
183
|
-
GMP::Z and GMP::Q
|
184
|
-
swap efficiently swap contents of two objects, there
|
185
|
-
is no GMP::F.swap because various GMP::F objects
|
186
|
-
may have different precisions, which would make
|
187
|
-
them unswapable
|
188
|
-
GMP::Z
|
189
|
-
to_i convert to Fixnum or Bignum
|
190
|
-
add! in-place addition
|
191
|
-
sub! in-place subtraction
|
192
|
-
addmul!(b,c) in-place += b*c
|
193
|
-
submul!(b,c) in-place -= b*c
|
194
|
-
tdiv,fdiv,cdiv truncate, floor and ceil division
|
195
|
-
tmod,fmod,cmod truncate, floor and ceil modulus
|
196
|
-
>> shift right, floor
|
197
|
-
divisible?(b) true if divisible by b
|
198
|
-
** power
|
199
|
-
powmod power modulo
|
200
|
-
[],[]= testing and setting bits (as booleans)
|
201
|
-
scan0,scan1 starting at bitnr (1st arg), scan for a 0 or 1
|
202
|
-
(respectively), then return the index of the
|
203
|
-
first instance.
|
204
|
-
cmpabs comparison of absolute value
|
205
|
-
com 2's complement
|
206
|
-
com! in-place 2's complement
|
207
|
-
&,|,^ logical operations: and, or, xor
|
208
|
-
even? is even
|
209
|
-
odd? is odd
|
210
|
-
<< shift left
|
211
|
-
tshr shift right, truncate
|
212
|
-
lastbits_pos(n) last n bits of object, modulo if negative
|
213
|
-
lastbits_sgn(n) last n bits of object, preserve sign
|
214
|
-
power? is perfect power
|
215
|
-
square? is perfect square
|
216
|
-
sqrt square root
|
217
|
-
sqrt! change the object into its square root
|
218
|
-
sqrtrem square root, remainder
|
219
|
-
root(n) nth root
|
220
|
-
probab_prime? 0 if composite, 1 if probably prime, 2 if
|
221
|
-
certainly prime
|
222
|
-
nextprime next *probable* prime
|
223
|
-
nextprime! change the object into its next *probable* prime
|
224
|
-
gcd, gcdext greatest common divisor
|
225
|
-
invert(m) invert mod m
|
226
|
-
jacobi jacobi symbol
|
227
|
-
legendre legendre symbol
|
228
|
-
remove(n) remove all occurences of factor n
|
229
|
-
popcount the number of bits equal to 1
|
230
|
-
sizeinbase(b) digits in base b
|
231
|
-
size_in_bin digits in binary
|
232
|
-
size number of limbs
|
233
|
-
GMP::Q
|
234
|
-
num numerator
|
235
|
-
den denominator
|
236
|
-
inv inversion
|
237
|
-
inv! in-place inversion
|
238
|
-
floor,ceil,trunc nearest integer
|
239
|
-
class methods of GMP::F
|
240
|
-
default_prec get default precision
|
241
|
-
default_prec= set default precision
|
242
|
-
GMP::F
|
243
|
-
prec get precision
|
244
|
-
floor,ceil,trunc nearest integer, GMP::F is returned, not GMP::Z
|
245
|
-
floor!,ceil!,trunc! in-place nearest integer
|
246
|
-
GMP::RandState
|
247
|
-
seed(integer) seed the generator with a Fixnum or GMP::Z
|
248
|
-
urandomb(fixnum) get uniformly distributed random number between 0
|
249
|
-
and 2^fixnum-1, inclusive
|
250
|
-
urandomm(integer) get uniformly distributed random number between 0
|
251
|
-
and integer-1, inclusive
|
252
|
-
GMP (timing functions for GMPbench (0.2))
|
253
|
-
cputime milliseconds of cpu time since Ruby start
|
254
|
-
time times the execution of a block
|
255
|
-
|
256
|
-
*only if MPFR is available*
|
257
|
-
class methods of GMP::F
|
258
|
-
const_log2 returns the natural log of 2
|
259
|
-
const_pi returns pi
|
260
|
-
const_euler returns euler
|
261
|
-
const_catalan returns catalan
|
262
|
-
GMP::F
|
263
|
-
sqrt square root of the object
|
264
|
-
rec_sqrt square root of the recprical of the object
|
265
|
-
cbrt cube root of the object
|
266
|
-
** power
|
267
|
-
log natural logarithm of object
|
268
|
-
log2 binary logarithm of object
|
269
|
-
log10 decimal logarithm of object
|
270
|
-
exp e^object
|
271
|
-
exp2 2^object
|
272
|
-
exp10 10^object
|
273
|
-
log1p the same as (object + 1).log, with better
|
274
|
-
precision
|
275
|
-
expm1 the same as (object.exp) - 1, with better
|
276
|
-
precision
|
277
|
-
eint exponential integral of object
|
278
|
-
li2 real part of the dilogarithm of object
|
279
|
-
gamma Gamma fucntion of object
|
280
|
-
lngamma logarithm of the Gamma function of object
|
281
|
-
digamma Digamma function of object (MPFR_VERSION >= "3.0.0")
|
282
|
-
zeta Reimann Zeta function of object
|
283
|
-
erf error function of object
|
284
|
-
erfc complementary error function of object
|
285
|
-
j0 first kind Bessel function of order 0 of object
|
286
|
-
j1 first kind Bessel function of order 1 of object
|
287
|
-
jn first kind Bessel function of order n of object
|
288
|
-
y0 second kind Bessel function of order 0 of object
|
289
|
-
y1 second kind Bessel function of order 1 of object
|
290
|
-
yn second kind Bessel function of order n of object
|
291
|
-
agm arithmetic-geometric mean
|
292
|
-
hypot
|
293
|
-
cos \
|
294
|
-
sin |
|
295
|
-
tan |
|
296
|
-
sin_cos |
|
297
|
-
sec |
|
298
|
-
csc |
|
299
|
-
cot |
|
300
|
-
acos |
|
301
|
-
asin |
|
302
|
-
atan | trigonometric functions
|
303
|
-
atan2 |
|
304
|
-
cosh | of the object
|
305
|
-
sinh |
|
306
|
-
tanh |
|
307
|
-
sinh_cosh |
|
308
|
-
sec |
|
309
|
-
csc |
|
310
|
-
cot |
|
311
|
-
acosh |
|
312
|
-
asinh |
|
313
|
-
atanh /
|
314
|
-
nan? \
|
315
|
-
infinite? | type of floating point number
|
316
|
-
finite? |
|
317
|
-
number? |
|
318
|
-
regular? / (MPFR_VERSION >= "3.0.0")
|
319
|
-
GMP::RandState
|
320
|
-
mpfr_urandomb(fixnum) get uniformly distributed random floating-point
|
321
|
-
number within 0 <= rop < 1
|
322
|
-
|
323
|
-
|
324
|
-
=Functional Mappings
|
325
|
-
|
326
|
-
In order to align better with the GMP paradigms of using return arguments, I have started creating "functional mappings", singleton methods that map directly to functions in GMP. These methods take return arguments, so that passing an object to a functional mapping may change the object itself. For example:
|
327
|
-
|
328
|
-
a = GMP::Z(0)
|
329
|
-
b = GMP::Z(13)
|
330
|
-
c = GMP::Z(17)
|
331
|
-
GMP::Z.add(a, b, c)
|
332
|
-
a #=> 30
|
333
|
-
|
334
|
-
Here's a fun list of all of the functional mappings written so far:
|
335
|
-
|
336
|
-
GMP::Z
|
337
|
-
.abs .add .addmul .cdiv_q_2exp .cdiv_r_2exp .com
|
338
|
-
.divexact .fdiv_q_2exp .fdiv_r_2exp .lcm .mul .mul_2exp
|
339
|
-
.neg .nextprime .sqrt .sub .submul .tdiv_q_2exp
|
340
|
-
.tdiv_r_2exp
|
341
|
-
|
342
|
-
=Documentation
|
343
|
-
|
344
|
-
* This README (https://github.com/srawlins/gmp)
|
345
|
-
* Loren Segal and the guys at RubyGems.org are badasses. YARDoc is here:
|
346
|
-
http://rubydoc.info/gems/gmp/frames
|
347
|
-
* There should be a manual.pdf at https://github.com/srawlins/gmp/blob/master/manual.pdf
|
348
|
-
I spend waaay too much time working on this, but it looks very pretty.
|
349
|
-
* CHANGELOG (https://github.com/srawlins/gmp/blob/master/CHANGELOG)
|
350
|
-
|
351
|
-
=Testing
|
352
|
-
|
353
|
-
Tests can be run with:
|
354
|
-
|
355
|
-
cd test
|
356
|
-
ruby unit_tests.rb
|
357
|
-
|
358
|
-
If you have the unit_test gem installed, all tests should pass. Otherwise, one
|
359
|
-
test may error. I imagine there is a bug in Ruby's built-in Test::Unit package
|
360
|
-
that is fixed with the unit_test gem.
|
361
|
-
|
362
|
-
=Known Issues
|
363
|
-
|
364
|
-
* Don't call GMP::RandState(:lc_2exp_size). Give a 2nd arg.
|
365
|
-
|
366
|
-
=Precision
|
367
|
-
|
368
|
-
Precision can be explicitely set as second argument for GMP::F.new().
|
369
|
-
|
370
|
-
If there is no explicit precision, highest precision of all GMP::F arguments is
|
371
|
-
used. That doesn't ensure that result will be exact. For details, consult any
|
372
|
-
paper about floating point arithmetics.
|
373
|
-
|
374
|
-
Default precision can be explicitely set by passing 0 as the second argument
|
375
|
-
for to GMP::F.new(). In particular, you can set precision of copy of GMP::F
|
376
|
-
object by:
|
377
|
-
new_obj = GMP::F.new(old_obj, 0)
|
378
|
-
|
379
|
-
Precision argument, and default_precision will be rounded up to whatever GMP
|
380
|
-
thinks is appropriate.
|
381
|
-
|
382
|
-
=Benchmarking
|
383
|
-
|
384
|
-
"GMP is carefully designed to be as fast as possible." Therefore, I believe it
|
385
|
-
is very important for GMP, and its various language bindings to be benchmarked.
|
386
|
-
In recent years, the GMP team developed GMPbench, an elegant, weighted
|
387
|
-
benchmark. Currently, at http://www.gmplib.org/gmpbench.html they maintain a
|
388
|
-
list of recent benchmark results, broken down by CPU, CPU freq, ABI, and
|
389
|
-
compiler flags; GMPbench compares different processor's performance against
|
390
|
-
eachother, rather than GMP against other bignum libraries, or comparing
|
391
|
-
different versions of GMP.
|
392
|
-
|
393
|
-
I intend to build a plug-in to GMPbench that will test the ruby gmp gem. The
|
394
|
-
results of this benchmark should be directly comparable with the results of GMP
|
395
|
-
(on same CPU, etc.). Rather than write a benchmark from the ground up, or try
|
396
|
-
to emulate what GMPbench does, a plug-in will allow for this type of
|
397
|
-
comparison. And in fact, GMPbench is (perhaps intentionally) written perfectly
|
398
|
-
to allow for plugging in.
|
399
|
-
|
400
|
-
Various scores are derived from GMPbench by running the <tt>runbench</tt>
|
401
|
-
script. This script compiles and runs various individual programs that
|
402
|
-
measure the performance of base functions, such as multiply, and app functions
|
403
|
-
such as rsa.
|
404
|
-
|
405
|
-
The gmp gem benchmark uses the GMPbench framework (that is, runbench, gexpr,
|
406
|
-
and the timing methods), and plugs in ruby scripts as the individual programs.
|
407
|
-
Right now, there are only three such plugged in ruby scripts:
|
408
|
-
|
409
|
-
* multiply - measures performance of multiplying (or squaring) GMP::Z objects
|
410
|
-
whose size (in bits) is given by 1 or 2 operands.
|
411
|
-
* divide - measures performance of dividing two GMP::Z objects (using tdiv)
|
412
|
-
whose size (in bits) is given by 2 operands.
|
413
|
-
* rsa - measures performance of using RSA to sign messages. The size of pq, the
|
414
|
-
product of the two co-prime GMP::Z objects, p and q, is given by 1 operand.
|
415
|
-
|
416
|
-
<b>OOOLLLDDD... UPDATE PLZ</b>
|
417
|
-
|
418
|
-
My guess is that the increase in ruby gmp gem overhead is caused by increased
|
419
|
-
efficiency in GMP; the inefficiencies of the gmp gem are relatively greater.
|
420
|
-
|
421
|
-
=Todo
|
422
|
-
|
423
|
-
* GMP::Z#to_d_2exp, #congruent?, #rootrem, #lcm, #kronecker, #bin,
|
424
|
-
#fib2, #lucnum, #lucnum2, #hamdist, #combit, #fits_x?
|
425
|
-
* GMP::Q#to_s(base), GMP::F#to_s(base) (test it!)
|
426
|
-
* benchmark gcdext, pi
|
427
|
-
* use Rake use Rake use Rake
|
428
|
-
|
429
|
-
These are inherited from Tomasz. I will go through these and see which are
|
430
|
-
still relevant, and which I understand.
|
431
|
-
|
432
|
-
* mpz_fits_* and 31 vs. 32 integer variables
|
433
|
-
* fix all sign issues (don't know what these are)
|
434
|
-
* to_s vs. inspect
|
435
|
-
* check if mpz_addmul_ui would optimize some statements
|
436
|
-
* some system that allows using denref and numref as normal ruby objects (?)
|
437
|
-
* takeover code that replaces all Bignums with GMP::Z
|
438
|
-
* better bignum parser (how? to_s seems good to me.)
|
439
|
-
* zero-copy method for strings generation
|
440
|
-
* benchmarks against Python GMP and Perl GMP
|
441
|
-
* dup methods
|
442
|
-
* integrate F into system
|
443
|
-
* should Z.[] bits be 0/1 or true/false, 0 is true, what might badly surprise users
|
444
|
-
* any2small_integer()
|
445
|
-
* check asm output, especially local memory efficiency
|
446
|
-
* it might be better to use `register' for some local variables
|
447
|
-
* powm with negative exponents
|
448
|
-
* check if different sorting of operatations gives better cache usage
|
449
|
-
* GMP::* op RubyFloat and RubyFloat op GMP::*
|
450
|
-
* sort checks
|