gmp 0.4.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/CHANGELOG +109 -0
  2. data/INSTALL +4 -0
  3. data/README.rdoc +357 -0
  4. data/benchmark/COPYING +674 -0
  5. data/benchmark/README +75 -0
  6. data/benchmark/divide +34 -0
  7. data/benchmark/gcd +38 -0
  8. data/benchmark/gexpr +0 -0
  9. data/benchmark/gexpr.c +359 -0
  10. data/benchmark/multiply +44 -0
  11. data/benchmark/rsa +93 -0
  12. data/benchmark/runbench +147 -0
  13. data/benchmark/version +1 -0
  14. data/ext/extconf.rb +30 -0
  15. data/ext/gmp.c +197 -0
  16. data/ext/gmpbench_timing.c +80 -0
  17. data/ext/gmpf.c +595 -0
  18. data/ext/gmpf.h +144 -0
  19. data/ext/gmpq.c +780 -0
  20. data/ext/gmpq.h +12 -0
  21. data/ext/gmprandstate.c +224 -0
  22. data/ext/gmpz.c +1968 -0
  23. data/ext/gmpz.h +20 -0
  24. data/ext/libgmp-10.dll +0 -0
  25. data/ext/ruby_gmp.h +243 -0
  26. data/ext/takeover.h +36 -0
  27. data/manual.pdf +0 -0
  28. data/manual.tex +804 -0
  29. data/test/README +34 -0
  30. data/test/tc_cmp.rb +74 -0
  31. data/test/tc_division.rb +109 -0
  32. data/test/tc_f_arithmetics_coersion.rb +71 -0
  33. data/test/tc_f_precision.rb +48 -0
  34. data/test/tc_fib_fac_nextprime.rb +51 -0
  35. data/test/tc_floor_ceil_truncate.rb +21 -0
  36. data/test/tc_logical_roots.rb +48 -0
  37. data/test/tc_q.rb +27 -0
  38. data/test/tc_q_basic.rb +41 -0
  39. data/test/tc_random.rb +54 -0
  40. data/test/tc_sgn_neg_abs.rb +47 -0
  41. data/test/tc_swap.rb +19 -0
  42. data/test/tc_z.rb +71 -0
  43. data/test/tc_z_basic.rb +35 -0
  44. data/test/tc_z_exponentiation.rb +22 -0
  45. data/test/tc_z_gcd_lcm_invert.rb +57 -0
  46. data/test/tc_z_jac_leg_rem.rb +73 -0
  47. data/test/tc_z_logic.rb +54 -0
  48. data/test/tc_z_shifts_last_bits.rb +22 -0
  49. data/test/tc_z_to_d_to_i.rb +24 -0
  50. data/test/tc_zerodivisionexceptions.rb +17 -0
  51. data/test/test-12.rb +14 -0
  52. data/test/test-19.rb +13 -0
  53. data/test/test-20.rb +29 -0
  54. data/test/test-21.rb +37 -0
  55. data/test/test-22.rb +12 -0
  56. data/test/test-23.rb +11 -0
  57. data/test/test_helper.rb +8 -0
  58. data/test/unit_tests.rb +39 -0
  59. metadata +115 -0
