gmp 0.6.31 → 0.6.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG +11 -0
- data/FEATURES.html +4 -4
- data/README.markdown +140 -20
- data/benchmark/bench.sh +32 -0
- data/benchmark/csv.sh +1 -0
- data/benchmark/{benchmark-results-5.0.5_1.9.3_0.6.7.ods → results-5.0.5_1.9.3_0.6.7.ods} +0 -0
- data/benchmark/results-5.1.0_0.6.19.ods +0 -0
- data/benchmark/results-5.1.3_0.6.31.ods +0 -0
- data/ext/extconf.rb +4 -0
- data/ext/gmp.c +37 -1
- data/ext/gmpf.c +10 -43
- data/ext/gmpq.c +3 -2
- data/ext/gmpz.c +78 -47
- data/ext/ruby_gmp.h +2 -0
- data/manual.pdf +0 -0
- data/manual.tex +18 -8
- data/test/tc_division.rb +1 -11
- data/test/tc_f_to_s.rb +3 -0
- data/test/tc_fib_fac_nextprime.rb +28 -3
- data/test/tc_q.rb +2 -0
- data/test/tc_z_to_dis.rb +4 -1
- data/test/unit_tests.rb +45 -45
- metadata +12 -12
- data/benchmark/benchmark-results-5.1.0_0.6.19.ods +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8f050d69659030fb11abceaf21d1ad265ac6d696
|
4
|
+
data.tar.gz: e15d7ae348a201bb6f5d53754141939128fa96ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 10b8ea24e97956f68d0315211113c2b93642c16aaeb40ff767c45d5137a79b252ae2d94b5136ba4e230de2a5cf4aa3ff3f308ab51b5f8f2dc9a22d932eaa5d56
|
7
|
+
data.tar.gz: 55ebb541e81d2045a300006adc26926c8483ff3947618b21478abdba52c66eef89f0bf86e69fe2b6547427010ff60d1bab471d06ae1746bceff7041687873684
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
0.6.41
|
2
|
+
* Added GMP::Z.fib2, with documentation and tests
|
3
|
+
* Properly coerce GMP::Q and Float. GMP::Q / Float will now convert both
|
4
|
+
operands into GMP::F
|
5
|
+
* Workaround Ruby 2.0.0 bug in using --with-gmp-dir in extconf.rb (#8047)
|
6
|
+
* Fixed bugs for Z#fac, Z#2fac, Z#primorial, Z#fib, and Z#lucnum, where Ruby
|
7
|
+
would crash if a negative number was passed in as the argument.
|
8
|
+
* Aliasing #inspect to #to_s for GMP::Z, GMP::Q, and GMP::F, for better
|
9
|
+
usability in Ruby 2.x, where Object#inspect no longer calls #to_s.
|
10
|
+
* Support now verified for Ruby 2.0.0 and Ruby 2.1.0-preview1
|
11
|
+
|
1
12
|
0.6.31:
|
2
13
|
* Added GMP::Z#rootrem and tests
|
3
14
|
|
data/FEATURES.html
CHANGED
@@ -106,8 +106,8 @@ Ext.onReady(function(){
|
|
106
106
|
['GMP::Z#remove', "mpz_remove", "yes","yes", "", "no"],
|
107
107
|
['GMP::Z.fac', "mpz_fac_ui", "yes","yes", "", "no"],
|
108
108
|
['', "mpz_bin_ui<br />mpz_bin_uiui", "no", "no", "no", "no"],
|
109
|
-
['GMP::Z.fib', "mpz_fib_ui", "yes","yes",
|
110
|
-
['',
|
109
|
+
['GMP::Z.fib', "mpz_fib_ui", "yes","yes","yes", "no"],
|
110
|
+
['GMP::Z.fib2', "mpz_fib2_ui", "yes","yes","yes", "no"],
|
111
111
|
['', "mpz_lucnum_ui", "no", "no", "no", "no"],
|
112
112
|
['', "mpz_lucnum2_ui", "no", "no", "no", "no"],
|
113
113
|
['GMP::Z#==<br />GMP::Z#<=><br />' +
|
@@ -200,8 +200,8 @@ Ext.onReady(function(){
|
|
200
200
|
['GMP::Z#remove', "mpz_remove", "yes","yes", "", "no"],
|
201
201
|
['GMP::Z.fac', "mpz_fac_ui", "yes","yes", "", "no"],
|
202
202
|
['', "mpz_bin_ui<br />mpz_bin_uiui", "no", "no", "no", "no"],
|
203
|
-
['GMP::Z.fib', "mpz_fib_ui", "yes","yes",
|
204
|
-
['',
|
203
|
+
['GMP::Z.fib', "mpz_fib_ui", "yes","yes","yes", "no"],
|
204
|
+
['GMP::Z.fib2', "mpz_fib2_ui", "yes","yes","yes", "no"],
|
205
205
|
['', "mpz_lucnum_ui", "no", "no", "no", "no"],
|
206
206
|
['', "mpz_lucnum2_ui", "no", "no", "no", "no"],
|
207
207
|
['GMP::Z#==<br />GMP::Z#<=><br />' +
|
data/README.markdown
CHANGED
@@ -47,8 +47,15 @@ paragraph at [their homepage](http://gmplib.org/#WHAT):
|
|
47
47
|
> contributions, meaning users can safely use GMP. To achieve this, we will ask
|
48
48
|
> contributors to sign paperwork where they allow us to distribute their work."
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
GMP 4.3.x and GMP 5.x are each supported against Ruby (MRI) 1.9.x, 2.0.0, and
|
51
|
+
2.1.0. GMP 5.1.x is the only version of GMP that has been tested recently.
|
52
|
+
Other Ruby platforms (such as Rubinius and JRuby) should be supported, but have not
|
53
|
+
been tested recently.
|
54
|
+
|
55
|
+
### Previously
|
56
|
+
|
57
|
+
Previously, on version 0.5.47, this gem was verified as functioning in the
|
58
|
+
following combinations:
|
52
59
|
|
53
60
|
<table border="1">
|
54
61
|
<tr>
|
@@ -217,14 +224,16 @@ Methods
|
|
217
224
|
- substraction
|
218
225
|
* multiplication
|
219
226
|
/ division
|
220
|
-
to_s convert to string. For GMP::Z, this
|
221
|
-
one optional argument, a base. The
|
222
|
-
Fixnum in the ranges \[2, 62\] or
|
223
|
-
Symbol: :bin, :oct,
|
227
|
+
to_s convert to string. For GMP::Z and GMP::F, this
|
228
|
+
method takes one optional argument, a base. The
|
229
|
+
base can be a Fixnum in the ranges \[2, 62\] or
|
230
|
+
\[-36, -2\] or a Symbol: one of :bin, :oct,
|
231
|
+
:dec, or :hex.
|
232
|
+
inspect alias for #to_s
|
224
233
|
-@ negation
|
225
234
|
neg! in-place negation
|
226
235
|
abs absolute value
|
227
|
-
|
236
|
+
abs! in-place absolute value
|
228
237
|
coerce promotion of arguments
|
229
238
|
== equality test
|
230
239
|
<=>,>=,>,<=,< comparisions
|
@@ -233,7 +242,8 @@ Methods
|
|
233
242
|
2fac(n), double_fac(n) double factorial of n
|
234
243
|
mfac(n) m-multi-factorial of n
|
235
244
|
primorial(n) primorial of n
|
236
|
-
fib(n) nth
|
245
|
+
fib(n) nth Fibonacci number
|
246
|
+
fib2(n) nth and (n-1)th Fibonacci numbers
|
237
247
|
pow(n,m) n to mth power
|
238
248
|
GMP::Z and GMP::Q
|
239
249
|
swap efficiently swap contents of two objects, there
|
@@ -406,6 +416,122 @@ Here's a fun list of all of the functional mappings written so far:
|
|
406
416
|
.neg .nextprime .sqrt .sub .submul .tdiv_q_2exp
|
407
417
|
.tdiv_r_2exp
|
408
418
|
|
419
|
+
Method Tables
|
420
|
+
-------------
|
421
|
+
|
422
|
+
The following is organized in the same categories as in the GMP and MPFR manuals.
|
423
|
+
|
424
|
+
### Integer Functions
|
425
|
+
|
426
|
+
<table>
|
427
|
+
<tr><th colspan="2"><h4>Assigning Integers</h4></th></tr>
|
428
|
+
<tr><th>GMP Function</th><th>GMP::Z method</th></tr>
|
429
|
+
<tr><td>mpz_swap</td><td>GMP::Z#swap</td></tr>
|
430
|
+
|
431
|
+
<tr><th colspan="2"><h4>Converting Integers</h4>
|
432
|
+
4x C functions mapped to 3x Ruby methods; 1x unmapped C function</th></tr>
|
433
|
+
<tr><th>GMP Function</th><th>GMP::Z method</th></tr>
|
434
|
+
<tr><td>mpz_get_ui<br />
|
435
|
+
mpz_get_si</td> <td>GMP::Z#to_i</td></tr>
|
436
|
+
<tr><td>mpz_get_d</td> <td>GMP::Z#to_d</td></tr>
|
437
|
+
<tr><td>mpz_get_d_2exp</td> <td><em>not implemented yet</em></td></tr>
|
438
|
+
<tr><td>mpz_get_str</td> <td>GMP::Z#to_s</td></tr>
|
439
|
+
|
440
|
+
<tr><th colspan="2"><h4>Integer Arithmetic</h4>
|
441
|
+
12x C functions mapped to 19x Ruby methods; 2x unmapped C functions</th></tr>
|
442
|
+
<tr><th>GMP Function</th><th>GMP::Z method</th></tr>
|
443
|
+
<tr><td>mpz_add<br />
|
444
|
+
mpz_add_ui</td> <td>GMP::Z#+<br />
|
445
|
+
GMP::Z#add! (destructive method)<br />
|
446
|
+
GMP::Z.add (in-place singleton method)</td></tr>
|
447
|
+
<tr><td>mpz_sub<br />
|
448
|
+
mpz_sub_ui<br />
|
449
|
+
mpz_ui_sub (never used)</td> <td>GMP::Z#-<br />
|
450
|
+
GMP::Z#sub! (destructive method)<br />
|
451
|
+
GMP::Z.sub (in-place singleton method)</td></tr>
|
452
|
+
<tr><td>mpz_mul<br />
|
453
|
+
mpz_mul_si<br />
|
454
|
+
mpz_mul_ui (not used yet)</td><td>GMP::Z#*<br />
|
455
|
+
GMP::Z.mul (in-place singleton method)</td></tr>
|
456
|
+
<tr><td>mpz_addmul<br />
|
457
|
+
mpz_addmul_ui</td> <td>GMP::Z#addmul! (destructive method)<br />
|
458
|
+
GMP::Z.addmul (in-place singleton method)</td></tr>
|
459
|
+
<tr><td>mpz_submul<br />
|
460
|
+
mpz_submul_ui</td> <td>GMP::Z#submul! (destructive method)<br />
|
461
|
+
GMP::Z.submul (in-place singleton method)</td></tr>
|
462
|
+
<tr><td>mpz_mul_2exp</td> <td>GMP::Z.mul_2exp (in-place singleton method)</td></tr>
|
463
|
+
<tr><td>mpz_neg</td> <td>GMP::Z@-<br />
|
464
|
+
GMP::Z#neg! (destructive method)<br />
|
465
|
+
GMP::Z.neg (in-place singleton method)</td></tr>
|
466
|
+
<tr><td>mpz_abs</td> <td>GMP::Z#abs<br />
|
467
|
+
GMP::Z#abs! (destructive method)<br />
|
468
|
+
GMP::Z.abs (in-place singleton method)</td></tr>
|
469
|
+
|
470
|
+
<tr><th colspan="2"><h4>Integer Division</h4>
|
471
|
+
26x C functions mapped to 18x Ruby methods; 11x unmapped C functions</th></tr>
|
472
|
+
<tr><th>GMP Function</th><th>GMP::Z method</th></tr>
|
473
|
+
<tr><td>mpz_cdiv_q<br />
|
474
|
+
mpz_cdiv_q_ui</td> <td>GMP::Z#cdiv</td></tr>
|
475
|
+
<tr><td>mpz_cdiv_r<br />
|
476
|
+
mpz_cdiv_r_ui</td> <td>GMP::Z#cmod</td></tr>
|
477
|
+
<tr><td>mpz_cdiv_qr<br />
|
478
|
+
mpz_cdiv_qr_ui</td> <td><em>not implemented yet</em></td></tr>
|
479
|
+
<tr><td>mpz_cdiv_ui</td> <td><em>not implemented yet</em></td></tr>
|
480
|
+
<tr><td>mpz_cdiv_q_2exp<br />
|
481
|
+
mpz_cdiv_r_2exp</td> <td>GMP::Z.cdiv_q_2exp (in-place singleton method)<br />
|
482
|
+
GMP::Z.cdiv_r_2exp (in-place singleton method)</td></tr>
|
483
|
+
<tr><td>mpz_fdiv_q<br />
|
484
|
+
mpz_fdiv_q_ui</td> <td>GMP::Z#fdiv</td></tr>
|
485
|
+
<tr><td>mpz_fdiv_r<br />
|
486
|
+
mpz_fdiv_r_ui</td> <td>GMP::Z#fmod</td></tr>
|
487
|
+
<tr><td>mpz_fdiv_qr<br />
|
488
|
+
mpz_fdiv_qr_ui</td> <td><em>not implemented yet</em></td></tr>
|
489
|
+
<tr><td>mpz_fdiv_ui</td> <td><em>not implemented yet</em></td></tr>
|
490
|
+
<tr><td>mpz_fdiv_q_2exp<br />
|
491
|
+
mpz_fdiv_r_2exp</td> <td>GMP::Z.fdiv_q_2exp (in-place singleton method)<br />
|
492
|
+
GMP::Z.fdiv_r_2exp (in-place singleton method)</td></tr>
|
493
|
+
<tr><td>mpz_tdiv_q<br />
|
494
|
+
mpz_tdiv_q_ui</td> <td>GMP::Z#tdiv</td></tr>
|
495
|
+
<tr><td>mpz_tdiv_r<br />
|
496
|
+
mpz_tdiv_r_ui</td> <td>GMP::Z#tmod</td></tr>
|
497
|
+
<tr><td>mpz_tdiv_qr<br />
|
498
|
+
mpz_tdiv_qr_ui</td> <td><em>not implemented yet</em></td></tr>
|
499
|
+
<tr><td>mpz_tdiv_ui</td> <td><em>not implemented yet</em></td></tr>
|
500
|
+
<tr><td>mpz_tdiv_q_2exp<br />
|
501
|
+
mpz_tdiv_r_2exp</td> <td>GMP::Z.tdiv_q_2exp (in-place singleton method)<br />
|
502
|
+
GMP::Z.tdiv_r_2exp (in-place singleton method)</td></tr>
|
503
|
+
<tr><td>mpz_mod<br />
|
504
|
+
mpz_mod_ui</td> <td>GMP::Z#mod</td></tr>
|
505
|
+
<tr><td>mpz_divexact<br />
|
506
|
+
mpz_divexact_ui</td> <td>GMP::Z.divexact (in-place singleton method)</td></tr>
|
507
|
+
<tr><td>mpz_divisible_p<br />
|
508
|
+
mpz_divisible_ui_p</td> <td>GMP::Z#divisible?<br />
|
509
|
+
GMP::Z.divisible? (in-place singleton method)</td></tr>
|
510
|
+
<tr><td>mpz_divisible_2exp_p</td> <td><em>not implemented yet</em></td></tr>
|
511
|
+
<tr><td>mpz_congruent_p<br />
|
512
|
+
mpz_congruent_ui_p</td> <td>GMP::Z#congruent?<br />
|
513
|
+
GMP::Z.congruent? (in-place singleton method)</td></tr>
|
514
|
+
<tr><td>mpz_congruent_2exp_p</td> <td><em>not implemented yet</em></td></tr>
|
515
|
+
|
516
|
+
<tr><th colspan="2"><h4>Integer Exponentiation</h4>
|
517
|
+
|
518
|
+
<tr><th colspan="2"><h4>Integer Roots</h4>
|
519
|
+
|
520
|
+
<tr><th colspan="2"><h4>Number Theoretic Functions</h4>
|
521
|
+
|
522
|
+
<tr><th colspan="2"><h4>Integer Comparisons</h4>
|
523
|
+
|
524
|
+
<tr><th colspan="2"><h4>Integer Logic and Bit Fiddling</h4>
|
525
|
+
|
526
|
+
<tr><th colspan="2"><h4>I/O of Integers</h4>
|
527
|
+
|
528
|
+
<tr><th colspan="2"><h4>Integer Random Numbers</h4>
|
529
|
+
|
530
|
+
<tr><th colspan="2"><h4>Integer Import and Export</h4>
|
531
|
+
|
532
|
+
<tr><th colspan="2"><h4>Miscellaneous Integer Functions</h4>
|
533
|
+
</table>
|
534
|
+
|
409
535
|
Documentation
|
410
536
|
-------------
|
411
537
|
|
@@ -417,18 +543,12 @@ Documentation
|
|
417
543
|
Testing
|
418
544
|
-------
|
419
545
|
|
420
|
-
Tests can be run with
|
421
|
-
|
422
|
-
cd test
|
423
|
-
ruby unit_tests.rb
|
546
|
+
Tests can be run with `rake test`. I like to run tests and print out a quick report of Ruby, GMP, and MPFR versions with `rake report`. You can precede any rake task with `GMP=gmp_install_dir` and `MPFR=mpfr_install_dir` (or `MPFR=--no-mpfr`) to pass `--with-gmp-dir` and `--with-mpfr-dir` options to `extconf.rb` as well.
|
424
547
|
|
425
|
-
|
548
|
+
You can also run tests from an individual file with:
|
426
549
|
|
427
|
-
|
428
|
-
|
429
|
-
rake test
|
430
|
-
rake report
|
431
|
-
MPFR=no-mpfr rake report
|
550
|
+
cd test
|
551
|
+
ruby some_test_file.rb
|
432
552
|
|
433
553
|
Known Issues
|
434
554
|
------------
|
@@ -469,13 +589,14 @@ Please see [performance](https://github.com/srawlins/gmp/blob/master/performance
|
|
469
589
|
Todo
|
470
590
|
----
|
471
591
|
|
472
|
-
* `GMP::Z#to_d_2exp`, `#kronecker`, `#bin`,
|
592
|
+
* `GMP::Z#to_d_2exp`, `#kronecker`, `#bin`, `::lucnum2`, `#combit`, `#fits_x?`
|
473
593
|
* `GMP::Q#to_s(base)`, `GMP::F#to_s(base)` (test it!)
|
474
594
|
* benchmark pi
|
475
595
|
* a butt-load of functional mappings. 47-ish sets.
|
476
596
|
* investigate possible memory leaks when using `GMP::Q(22/7)` for example
|
477
597
|
* beef up `r_gmpq_initialize`; I don't like to rely on `mpz_set_value`.
|
478
598
|
* finish compile-results.rb
|
599
|
+
* check if `mpz_mul_ui` would optimize `GMP::Z#*`
|
479
600
|
* New in MPFR 3.1.0: mpfr_frexp, mpfr_grandom, mpfr_z_sub, divide-by-zero exception (?)
|
480
601
|
* JRuby doesn't like some MPFR stuff, specifically sqrt tests fail.
|
481
602
|
* Rubinius in 1.9 mode fails a sprintf test in a minor way.
|
@@ -484,7 +605,6 @@ The below are inherited from Tomasz. I will go through these and see which are
|
|
484
605
|
still relevant, and which I understand.
|
485
606
|
|
486
607
|
* `mpz_fits_*` and 31 vs. 32 integer variables
|
487
|
-
* fix all sign issues (don't know what these are)
|
488
608
|
* check if `mpz_addmul_ui` would optimize some statements
|
489
609
|
* some system that allows using denref and numref as normal ruby objects
|
490
610
|
* takeover code that replaces all `Bignums` with `GMP::Z`
|
data/benchmark/bench.sh
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#! /bin/bash
|
2
|
+
source ~/.rvm/scripts/rvm
|
3
|
+
|
4
|
+
function out {
|
5
|
+
echo "========================================"
|
6
|
+
echo "$*"
|
7
|
+
echo "========================================"
|
8
|
+
}
|
9
|
+
|
10
|
+
echo "RUBY: `ruby -v`"
|
11
|
+
echo "GMP: `ruby -r '../ext/gmp' -e \"puts GMP::GMP_VERSION\"`"
|
12
|
+
echo "GMP_CC: `ruby -r '../ext/gmp' -e \"puts GMP::GMP_CC\"`"
|
13
|
+
echo "MPFR: `ruby -r '../ext/gmp' -e \"puts GMP::MPFR_VERSION\"`"
|
14
|
+
|
15
|
+
if [[ $1 == --help ]]; then
|
16
|
+
echo "bench.sh benchmark_directory ..."
|
17
|
+
exit 1
|
18
|
+
fi
|
19
|
+
|
20
|
+
ruby_version=`ruby -v |cut -d' ' -f 2`
|
21
|
+
PATH=.:$PATH
|
22
|
+
for directory in "$@"; do
|
23
|
+
out "Benchmarking in $directory..."
|
24
|
+
cd $directory
|
25
|
+
if [ ! -f runbench ]; then
|
26
|
+
echo "Oops, not a benchmark directory! 'runbench' does not exist."
|
27
|
+
else
|
28
|
+
echo "./runbench -n |tee ${ruby_version}.txt"
|
29
|
+
./runbench -n |tee ${ruby_version}.txt
|
30
|
+
cd -
|
31
|
+
fi
|
32
|
+
done
|
data/benchmark/csv.sh
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
sed 's/[ ]*GMPbench:[ ]*//' |sed 's/[ ]*GMPbench.[a-z]*.[a-z]*([0-9,]*)[ ]*/,,,/' |sed 's/[ ]*GMPbench.[a-z]*\.[a-z]*[ ]*/,,/' |sed 's/[ ]*GMPbench.[a-z]*[ ]*/,/' |sed 's/Program.*//' |sed 's/Category.*//'
|
File without changes
|
Binary file
|
Binary file
|
data/ext/extconf.rb
CHANGED
data/ext/gmp.c
CHANGED
@@ -27,7 +27,10 @@ static VALUE r_gmpz_coerce(VALUE self, VALUE arg)
|
|
27
27
|
|
28
28
|
static VALUE r_gmpq_coerce(VALUE self, VALUE arg)
|
29
29
|
{
|
30
|
-
|
30
|
+
if (FLOAT_P(arg))
|
31
|
+
return rb_assoc_new(r_gmpfsg_new(1, &arg, cGMP_F), r_gmpfsg_new(1, &self, cGMP_F));
|
32
|
+
else
|
33
|
+
return rb_assoc_new(r_gmpqsg_new(1, &arg, cGMP_Q), self);
|
31
34
|
}
|
32
35
|
|
33
36
|
static VALUE r_gmpf_coerce(VALUE self, VALUE arg)
|
@@ -55,6 +58,34 @@ static VALUE r_gmpfsg_set_default_prec(VALUE klass, VALUE arg)
|
|
55
58
|
return Qnil;
|
56
59
|
}
|
57
60
|
|
61
|
+
ID bin_base_id; /* binary */
|
62
|
+
ID oct_base_id; /* octal */
|
63
|
+
ID dec_base_id; /* decimal */
|
64
|
+
ID hex_base_id; /* hexadecimal */
|
65
|
+
|
66
|
+
int get_base(VALUE base_val) {
|
67
|
+
ID base_id;
|
68
|
+
int base = 10;
|
69
|
+
|
70
|
+
if (FIXNUM_P(base_val)) {
|
71
|
+
base = FIX2INT(base_val);
|
72
|
+
|
73
|
+
if ((base >= 2 && base <= 62) || (base >= -36 && base <= -2))
|
74
|
+
return base;
|
75
|
+
else
|
76
|
+
rb_raise(rb_eRangeError, "base must be within [2, 62] or [-36, -2].");
|
77
|
+
} else if (SYMBOL_P(base_val)) {
|
78
|
+
base_id = rb_to_id(base_val);
|
79
|
+
if (base_id == bin_base_id) return 2;
|
80
|
+
else if (base_id == oct_base_id) return 8;
|
81
|
+
else if (base_id == dec_base_id) return 10;
|
82
|
+
else if (base_id == hex_base_id) return 16;
|
83
|
+
else rb_raise(rb_eRangeError, "base must be within [2, 62] or [-36, -2].");
|
84
|
+
} else {
|
85
|
+
rb_raise(rb_eTypeError, "Expected Fixnum or one of :bin, :oct, :dec, :hex");
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
58
89
|
VALUE r_gmpsg_sprintf2(VALUE klass, VALUE format, VALUE arg) {
|
59
90
|
VALUE res;
|
60
91
|
char *buffer;
|
@@ -128,6 +159,11 @@ mp_rnd_t r_get_rounding_mode(VALUE rnd)
|
|
128
159
|
rb_define_method(rb_cBignum, ruby_fname, takeover_bignum_##fname, -1);
|
129
160
|
|
130
161
|
void Init_gmp() {
|
162
|
+
bin_base_id = rb_intern("bin");
|
163
|
+
oct_base_id = rb_intern("oct");
|
164
|
+
dec_base_id = rb_intern("dec");
|
165
|
+
hex_base_id = rb_intern("hex");
|
166
|
+
|
131
167
|
mGMP = rb_define_module("GMP");
|
132
168
|
rb_define_const(mGMP, "GMP_VERSION", rb_str_new2(gmp_version));
|
133
169
|
rb_define_const(mGMP, "GMP_CC", rb_str_new2(__GMP_CC));
|
data/ext/gmpf.c
CHANGED
@@ -136,6 +136,8 @@ VALUE r_gmpf_initialize(int argc, VALUE *argv, VALUE self)
|
|
136
136
|
}
|
137
137
|
|
138
138
|
#else
|
139
|
+
(void)base;
|
140
|
+
|
139
141
|
if (prec == 0)
|
140
142
|
r_mpf_init (self_val);
|
141
143
|
else
|
@@ -266,54 +268,17 @@ VALUE r_gmpf_to_s(int argc, VALUE *argv, VALUE self)
|
|
266
268
|
char *str, *str2;
|
267
269
|
VALUE res;
|
268
270
|
mp_exp_t exponent;
|
269
|
-
|
270
|
-
|
271
|
-
int base_val = 10;
|
272
|
-
ID base_id;
|
273
|
-
const char * bin_base = "bin"; /* binary */
|
274
|
-
const char * oct_base = "oct"; /* octal */
|
275
|
-
const char * dec_base = "dec"; /* decimal */
|
276
|
-
const char * hex_base = "hex"; /* hexadecimal */
|
277
|
-
ID bin_base_id = rb_intern(bin_base);
|
278
|
-
ID oct_base_id = rb_intern(oct_base);
|
279
|
-
ID dec_base_id = rb_intern(dec_base);
|
280
|
-
ID hex_base_id = rb_intern(hex_base);
|
271
|
+
VALUE base_val;
|
272
|
+
int base = 10;
|
281
273
|
|
282
274
|
mpf_get_struct(self, self_val);
|
283
275
|
|
284
276
|
/* TODO: accept a second optional argument, n_digits */
|
285
|
-
rb_scan_args
|
286
|
-
|
287
|
-
|
288
|
-
if (NIL_P (base)) { base = INT2FIX (10); } /* default value */
|
289
|
-
if (FIXNUM_P (base)) {
|
290
|
-
base_val = FIX2INT (base);
|
291
|
-
if ((base_val >= 2 && base_val <= 62) ||
|
292
|
-
(base_val >= -36 && base_val <= -2)) {
|
293
|
-
/* good base */
|
294
|
-
} else {
|
295
|
-
base_val = 10;
|
296
|
-
rb_raise (rb_eRangeError, "base must be within [2, 62] or [-36, -2].");
|
297
|
-
}
|
298
|
-
} else if (SYMBOL_P (base)) {
|
299
|
-
base_id = rb_to_id (base);
|
300
|
-
if (base_id == bin_base_id) {
|
301
|
-
base_val = 2;
|
302
|
-
} else if (base_id == oct_base_id) {
|
303
|
-
base_val = 8;
|
304
|
-
} else if (base_id == dec_base_id) {
|
305
|
-
base_val = 10;
|
306
|
-
} else if (base_id == hex_base_id) {
|
307
|
-
base_val = 16;
|
308
|
-
} else {
|
309
|
-
base_val = 10; /* TODO: should raise an exception here. */
|
310
|
-
}
|
311
|
-
}
|
277
|
+
rb_scan_args(argc, argv, "01", &base_val);
|
278
|
+
if (NIL_P(base_val)) { base = 10; } /* default value */
|
279
|
+
else { base = get_base(base_val); }
|
312
280
|
|
313
|
-
|
314
|
-
//res = rb_str_new2(str);
|
315
|
-
|
316
|
-
str = mpfr_get_str(NULL, &exponent, base_val, 0, self_val, __gmp_default_rounding_mode);
|
281
|
+
str = mpfr_get_str(NULL, &exponent, base, 0, self_val, __gmp_default_rounding_mode);
|
317
282
|
if ((strcmp(str, "NaN") == 0) ||
|
318
283
|
(strcmp(str, "Inf") == 0) ||
|
319
284
|
(strcmp(str, "-Inf") == 0))
|
@@ -326,6 +291,7 @@ VALUE r_gmpf_to_s(int argc, VALUE *argv, VALUE self)
|
|
326
291
|
__gmp_asprintf(&str2, "-0.%se%+ld", str+1, exponent);
|
327
292
|
else
|
328
293
|
__gmp_asprintf(&str2, "0.%se%+ld", str, exponent);
|
294
|
+
|
329
295
|
res = rb_str_new2(str2);
|
330
296
|
mpfr_free_str(str2);
|
331
297
|
}
|
@@ -1288,6 +1254,7 @@ void init_gmpf()
|
|
1288
1254
|
|
1289
1255
|
// Converting Floats
|
1290
1256
|
rb_define_method(cGMP_F, "to_s", r_gmpf_to_s, -1);
|
1257
|
+
rb_define_alias(cGMP_F, "inspect", "to_s");
|
1291
1258
|
rb_define_method(cGMP_F, "to_d", r_gmpf_to_d, 0);
|
1292
1259
|
rb_define_alias(cGMP_F, "to_f", "to_d");
|
1293
1260
|
|
data/ext/gmpq.c
CHANGED
@@ -807,12 +807,13 @@ void init_gmpq()
|
|
807
807
|
// Initializing Rationals
|
808
808
|
rb_define_singleton_method(cGMP_Q, "new", r_gmpqsg_new, -1);
|
809
809
|
rb_define_method(cGMP_Q, "swap", r_gmpq_swap, 1);
|
810
|
-
|
810
|
+
|
811
811
|
// Rational Conversions
|
812
812
|
rb_define_method(cGMP_Q, "to_d", r_gmpq_to_d, 0);
|
813
813
|
rb_define_alias(cGMP_Q, "to_f", "to_d");
|
814
814
|
rb_define_method(cGMP_Q, "to_s", r_gmpq_to_s, 0);
|
815
|
-
|
815
|
+
rb_define_alias(cGMP_Q, "inspect", "to_s");
|
816
|
+
|
816
817
|
// Rational Arithmetic
|
817
818
|
rb_define_method(cGMP_Q, "+", r_gmpq_add, 1);
|
818
819
|
rb_define_method(cGMP_Q, "-", r_gmpq_sub, 1);
|
data/ext/gmpz.c
CHANGED
@@ -154,7 +154,7 @@ static VALUE r_gmpz_##fname(VALUE self, VALUE arg) \
|
|
154
154
|
static VALUE r_gmpzsg_##fname(VALUE klass, VALUE arg) \
|
155
155
|
{ \
|
156
156
|
MP_INT *arg_val_z, *res_val; \
|
157
|
-
|
157
|
+
long arg_val_ul; \
|
158
158
|
VALUE res; \
|
159
159
|
\
|
160
160
|
(void)klass; \
|
@@ -165,17 +165,50 @@ static VALUE r_gmpzsg_##fname(VALUE klass, VALUE arg) \
|
|
165
165
|
mpz_get_struct (arg, arg_val_z); \
|
166
166
|
if (!mpz_fits_ulong_p (arg_val_z)) \
|
167
167
|
rb_raise (rb_eRangeError, "argument out of range"); \
|
168
|
-
arg_val_ul =
|
169
|
-
if (arg_val_ul == 0) \
|
170
|
-
rb_raise (rb_eRangeError, "argument out of range"); \
|
168
|
+
arg_val_ul = mpz_get_si (arg_val_z); \
|
171
169
|
} else { \
|
172
170
|
typeerror_as (ZX, "argument"); \
|
173
171
|
} \
|
172
|
+
\
|
173
|
+
if (arg_val_ul < 0) \
|
174
|
+
rb_raise (rb_eRangeError, "argument out of range"); \
|
175
|
+
\
|
174
176
|
mpz_make_struct_init (res, res_val); \
|
175
|
-
mpz_fname (res_val, arg_val_ul);
|
177
|
+
mpz_fname (res_val, (unsigned long)arg_val_ul); \
|
178
|
+
\
|
176
179
|
return res; \
|
177
180
|
}
|
178
181
|
|
182
|
+
#define DEFUN_INT_SINGLETON_ZZ_UI(fname,mpz_fname) \
|
183
|
+
static VALUE r_gmpzsg_##fname(VALUE klass, VALUE arg) \
|
184
|
+
{ \
|
185
|
+
MP_INT *arg_val_z, *res_val_1, *res_val_2; \
|
186
|
+
long arg_val_ul; \
|
187
|
+
VALUE res_1, res_2; \
|
188
|
+
\
|
189
|
+
(void)klass; \
|
190
|
+
\
|
191
|
+
if (FIXNUM_P (arg)) { \
|
192
|
+
arg_val_ul = FIX2NUM (arg); \
|
193
|
+
} else if (GMPZ_P (arg)) { \
|
194
|
+
mpz_get_struct (arg, arg_val_z); \
|
195
|
+
if (!mpz_fits_ulong_p (arg_val_z)) \
|
196
|
+
rb_raise (rb_eRangeError, "argument out of range"); \
|
197
|
+
arg_val_ul = mpz_get_si (arg_val_z); \
|
198
|
+
} else { \
|
199
|
+
typeerror_as (ZX, "argument"); \
|
200
|
+
} \
|
201
|
+
\
|
202
|
+
if (arg_val_ul < 0) \
|
203
|
+
rb_raise (rb_eRangeError, "argument out of range"); \
|
204
|
+
\
|
205
|
+
mpz_make_struct_init (res_1, res_val_1); \
|
206
|
+
mpz_make_struct_init (res_2, res_val_2); \
|
207
|
+
mpz_fname (res_val_1, res_val_2, (unsigned long)arg_val_ul); \
|
208
|
+
\
|
209
|
+
return rb_assoc_new(res_1, res_2); \
|
210
|
+
}
|
211
|
+
|
179
212
|
#define DEFUN_INT_SINGLETON_UIUI(fname,mpz_fname) \
|
180
213
|
static VALUE r_gmpzsg_##fname(VALUE klass, VALUE arg1, VALUE arg2) \
|
181
214
|
{ \
|
@@ -851,51 +884,20 @@ VALUE r_gmpz_to_d(VALUE self)
|
|
851
884
|
* digits and upper-case letters are used; for 37..62, digits, upper-case letters, and
|
852
885
|
* lower-case letters (in that significance order) are used.
|
853
886
|
*/
|
854
|
-
VALUE r_gmpz_to_s(int argc, VALUE *argv, VALUE
|
887
|
+
VALUE r_gmpz_to_s(int argc, VALUE *argv, VALUE self_val)
|
855
888
|
{
|
856
|
-
MP_INT *
|
889
|
+
MP_INT *self;
|
857
890
|
char *str;
|
858
891
|
VALUE res;
|
859
|
-
VALUE
|
860
|
-
int
|
861
|
-
ID base_id;
|
862
|
-
const char * bin_base = "bin"; /* binary */
|
863
|
-
const char * oct_base = "oct"; /* octal */
|
864
|
-
const char * dec_base = "dec"; /* decimal */
|
865
|
-
const char * hex_base = "hex"; /* hexadecimal */
|
866
|
-
ID bin_base_id = rb_intern(bin_base);
|
867
|
-
ID oct_base_id = rb_intern(oct_base);
|
868
|
-
ID dec_base_id = rb_intern(dec_base);
|
869
|
-
ID hex_base_id = rb_intern(hex_base);
|
870
|
-
|
871
|
-
rb_scan_args(argc, argv, "01", &base);
|
872
|
-
if (NIL_P(base)) { base = INT2FIX(10); } /* default value */
|
873
|
-
if (FIXNUM_P(base)) {
|
874
|
-
base_val = FIX2INT(base);
|
875
|
-
if ((base_val >= 2 && base_val <= 62) ||
|
876
|
-
(base_val >= -36 && base_val <= -2)) {
|
877
|
-
/* good base */
|
878
|
-
} else {
|
879
|
-
base_val = 10;
|
880
|
-
rb_raise(rb_eRangeError, "base must be within [2, 62] or [-36, -2].");
|
881
|
-
}
|
882
|
-
} else if (SYMBOL_P(base)) {
|
883
|
-
base_id = rb_to_id(base);
|
884
|
-
if (base_id == bin_base_id) {
|
885
|
-
base_val = 2;
|
886
|
-
} else if (base_id == oct_base_id) {
|
887
|
-
base_val = 8;
|
888
|
-
} else if (base_id == dec_base_id) {
|
889
|
-
base_val = 10;
|
890
|
-
} else if (base_id == hex_base_id) {
|
891
|
-
base_val = 16;
|
892
|
-
} else {
|
893
|
-
base_val = 10; /* should raise an exception here. */
|
894
|
-
}
|
895
|
-
}
|
892
|
+
VALUE base_val;
|
893
|
+
unsigned int base;
|
896
894
|
|
897
|
-
|
898
|
-
|
895
|
+
rb_scan_args(argc, argv, "01", &base_val);
|
896
|
+
if (NIL_P(base_val)) { base = 10; } /* default value */
|
897
|
+
else { base = get_base(base_val); }
|
898
|
+
|
899
|
+
Data_Get_Struct(self_val, MP_INT, self);
|
900
|
+
str = mpz_get_str(NULL, base, self);
|
899
901
|
res = rb_str_new2(str);
|
900
902
|
free (str);
|
901
903
|
|
@@ -1101,6 +1103,7 @@ VALUE r_gmpz_mul(VALUE self, VALUE arg)
|
|
1101
1103
|
mpz_mul(res_val, self_val, arg_val);
|
1102
1104
|
} else if (FIXNUM_P(arg)) {
|
1103
1105
|
mpz_make_struct_init(res, res_val);
|
1106
|
+
/* TODO: use mpz_mul_ui */
|
1104
1107
|
mpz_mul_si(res_val, self_val, FIX2NUM(arg));
|
1105
1108
|
} else if (GMPQ_P(arg)) {
|
1106
1109
|
return r_gmpq_mul(arg, self);
|
@@ -1293,6 +1296,12 @@ DEFUN_INT2INT(abs, mpz_abs)
|
|
1293
1296
|
* * GMP::Q
|
1294
1297
|
* * GMP::F
|
1295
1298
|
* * Bignum
|
1299
|
+
*
|
1300
|
+
* If _b_ is a GMP::Z, Fixnum, GMP::Q, or Bignum, then no division is actually
|
1301
|
+
* performed. Instead, we simply construct a new GMP::Q number, using _a_ and
|
1302
|
+
* _b_ as the numerator and denominator (not exactly true for the GMP::Q case).
|
1303
|
+
*
|
1304
|
+
* If _b_ is a GMP::F, then the result is calculated via `mpf_div`.
|
1296
1305
|
*/
|
1297
1306
|
VALUE r_gmpz_div(VALUE self, VALUE arg)
|
1298
1307
|
{
|
@@ -2344,7 +2353,27 @@ DEFUN_INT_SINGLETON_UI(primorial, mpz_primorial_ui)
|
|
2344
2353
|
* * GMP::Z.fib(6) #=> 8
|
2345
2354
|
* * GMP::Z.fib(7) #=> 13
|
2346
2355
|
*/
|
2347
|
-
DEFUN_INT_SINGLETON_UI(fib,
|
2356
|
+
DEFUN_INT_SINGLETON_UI(fib, mpz_fib_ui)
|
2357
|
+
|
2358
|
+
/*
|
2359
|
+
* Document-method: GMP::Z.fib2
|
2360
|
+
*
|
2361
|
+
* call-seq:
|
2362
|
+
* GMP::Z.fib2(n)
|
2363
|
+
*
|
2364
|
+
* Returns [<i>F[n]</i>, <i>F[n-1]</i>], the <i>n</i>th and <i>n-1</i>th Fibonacci numbers.
|
2365
|
+
*
|
2366
|
+
* Examples:
|
2367
|
+
* * GMP::Z.fib2(1) #=> [ 1, 0]
|
2368
|
+
* * GMP::Z.fib2(2) #=> [ 1, 1]
|
2369
|
+
* * GMP::Z.fib2(3) #=> [ 2, 1]
|
2370
|
+
* * GMP::Z.fib2(4) #=> [ 3, 2]
|
2371
|
+
* * GMP::Z.fib2(5) #=> [ 5, 3]
|
2372
|
+
* * GMP::Z.fib2(6) #=> [ 8, 5]
|
2373
|
+
* * GMP::Z.fib2(7) #=> [13, 8]
|
2374
|
+
*/
|
2375
|
+
DEFUN_INT_SINGLETON_ZZ_UI(fib2, mpz_fib2_ui)
|
2376
|
+
|
2348
2377
|
DEFUN_INT_SINGLETON_UI(lucnum, mpz_lucnum_ui)
|
2349
2378
|
|
2350
2379
|
|
@@ -3034,6 +3063,7 @@ void init_gmpz()
|
|
3034
3063
|
rb_define_method(cGMP_Z, "to_i", r_gmpz_to_i, 0);
|
3035
3064
|
rb_define_method(cGMP_Z, "to_d", r_gmpz_to_d, 0);
|
3036
3065
|
rb_define_method(cGMP_Z, "to_s", r_gmpz_to_s, -1);
|
3066
|
+
rb_define_alias(cGMP_Z, "inspect", "to_s");
|
3037
3067
|
|
3038
3068
|
// Integer Arithmetic
|
3039
3069
|
rb_define_method(cGMP_Z, "+", r_gmpz_add, 1);
|
@@ -3122,6 +3152,7 @@ void init_gmpz()
|
|
3122
3152
|
rb_define_singleton_method(cGMP_Z, "primorial", r_gmpzsg_primorial, 1);
|
3123
3153
|
#endif
|
3124
3154
|
rb_define_singleton_method(cGMP_Z, "fib", r_gmpzsg_fib, 1);
|
3155
|
+
rb_define_singleton_method(cGMP_Z, "fib2", r_gmpzsg_fib2, 1);
|
3125
3156
|
rb_define_singleton_method(cGMP_Z, "lucnum", r_gmpzsg_lucnum, 1);
|
3126
3157
|
// Functional Mappings
|
3127
3158
|
rb_define_singleton_method(cGMP_Z, "lcm", r_gmpzsg_lcm, 3);
|
data/ext/ruby_gmp.h
CHANGED
@@ -154,6 +154,8 @@ extern VALUE mGMP, cGMP_Z, cGMP_Q, cGMP_F, cGMP_RandState;
|
|
154
154
|
extern VALUE cGMP_Rnd;
|
155
155
|
#endif /* MPFR */
|
156
156
|
|
157
|
+
extern int get_base(VALUE base_val);
|
158
|
+
|
157
159
|
extern void r_gmpz_free(void *ptr);
|
158
160
|
extern void r_gmpq_free(void *ptr);
|
159
161
|
extern void r_gmpf_free(void *ptr);
|
data/manual.pdf
CHANGED
Binary file
|
data/manual.tex
CHANGED
@@ -34,8 +34,8 @@
|
|
34
34
|
\huge{gmp} &\\
|
35
35
|
\midrule[3pt]
|
36
36
|
\multicolumn{2}{r}{\large{Ruby bindings to the GMP library}}\\
|
37
|
-
\multicolumn{2}{r}{\large{Edition 0.6.
|
38
|
-
\multicolumn{2}{r}{\large{
|
37
|
+
\multicolumn{2}{r}{\large{Edition 0.6.41}}\\
|
38
|
+
\multicolumn{2}{r}{\large{15 October 2013}}
|
39
39
|
\end{tabular}
|
40
40
|
|
41
41
|
\vfill
|
@@ -45,9 +45,9 @@
|
|
45
45
|
|
46
46
|
\vfill
|
47
47
|
This manual describes how to use the gmp Ruby gem, which provides bindings to
|
48
|
-
the GNU multiple precision arithmetic library, version 4.3.x or 5.
|
48
|
+
the GNU multiple precision arithmetic library, version 4.3.x or 5.x.\\
|
49
49
|
\\
|
50
|
-
Copyright 2009, 2010, 2011, 2012 Sam Rawlins.\\
|
50
|
+
Copyright 2009, 2010, 2011, 2012, 2013 Sam Rawlins.\\
|
51
51
|
No license yet.
|
52
52
|
\newpage
|
53
53
|
|
@@ -143,9 +143,9 @@ OK. First, we've got a few requirements. To install the gmp gem, you need one
|
|
143
143
|
of the following versions of Ruby:
|
144
144
|
\begin{itemize}
|
145
145
|
\item (MRI) Ruby 1.8.6 - tested lightly.
|
146
|
-
\item (MRI) Ruby 1.8.7 - tested
|
147
|
-
\item (MRI) Ruby 1.9.
|
148
|
-
\item (MRI) Ruby
|
146
|
+
\item (MRI) Ruby 1.8.7 - tested lightly.
|
147
|
+
\item (MRI) Ruby 1.9.3 - tested seriously.
|
148
|
+
\item (MRI) Ruby 2.0.0 - tested seriously.
|
149
149
|
\item (REE) Ruby 1.8.7 - tested lightly.
|
150
150
|
\item (RBX) Rubinius 1.1 - tested lightly.
|
151
151
|
\end{itemize}
|
@@ -854,7 +854,17 @@ There is also a convenience method available, \texttt{GMP::Z()}.\\
|
|
854
854
|
\textbf{fib} & & GMP::Z.fib($n$) $\rightarrow$ $integer$ \\
|
855
855
|
\cmidrule(r){2-3}
|
856
856
|
& \multicolumn{2}{p{\defnwidth}}{
|
857
|
-
Returns $F[n]$,
|
857
|
+
Returns $F[n]$, the $n$th Fibonacci number.
|
858
|
+
}
|
859
|
+
\end{tabular}
|
860
|
+
\newline\newline
|
861
|
+
|
862
|
+
\begin{tabular}{p{\methwidth} l r}
|
863
|
+
\toprule
|
864
|
+
\textbf{fib2} & & GMP::Z.fib2($n$) $\rightarrow$ $integer$ \\
|
865
|
+
\cmidrule(r){2-3}
|
866
|
+
& \multicolumn{2}{p{\defnwidth}}{
|
867
|
+
Returns $F[n]$ and $F[n-1]$, the $n$th and $n-1$th Fibonacci numbers.
|
858
868
|
}
|
859
869
|
\end{tabular}
|
860
870
|
|
data/test/tc_division.rb
CHANGED
@@ -15,23 +15,13 @@ class TC_division < Test::Unit::TestCase
|
|
15
15
|
assert_equal(GMP::Q, (@a / 3 ).class, "GMP::Z / Fixnum should be GMP::Q.")
|
16
16
|
assert_equal(GMP::Q, (@a / 2**32).class, "GMP::Z / Bignum should be GMP::Q.")
|
17
17
|
assert_equal(GMP::Q, (@a / @c ).class, "GMP::Z / GMP::Z should be GMP::Q.")
|
18
|
-
|
18
|
+
|
19
19
|
assert_in_delta(0.7142857142, @a / @b, 1e-7, "GMP::Z./ should work.")
|
20
20
|
assert_in_delta(1.4 , @b / @a, 1e-7, "GMP::Z./ should work.")
|
21
21
|
assert_in_delta(1.6666666667, @a / 3, 1e-7, "GMP::Z./ should work.")
|
22
22
|
assert_in_delta(0.6 , 3 / @a, 1e-7, "GMP::Z./ should work.")
|
23
23
|
assert_in_delta(0.2 , @a / @c, 1e-7, "GMP::Z./ should work.")
|
24
24
|
assert_in_delta(5.0 , @c / @a, 1e-7, "GMP::Z./ should work.")
|
25
|
-
rescue TypeError => e
|
26
|
-
if e.message == "GMP::Q can't be coerced into Float"
|
27
|
-
#puts ""
|
28
|
-
print "[Suppressing error that should be fixed with a recent version of Test::Unit installed]"
|
29
|
-
#puts "installed."
|
30
|
-
else
|
31
|
-
puts "Accidentally rescued TypeError with message \"#{e.message}\", raising..."
|
32
|
-
raise e
|
33
|
-
end
|
34
|
-
end
|
35
25
|
end
|
36
26
|
|
37
27
|
def test_z_tdiv
|
data/test/tc_f_to_s.rb
CHANGED
@@ -63,13 +63,16 @@ class TC_F_to_s < Test::Unit::TestCase
|
|
63
63
|
f = GMP::F(0.5)
|
64
64
|
assert_equal("0.50000000000000000e+0", f.to_s)
|
65
65
|
assert_equal("0.10000000000000000000000000000000000000000000000000000e+0", f.to_s(2))
|
66
|
+
assert_equal("0.10000000000000000000000000000000000000000000000000000e+0", f.to_s(:bin))
|
66
67
|
assert_equal("0.11111111111111111111111111111111112e+0", f.to_s(3))
|
67
68
|
assert_equal("0.200000000000000000000000000e+0", f.to_s(4))
|
69
|
+
assert_equal("0.50000000000000000e+0", f.inspect)
|
68
70
|
|
69
71
|
g = GMP::F(0.8)
|
70
72
|
assert_equal("0.80000000000000004e+0", g.to_s)
|
71
73
|
assert_equal("0.21012101210121012101210121012101220e+0", g.to_s(3))
|
72
74
|
assert_equal("0.400000000000000000000003e+0", g.to_s(5))
|
73
75
|
assert_equal("0.k00000000002ge+0", g.to_s(25))
|
76
|
+
assert_equal("0.80000000000000004e+0", g.inspect)
|
74
77
|
end
|
75
78
|
end
|
@@ -2,15 +2,20 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
|
2
2
|
|
3
3
|
class TC_fib_fac_nextprime < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
|
5
|
+
@z0 = GMP::Z.new( 0)
|
6
|
+
@z1 = GMP::Z.new( 1)
|
7
|
+
@z2 = GMP::Z.new( 2)
|
6
8
|
@z7 = GMP::Z.new( 7)
|
7
9
|
@z8 = GMP::Z.new( 8)
|
10
|
+
@z10 = GMP::Z.new(10)
|
8
11
|
@z11 = GMP::Z.new(11)
|
9
12
|
@z13 = GMP::Z.new(13)
|
10
13
|
@z17 = GMP::Z.new(17)
|
11
14
|
@z19 = GMP::Z.new(19)
|
15
|
+
@z34 = GMP::Z.new(34)
|
16
|
+
@z55 = GMP::Z.new(55)
|
12
17
|
end
|
13
|
-
|
18
|
+
|
14
19
|
def test_fib
|
15
20
|
assert_equal( 1, GMP::Z.fib( 1), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
|
16
21
|
assert_equal( 1, GMP::Z.fib( 2), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
|
@@ -19,6 +24,7 @@ class TC_fib_fac_nextprime < Test::Unit::TestCase
|
|
19
24
|
assert_equal( 5, GMP::Z.fib( 5), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
|
20
25
|
assert_equal( 8, GMP::Z.fib( 6), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
|
21
26
|
assert_equal( 13, GMP::Z.fib( 7), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
|
27
|
+
assert_equal( 13, GMP::Z.fib( @z7), "GMP::Z::fib(x : GMP::Z) should be calculated correctly.")
|
22
28
|
assert_equal( 21, GMP::Z.fib( 8), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
|
23
29
|
assert_equal( 34, GMP::Z.fib( 9), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
|
24
30
|
assert_equal( 55, GMP::Z.fib( 10), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
|
@@ -27,8 +33,24 @@ class TC_fib_fac_nextprime < Test::Unit::TestCase
|
|
27
33
|
assert_equal(144, GMP::Z.fib( 12), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
|
28
34
|
assert_equal(233, GMP::Z.fib( 13), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
|
29
35
|
assert_equal(377, GMP::Z.fib( 14), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
|
36
|
+
|
37
|
+
assert_raise(RangeError) { GMP::Z.fib(-1) }
|
38
|
+
assert_raise(RangeError) { GMP::Z.fib(GMP::Z(-1)) }
|
30
39
|
end
|
31
|
-
|
40
|
+
|
41
|
+
def test_fib2
|
42
|
+
assert_equal([ @z1, @z0], GMP::Z.fib2( 1), "GMP::Z::fib2(x : Fixnum) should be calculated correctly.")
|
43
|
+
assert_equal([ @z1, @z1], GMP::Z.fib2( 2), "GMP::Z::fib2(x : Fixnum) should be calculated correctly.")
|
44
|
+
assert_equal([ @z2, @z1], GMP::Z.fib2( 3), "GMP::Z::fib2(x : Fixnum) should be calculated correctly.")
|
45
|
+
assert_equal([@z13, @z8], GMP::Z.fib2( 7), "GMP::Z::fib2(x : Fixnum) should be calculated correctly.")
|
46
|
+
assert_equal([@z13, @z8], GMP::Z.fib2( @z7), "GMP::Z::fib2(x : GMP::Z) should be calculated correctly.")
|
47
|
+
assert_equal([@z55,@z34], GMP::Z.fib2( 10), "GMP::Z::fib2(x : Fixnum) should be calculated correctly.")
|
48
|
+
assert_equal([@z55,@z34], GMP::Z.fib2(@z10), "GMP::Z::fib2(x : GMP::Z) should be calculated correctly.")
|
49
|
+
|
50
|
+
assert_raise(RangeError) { GMP::Z.fib2(-1) }
|
51
|
+
assert_raise(RangeError) { GMP::Z.fib2(GMP::Z(-1)) }
|
52
|
+
end
|
53
|
+
|
32
54
|
def test_fac
|
33
55
|
assert_equal( 1, GMP::Z.fac( 0), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
|
34
56
|
assert_equal( 1, GMP::Z.fac( 1), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
|
@@ -38,6 +60,9 @@ class TC_fib_fac_nextprime < Test::Unit::TestCase
|
|
38
60
|
assert_equal( 120, GMP::Z.fac( 5), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
|
39
61
|
assert_equal( 720, GMP::Z.fac( 6), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
|
40
62
|
assert_equal(5040, GMP::Z.fac( 7), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
|
63
|
+
|
64
|
+
assert_raise(RangeError) { GMP::Z.fac(-1) }
|
65
|
+
assert_raise(RangeError) { GMP::Z.fac(GMP::Z(-1)) }
|
41
66
|
end
|
42
67
|
|
43
68
|
def test_nextprime
|
data/test/tc_q.rb
CHANGED
@@ -115,5 +115,7 @@ class TC_Q < Test::Unit::TestCase
|
|
115
115
|
assert_equal("0", GMP::Q(0,1).to_s, "GMP::Q should to_s properly.")
|
116
116
|
assert_equal("0", GMP::Q(0,2000).to_s, "GMP::Q should to_s properly.")
|
117
117
|
assert_equal("0", GMP::Q(0,-2000).to_s, "GMP::Q should to_s properly.")
|
118
|
+
|
119
|
+
assert_equal("1/2", GMP::Q(1,2).inspect, "GMP::Q should inspect properly.")
|
118
120
|
end
|
119
121
|
end
|
data/test/tc_z_to_dis.rb
CHANGED
@@ -50,7 +50,7 @@ class TC_to_i_to_d < Test::Unit::TestCase
|
|
50
50
|
assert_equal( "-726746425", @d.to_s(:oct), "GMP::Z should to_s correctly.")
|
51
51
|
assert_equal( "-123456789", @d.to_s(:dec), "GMP::Z should to_s correctly.")
|
52
52
|
assert_equal( "-75bcd15", @d.to_s(:hex), "GMP::Z should to_s correctly.")
|
53
|
-
|
53
|
+
|
54
54
|
assert_equal("1", GMP::Z.new(1).to_s, "Z(1).to_s should equal '1'")
|
55
55
|
assert_equal("-1", GMP::Z.new(-1).to_s, "Z(1).to_s should equal '-1'")
|
56
56
|
assert_equal("1234567890", GMP::Z.new(1234567890).to_s, "GMP::Z should to_s correctly.")
|
@@ -65,5 +65,8 @@ class TC_to_i_to_d < Test::Unit::TestCase
|
|
65
65
|
assert_equal("377", GMP::Z.new(255).to_s(:oct), "GMP::Z should to_s(:oct) correctly.")
|
66
66
|
assert_equal("255", GMP::Z.new(255).to_s(:dec), "GMP::Z should to_s(:dec) correctly.")
|
67
67
|
assert_equal("ff", GMP::Z.new(255).to_s(:hex), "GMP::Z should to_s(:hex) correctly.")
|
68
|
+
|
69
|
+
assert_equal("1", GMP::Z.new(1).inspect, "Z(1).inspect should equal '1'")
|
70
|
+
assert_equal("-1", GMP::Z.new(-1).inspect, "Z(1).inspect should equal '-1'")
|
68
71
|
end
|
69
72
|
end
|
data/test/unit_tests.rb
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
DIR = File.expand_path(File.dirname(__FILE__))
|
4
4
|
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
require '
|
8
|
-
require '
|
9
|
-
require '
|
10
|
-
require '
|
11
|
-
require '
|
12
|
-
require '
|
13
|
-
require '
|
14
|
-
require '
|
15
|
-
require '
|
16
|
-
require '
|
17
|
-
require '
|
18
|
-
require '
|
19
|
-
require '
|
20
|
-
require '
|
21
|
-
require '
|
22
|
-
require '
|
23
|
-
require '
|
24
|
-
require '
|
25
|
-
require '
|
26
|
-
require '
|
27
|
-
require '
|
28
|
-
require '
|
29
|
-
require '
|
30
|
-
require '
|
31
|
-
require '
|
32
|
-
require '
|
33
|
-
require '
|
34
|
-
require '
|
5
|
+
require File.join(DIR, 'tc_constants')
|
6
|
+
require File.join(DIR, 'tc_division')
|
7
|
+
require File.join(DIR, 'tc_f_precision')
|
8
|
+
require File.join(DIR, 'tc_f_arithmetics_coersion')
|
9
|
+
require File.join(DIR, 'tc_f_to_s')
|
10
|
+
require File.join(DIR, 'tc_z')
|
11
|
+
require File.join(DIR, 'tc_z_basic')
|
12
|
+
require File.join(DIR, 'tc_z_addmul')
|
13
|
+
require File.join(DIR, 'tc_z_submul')
|
14
|
+
require File.join(DIR, 'tc_z_logic')
|
15
|
+
require File.join(DIR, 'tc_z_exponentiation')
|
16
|
+
require File.join(DIR, 'tc_z_export_import')
|
17
|
+
require File.join(DIR, 'tc_z_hamdist')
|
18
|
+
require File.join(DIR, 'tc_z_io')
|
19
|
+
require File.join(DIR, 'tc_z_to_dis')
|
20
|
+
require File.join(DIR, 'tc_z_shifts_last_bits')
|
21
|
+
require File.join(DIR, 'tc_z_jac_leg_rem')
|
22
|
+
require File.join(DIR, 'tc_z_gcd_lcm_invert')
|
23
|
+
require File.join(DIR, 'tc_q')
|
24
|
+
require File.join(DIR, 'tc_q_basic')
|
25
|
+
require File.join(DIR, 'tc_cmp')
|
26
|
+
require File.join(DIR, 'tc_zerodivisionexceptions')
|
27
|
+
require File.join(DIR, 'tc_sgn_neg_abs')
|
28
|
+
require File.join(DIR, 'tc_fib_fac_nextprime')
|
29
|
+
require File.join(DIR, 'tc_swap')
|
30
|
+
require File.join(DIR, 'tc_floor_ceil_truncate')
|
31
|
+
require File.join(DIR, 'tc_logical_roots')
|
32
|
+
require File.join(DIR, 'tc_random')
|
33
|
+
require File.join(DIR, 'tc_hashes')
|
34
|
+
require File.join(DIR, 'tc_z_functional_mappings')
|
35
35
|
|
36
|
-
require '
|
37
|
-
require '
|
38
|
-
require '
|
39
|
-
require '
|
40
|
-
require '
|
36
|
+
require File.join(DIR, 'gmp_tcong')
|
37
|
+
require File.join(DIR, 'gmp_tgcd')
|
38
|
+
require File.join(DIR, 'gmp_tlcm')
|
39
|
+
require File.join(DIR, 'gmp_tprintf')
|
40
|
+
require File.join(DIR, 'gmp_troot')
|
41
41
|
|
42
42
|
begin
|
43
43
|
GMP::MPFR_VERSION
|
44
|
-
require '
|
45
|
-
require '
|
46
|
-
require '
|
47
|
-
require '
|
48
|
-
require '
|
49
|
-
require '
|
50
|
-
require '
|
51
|
-
require '
|
52
|
-
require '
|
44
|
+
require File.join(DIR, 'tc_mpfr_constants')
|
45
|
+
require File.join(DIR, 'tc_mpfr_integer')
|
46
|
+
require File.join(DIR, 'tc_mpfr_random')
|
47
|
+
require File.join(DIR, 'tc_mpfr_functions')
|
48
|
+
require File.join(DIR, 'tc_mpfr_rounding')
|
49
|
+
require File.join(DIR, 'mpfr_tcbrt')
|
50
|
+
require File.join(DIR, 'mpfr_tisnan')
|
51
|
+
require File.join(DIR, 'mpfr_trec_sqrt')
|
52
|
+
require File.join(DIR, 'mpfr_tsqrt')
|
53
53
|
rescue
|
54
54
|
|
55
55
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
5
|
-
prerelease:
|
4
|
+
version: 0.6.41
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Tomasz Wegrzanowski
|
@@ -10,7 +9,7 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2013-
|
12
|
+
date: 2013-10-15 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
14
|
description: gmp - providing Ruby bindings to the GMP library.
|
16
15
|
email:
|
@@ -89,8 +88,11 @@ files:
|
|
89
88
|
- test/unit_tests.rb
|
90
89
|
- test/README
|
91
90
|
- test/test_unit/assertions.rb
|
92
|
-
- benchmark/
|
93
|
-
- benchmark/
|
91
|
+
- benchmark/bench.sh
|
92
|
+
- benchmark/csv.sh
|
93
|
+
- benchmark/results-5.0.5_1.9.3_0.6.7.ods
|
94
|
+
- benchmark/results-5.1.0_0.6.19.ods
|
95
|
+
- benchmark/results-5.1.3_0.6.31.ods
|
94
96
|
- CHANGELOG
|
95
97
|
- INSTALL
|
96
98
|
- README.html
|
@@ -103,28 +105,26 @@ files:
|
|
103
105
|
- performance.2012.pdf
|
104
106
|
homepage: http://github.com/srawlins/gmp
|
105
107
|
licenses: []
|
108
|
+
metadata: {}
|
106
109
|
post_install_message:
|
107
110
|
rdoc_options: []
|
108
111
|
require_paths:
|
109
112
|
- lib
|
110
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
114
|
requirements:
|
113
|
-
- -
|
115
|
+
- - ">="
|
114
116
|
- !ruby/object:Gem::Version
|
115
117
|
version: 1.8.6
|
116
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
-
none: false
|
118
119
|
requirements:
|
119
|
-
- -
|
120
|
+
- - ">="
|
120
121
|
- !ruby/object:Gem::Version
|
121
122
|
version: '0'
|
122
123
|
requirements:
|
123
124
|
- GMP compiled and working properly.
|
124
125
|
rubyforge_project:
|
125
|
-
rubygems_version: 1.8
|
126
|
+
rubygems_version: 2.1.8
|
126
127
|
signing_key:
|
127
|
-
specification_version:
|
128
|
+
specification_version: 4
|
128
129
|
summary: Provides Ruby bindings to the GMP library.
|
129
130
|
test_files: []
|
130
|
-
has_rdoc: yard
|
Binary file
|