@@ -0,0 +1,109 @@
1
+ 0.4.0:
2
+ * Support for Windows introduced. gmp-x86-mswin32 gem should be used.
3
+ * All tests should pass under Windows.
4
+ * Support for Windows in benchmark started. Still buggy.
5
+ * Added tests for GMP::Z.gcd.
6
+ * Added tests for GMP::Z.invert.
7
+ * Added tests for GMP::RandState (seed, urandomb).
8
+ * Added documentation for GMP::Z.gcd.
9
+ * Added documentation for GMP::Z.invert.
10
+ * Added documentation for GMP::RandState (new, seed, urandomb).
11
+ * Cleaned up documentation (fixed GMP :: Z spacings).
12
+ * Added benchmark/gcd
13
+ * Unit test results: 69 tests, 533 assertions, 0 failures, 0 errors
14
+
15
+ 0.2.11:
16
+ * Added GMP::Z.gcd. _not_ tested or documented.
17
+ * Added GMP::Z.invert. _not_ tested or documented.
18
+ * Added GMP::Z.sizeinbase and size_in_bin. _not_ tested or documented.
19
+ * benchmark/rsa is complete, assuming gcd and invert function properly.
20
+
21
+ 0.2.10:
22
+ * Added GMP::Z.%. Tested. Documented.
23
+ * Beginning benchmark/rsa (it required %).
24
+
25
+ 0.2.9:
26
+ * benchmark/ finally something.
27
+ * GMP::time and GMP::cputime introduced.
28
+ * GMP::RandState.new now supports different algorithms.
29
+
30
+ 0.2.8:
31
+ * GMP::RandState introduced. urandomb supported.
32
+ * PDF documentation is extended.
33
+
34
+ 0.2.2:
35
+ * GMP::Z.jacobi and GPM::Z#jacobi work and are tested.
36
+ * GMP::Z.legendre works and is tested.
37
+ * GMP::Z.next_prime is an alias for GMP::Z.nextprime.
38
+ * GMP::Z.next_prime! is an alias for GMP::Z.nextprime!.
39
+ * GMP::Z.remove works as it is supposed to.
40
+ * PDF documentation is extended.
41
+
42
+ 0.2.1:
43
+ * Got GMP::F(Fixnum) working, (I think it already was).
44
+ * More and more documentation in PDF.
45
+
46
+ 0.1.9:
47
+ * Cleaning up more documentation in PDF format.
48
+
49
+ 0.1.8:
50
+ * Added test: tc_division, in progress.
51
+ * Unit test results: 56 tests, 361 assertions, 0 failures, 0 errors
52
+ * Added to_f ==> to_d aliases for GMP::Q and GMP::F.
53
+
54
+ 0.1.7:
55
+ * Added tests: tc_shifts_last_bits, tc_logical_roots, tc_f_precision,
56
+ tc_f_arithmetics_coersion, tc_default_prec
57
+ * Unit test results: 54 tests, 326 assertions, 0 failures, 0 errors
58
+ * Fixed defect in GMP::F.sub when argument is Bignum
59
+ * Fixed defect in GMP::F.div when argument is Bignum
60
+ * Added documentation "manual" in form of a LaTeX-based PDF. Very incomplete
61
+ * as of yet.
62
+
63
+ 0.1.6.2:
64
+ * Added optional argument to GMP::Z.to_s. Supply base as either a Fixnum or
65
+ a Symbol like :hex to get the string in a different base.
66
+
67
+ 0.1.6:
68
+ * Tested on OS X 10.5.8 with Ruby 1.9.1. It's a go!
69
+ * Tested on LinuxMint 7 with Ruby 1.8.7. It's a go! Ping me if you have Linux
70
+ problems.
71
+ * Added documentation.
72
+ * Cleaned up source.
73
+ * Added tests: tc_swap, tc_floor_ceil_truncate, tc_to_i_to_d
74
+
75
+ 0.1.5:
76
+ * Merged in reorg changes: Files like gmpz.c allow for documenting the C
77
+ extension methods.
78
+ * A good portion of the documentation has been written, may not be included
79
+ yet, but can be generated with
80
+ rdoc README.rdoc ext/*.c ext/*.h
81
+
82
+ 0.1.4:
83
+ * Fixed a lot of gemspec problems
84
+ * Many more tests
85
+ * Tested on OS X 10.5.8
86
+
87
+ 0.1.1:
88
+ * Attempting to revitalize through GitHub
89
+ * no changes to code yet
90
+ * modernizing files, eg with new ruby standards, towards a gem
91
+
92
+ 1.0:
93
+ * MPFR support
94
+ * better string conversion
95
+ * Debian package
96
+
97
+ alpha9:
98
+ * more GMP::F code
99
+ * GMP::Z division
100
+
101
+ alpha8:
102
+ * various minor changes
103
+
104
+ alpha7:
105
+ * more GMP::F code
106
+
107
+ alpha6:
108
+ * basic support for GMP::F
109
+ * various minor changes
data/INSTALL ADDED
@@ -0,0 +1,4 @@
1
+ To compile:
2
+ $ ./extconf.rb
3
+ $ make
4
+ $ make install
@@ -0,0 +1,357 @@
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.4.0 on:
51
+ +-------------------------------------+-------------------+-----------+
52
+ | Platform | Ruby | GMP |
53
+ +-------------------------------------+-------------------+-----------+
54
+ | Cygwin 1.7 on x86 | (MRI) Ruby 1.8.7 | GMP 4.3.1 |
55
+ | | | GMP 4.3.2 |
56
+ | | | GMP 5.0.0 |
57
+ |-------------------------------------+-------------------+-----------|
58
+ | Windows XP on x86 | (MRI) Ruby 1.9.1 | GMP 5.0.1 |
59
+ |-------------------------------------+-------------------+-----------|
60
+ | Linux (LinuxMint 7) on x86 (32-bit) | (MRI) Ruby 1.8.7 | GMP 4.3.1 |
61
+ |-------------------------------------+-------------------+-----------|
62
+ | Mac OS X 10.5.7 on x86 (32-bit) | (MRI) Ruby 1.8.6 | GMP 4.3.1 |
63
+ | | (MRI) Ruby 1.9.1 | |
64
+ +-------------------------------------+-------------------+-----------+
65
+
66
+ <b>Note:</b> To get this running on Mac OS X (32-bit), I compiled GMP 4.3.1 with:
67
+ ./configure ABI=32 --disable-dependency-tracking
68
+
69
+ =Authors
70
+
71
+ * Tomasz Wegrzanowski
72
+ * srawlins
73
+
74
+ =Classes
75
+
76
+ The module GMP is provided with following classes:
77
+ * GMP::Z - infinite precision integer numbers
78
+ * GMP::Q - infinite precision rational numbers
79
+ * GMP::F - arbitrary precision floating point numbers
80
+ * GMP::RandState - states of individual random number generators
81
+
82
+ Numbers are created by using new().
83
+ Constructors can take following arguments:
84
+
85
+ GMP::Z.new()
86
+ GMP::Z.new(GMP::Z)
87
+ GMP::Z.new(Fixnum)
88
+ GMP::Z.new(Bignum)
89
+ GMP::Z.new(String)
90
+ GMP::Q.new()
91
+ GMP::Q.new(GMP::Q)
92
+ GMP::Q.new(String)
93
+ GMP::Q.new(any GMP::Z initializer)
94
+ GMP::Q.new(any GMP::Z initializer, any GMP::Z initializer)
95
+ GMP::F.new()
96
+ GMP::F.new(GMP::Z, precision=0)
97
+ GMP::F.new(GMP::Q, precision=0)
98
+ GMP::F.new(GMP::F)
99
+ GMP::F.new(GMP::F, precision)
100
+ GMP::F.new(String, precision=0)
101
+ GMP::F.new(Fixnum, precision=0)
102
+ GMP::F.new(Bignum, precision=0)
103
+ GMP::F.new(Float, precision=0)
104
+ GMP::RandState.new([algorithm] [, algorithm_args])
105
+
106
+ You can also call them as:
107
+ GMP.Z(args)
108
+ GMP.Q(args)
109
+ GMP.F(args)
110
+ GMP.RandState()
111
+
112
+ =Methods
113
+
114
+ GMP::Z, GMP::Q and GMP::F
115
+ + addition
116
+ - substraction
117
+ * multiplication
118
+ to_s convert to string. For GMP::Z, this method takes
119
+ one optional argument, a base. The base can be a
120
+ Fixnum in the ranges [2, 62] or [-36, -2] or a
121
+ Symbol: :bin, :oct, :dec, or :hex.
122
+ -@ negation
123
+ neg! in-place negation
124
+ abs absolute value
125
+ asb! in-place absolute value
126
+ coerce promotion of arguments
127
+ == equality test
128
+ <=>,>=,>,<=,< comparisions
129
+ class methods of GMP::Z
130
+ fac(n) factorial of n
131
+ fib(n) nth fibonacci number
132
+ pow(n,m) n to mth power
133
+ GMP::Z and GMP::Q
134
+ swap efficiently swap contents of two objects, there
135
+ is no GMP::F.swap because various GMP::F objects
136
+ may have different precisions, which would make
137
+ them unswapable
138
+ GMP::Z
139
+ add! in-place addition
140
+ sub! in-place subtraction
141
+ tdiv,fdiv,cdiv truncate, floor and ceil division
142
+ tmod,fmod,cmod truncate, floor and ceil modulus
143
+ [],[]= testing and setting bits (as booleans)
144
+ scan0,scan1 starting at bitnr (1st arg), scan for a 0 or 1
145
+ (respectively), then return the index of the
146
+ first instance.
147
+ com 2's complement
148
+ com! in-place 2's complement
149
+ &,|,^ logical operations: and, or, xor
150
+ ** power
151
+ powmod power modulo
152
+ even? is even
153
+ odd? is odd
154
+ << shift left
155
+ >> shift right, floor
156
+ tshr shift right, truncate
157
+ lastbits_pos(n) last n bits of object, modulo if negative
158
+ lastbits_sgn(n) last n bits of object, preserve sign
159
+ power? is perfect power
160
+ square? is perfect square
161
+ sqrt square root
162
+ sqrt! change the object into its square root
163
+ sqrtrem square root, remainder
164
+ root(n) nth root
165
+ probab_prime? 0 if composite, 1 if probably prime, 2 if
166
+ certainly prime
167
+ nextprime next *probable* prime
168
+ nextprime! change the object into its next *probable* prime
169
+ gcd greatest common divisor
170
+ invert(m) invert mod m
171
+ jacobi jacobi symbol
172
+ legendre legendre symbol
173
+ remove(n) remove all occurences of factor n
174
+ popcount the number of bits equal to 1
175
+ sizeinbase(b) digits in base b
176
+ size_in_bin digits in binary
177
+ to_i convert to Fixnum or Bignum
178
+ GMP::Q and GMP::F
179
+ / division
180
+ GMP::Q
181
+ num numerator
182
+ den denominator
183
+ inv inversion
184
+ inv! in-place inversion
185
+ floor,ceil,trunc nearest integer
186
+ class methods of GMP::F
187
+ default_prec get default precision
188
+ default_prec= set default precision
189
+ GMP::F
190
+ prec get precision
191
+ floor,ceil,trunc nearest integer, GMP::F is returned, not GMP::Z
192
+ floor!,ceil!,trunc! in-place nearest integer
193
+ GMP::F (only if MPFR is available)
194
+ exp e^object
195
+ expm1 the same as (object.exp) - 1, with better
196
+ precision
197
+ log natural logarithm of object
198
+ log2 binary logarithm of object
199
+ log10 decimal logarithm of object
200
+ log1p the same as (object + 1).log, with better
201
+ precision
202
+ sqrt square root of the object
203
+ cos \
204
+ sin |
205
+ tan |
206
+ acos |
207
+ asin |
208
+ atan | trigonometric functions
209
+ cosh | of the object
210
+ sinh |
211
+ tanh |
212
+ aconh |
213
+ asinh |
214
+ atanh /
215
+ nan? \
216
+ infinite? | type of floating point number
217
+ finite? |
218
+ number? /
219
+ ** power
220
+ GMP::RandState
221
+ seed(integer) seed the generator with a Fixnum or GMP::Z
222
+ urandomb(fixnum) get uniformly distributed random number between 0
223
+ and 2^fixnum-1, inclusive
224
+ GMP (timing functions for GMPbench (0.2))
225
+ cputime milliseconds of cpu time since Ruby start
226
+ time times the execution of a block
227
+
228
+
229
+ =Testing
230
+
231
+ Tests can be run with:
232
+
233
+ cd test
234
+ ruby unit_tests.rb
235
+
236
+ If you have the unit_test gem installed, all tests should pass. Otherwise, one
237
+ test may error. I imagine there is a bug in Ruby's built-in Test::Unit package
238
+ that is fixed with the unit_test gem.
239
+
240
+ =Known Issues
241
+
242
+ * GMP::Z#pow does not appear to be working at all. Looking at the code, I don't
243
+ think it ever did.
244
+ * Don't call GMP::RandState(:lc_2exp_size). Give a 2nd arg.
245
+
246
+ =Precision
247
+
248
+ Precision can be explicitely set as second argument for GMP::F.new().
249
+
250
+ If there is no explicit precision, highest precision of all GMP::F arguments is
251
+ used. That doesn't ensure that result will be exact. For details, consult any
252
+ paper about floating point arithmetics.
253
+
254
+ Default precision can be explicitely set by passing 0 to GMP::F.new(). In
255
+ particular, you can set precision of copy of GMP::F object by:
256
+ new_obj = GMP::F.new(old_obj, 0)
257
+
258
+ Precision argument, and default_precision will be rounded up to whatever GMP
259
+ thinks is appropriate.
260
+
261
+ =Benchmarking
262
+
263
+ "GMP is carefully designed to be as fast as possible." Therefore, I believe it
264
+ is very important for GMP, and its various language bindings to be benchmarked.
265
+ In recent years, the GMP team developed GMPbench, an elegant, weighted
266
+ benchmark. Currently, at http://www.gmplib.org/gmpbench.html they maintain a
267
+ list of recent benchmark results, broken down by CPU, CPU freq, ABI, and
268
+ compiler flags; GMPbench compares different processor's performance against
269
+ eachother, rather than GMP against other bignum libraries, or comparing
270
+ different versions of GMP.
271
+
272
+ I intend to build a plug-in to GMPbench that will test the ruby gmp gem. The
273
+ results of this benchmark should be directly comparable with the results of GMP
274
+ (on same CPU, etc.). Rather than write a benchmark from the ground up, or try
275
+ to emulate what GMPbench does, a plug-in will allow for this type of
276
+ comparison. And in fact, GMPbench is (perhaps intentionally) written perfectly
277
+ to allow for plugging in.
278
+
279
+ Various scores are derived from GMPbench by running the <tt>runbench</tt>
280
+ script. This script compiles and runs various individual programs that
281
+ measure the performance of base functions, such as multiply, and app functions
282
+ such as rsa.
283
+
284
+ The gmp gem benchmark uses the GMPbench framework (that is, runbench, gexpr,
285
+ and the timing methods), and plugs in ruby scripts as the individual programs.
286
+ Right now, there are only three such plugged in ruby scripts:
287
+
288
+ * multiply - measures performance of multiplying (or squaring) GMP::Z objects
289
+ whose size (in bits) is given by 1 or 2 operands.
290
+ * divide - measures performance of dividing two GMP::Z objects (using tdiv)
291
+ whose size (in bits) is given by 2 operands.
292
+ * rsa - measures performance of using RSA to sign messages. The size of pq, the
293
+ product of the two co-prime GMP::Z objects, p and q, is given by 1 operand.
294
+
295
+ Results: on my little Intel Core Duo T2400 @ 1.83GHz:
296
+ +---------------------------------------------------------+
297
+ | GMP 4.3.1* compiled with GCC 3.4.4, I think (cygwin did |
298
+ | it) |
299
+ +------------+-----------+--------------------------------+
300
+ | test | GMP | ruby gmp gem |
301
+ | multiply | 4660 | 2473.8 (47% overhead) |
302
+ | divide | 2744 | 2253.1 (18% overhead) |
303
+ | gcd | 1004.5 | 865.13 (14% overhead) |
304
+ | rsa | 515.49 | 506.69 ( 2% overhead) |
305
+ +------------+-----------+--------------------------------+
306
+ | GMP 5.0.0 compiled with GCC 3.4.4, I think (cygwin did |
307
+ | it) |
308
+ +------------+-----------+--------------------------------+
309
+ | test | GMP | ruby gmp gem |
310
+ | multiply | 4905 | 2572.1 (48% overhead) |
311
+ | divide | 4873 | 3427.4 (30% overhead) |
312
+ | gcd | 1083.5 | 931.75 (14% overhead) |
313
+ | rsa | 520.20 | 506.14 ( 3% overhead) |
314
+ +------------+--------+-----------------------------------+
315
+ | GMP 5.0.1 compiled with GCC 3.4.5 in MinGW |
316
+ +------------+-----------+--------------------------------+
317
+ | test | GMP | ruby gmp gem |
318
+ | multiply | 4950 | xxxx.x (xx% overhead) |
319
+ | divide | 4809 | xxxx.x (xx% overhead) |
320
+ | gcd | 1071.3 | xxx.xx (xx% overhead) |
321
+ | rsa | 524.96 | xxx.xx ( x% overhead) |
322
+ +------------+--------+-----------------------------------+
323
+ \* GMP 4.3.2 evaluated to almost the same benchmarks.
324
+
325
+ My guess is that the increase in ruby gmp gem overhead is caused by increased
326
+ efficiency in GMP; the inefficiencies of the gmp gem are relatively greater.
327
+
328
+ =Todo
329
+
330
+ These are inherited from Tomasz. I will go through these and see which are
331
+ still relevant.
332
+
333
+ * mpz_fits_* and 31 vs. 32 integer variables
334
+ * all appropriate module and class methods if there are any to add
335
+ * fix all sign issues (don't know what these are)
336
+ * floats with precision control
337
+ * to_s vs. inspect
338
+ * check if mpz_addmul_ui would optimize some statements
339
+ * some system that allows using denref and numref as normal ruby objects (?)
340
+ * should we allocate global temporary variables like Perl GMP does?
341
+ * takeover code that replaces all Bignums with GMP::Z
342
+ * better bignum parser
343
+ * zero-copy method for strings generation
344
+ * put rb_raise into nice macros
345
+ * benchmarks against Python GMP (gmpy? Is this still active?) and Perl GMP
346
+ * dup methods
347
+ * integrate F into system
348
+ * should Z.[] bits be 0/1 or true/false, 0 is true, what might badly surprise users
349
+ * any2small_integer()
350
+ * check asm output, especially local memory efficiency
351
+ * it might be better to use `register' for some local variables
352
+ * powm with negative exponents
353
+ * check if different sorting of operatations gives better cache usage
354
+ * GMP::* op RubyFloat and RubyFloat op GMP::*
355
+ * sort checks
356
+ * GMP::Q.to_s(base), GMP::F.to_s(base)
357
+ * benchmark gcdext, pi