gmp 0.6.13 → 0.6.17
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -1
- data/ext/gmpz.c +61 -0
- data/test/tc_z_io.rb +50 -0
- data/test/unit_tests.rb +1 -0
- metadata +3 -2
data/README.markdown
CHANGED
@@ -97,7 +97,7 @@ by me: gmp gem 0.5.47 on:
|
|
97
97
|
GMP 5.0.1 (3.0.0)</td>
|
98
98
|
</tr>
|
99
99
|
<tr>
|
100
|
-
<td rowspan="
|
100
|
+
<td rowspan="3">Mac OS X 10.6.8 on x86_64 (64-bit)</td>
|
101
101
|
<td>(MRI) Ruby 1.8.7</td>
|
102
102
|
<td>GMP 4.3.2 (2.4.2)<br />
|
103
103
|
GMP 5.0.5 (3.1.1)</td>
|
@@ -284,6 +284,8 @@ Methods
|
|
284
284
|
remove(n) remove all occurences of factor n
|
285
285
|
popcount the number of bits equal to 1
|
286
286
|
hamdist the hamming distance between two integers
|
287
|
+
out_raw output to IO object
|
288
|
+
inp_raw input from IO object
|
287
289
|
sizeinbase(b) digits in base b
|
288
290
|
size_in_bin digits in binary
|
289
291
|
size number of limbs
|
data/ext/gmpz.c
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#include <gmpz.h>
|
2
2
|
#include <gmpq.h>
|
3
3
|
#include <gmpf.h>
|
4
|
+
#include <ruby/io.h>
|
4
5
|
|
5
6
|
/*
|
6
7
|
* Document-class: GMP::Z
|
@@ -2675,6 +2676,61 @@ VALUE r_gmpz_getbit(VALUE self, VALUE bitnr)
|
|
2675
2676
|
}
|
2676
2677
|
|
2677
2678
|
|
2679
|
+
/**********************************************************************
|
2680
|
+
* I/O of Integers *
|
2681
|
+
**********************************************************************/
|
2682
|
+
|
2683
|
+
/*
|
2684
|
+
* call-seq:
|
2685
|
+
* a.out_raw(stream) #=> Fixnum
|
2686
|
+
*
|
2687
|
+
* Output _a_ on IO object _stream_, in raw binary format. The integer is
|
2688
|
+
* written in a portable format, with 4 bytes of size information, and that
|
2689
|
+
* many bytes of limbs. Both the size and the limbs are written in decreasing
|
2690
|
+
* significance order (i.e., in big-endian).
|
2691
|
+
*
|
2692
|
+
* The output can be read with `GMP::Z.inp_raw`.
|
2693
|
+
*
|
2694
|
+
* Return the number of bytes written, or if an error occurred, return 0.
|
2695
|
+
*/
|
2696
|
+
VALUE r_gmpz_out_raw(VALUE self, VALUE stream)
|
2697
|
+
{
|
2698
|
+
MP_INT *self_val;
|
2699
|
+
FILE *fd;
|
2700
|
+
mpz_get_struct(self, self_val);
|
2701
|
+
if (TYPE (stream) != T_FILE) {
|
2702
|
+
rb_raise (rb_eTypeError, "stream must be an IO.");
|
2703
|
+
}
|
2704
|
+
fd = rb_io_stdio_file (RFILE (stream)->fptr);
|
2705
|
+
return INT2FIX (mpz_out_raw (fd, self_val));
|
2706
|
+
}
|
2707
|
+
|
2708
|
+
/*
|
2709
|
+
* call-seq:
|
2710
|
+
* GMP::Z.inp_raw(a, stream) #=> Fixnum
|
2711
|
+
*
|
2712
|
+
* Input from IO object _stream_ in the format written by `GMP::Z#out_raw`, and
|
2713
|
+
* put the result in _a_. Return the number of bytes read, or if an error
|
2714
|
+
* occurred, return 0.
|
2715
|
+
*/
|
2716
|
+
VALUE r_gmpzsg_inp_raw(VALUE klass, VALUE a_val, VALUE stream_val)
|
2717
|
+
{
|
2718
|
+
MP_INT *a;
|
2719
|
+
FILE *stream;
|
2720
|
+
(void)klass;
|
2721
|
+
|
2722
|
+
if (! GMPZ_P(a_val))
|
2723
|
+
typeerror_as(Z, "a");
|
2724
|
+
|
2725
|
+
if (TYPE (stream_val) != T_FILE)
|
2726
|
+
rb_raise (rb_eTypeError, "stream must be an IO.");
|
2727
|
+
|
2728
|
+
mpz_get_struct(a_val, a);
|
2729
|
+
stream = rb_io_stdio_file (RFILE (stream_val)->fptr);
|
2730
|
+
return INT2FIX (mpz_inp_raw (a, stream));
|
2731
|
+
}
|
2732
|
+
|
2733
|
+
|
2678
2734
|
/**********************************************************************
|
2679
2735
|
* Miscellaneous Integer Functions *
|
2680
2736
|
**********************************************************************/
|
@@ -2903,6 +2959,11 @@ void init_gmpz()
|
|
2903
2959
|
// Functional Mappings
|
2904
2960
|
rb_define_singleton_method(cGMP_Z, "com", r_gmpzsg_com, 2);
|
2905
2961
|
|
2962
|
+
// I/O of Integers
|
2963
|
+
rb_define_method(cGMP_Z, "out_raw", r_gmpz_out_raw, 1);
|
2964
|
+
// Functional Mapping
|
2965
|
+
rb_define_singleton_method(cGMP_Z, "inp_raw", r_gmpzsg_inp_raw, 2);
|
2966
|
+
|
2906
2967
|
// Miscellaneous Integer Functions
|
2907
2968
|
rb_define_method(cGMP_Z, "even?", r_gmpz_is_even, 0);
|
2908
2969
|
rb_define_method(cGMP_Z, "odd?", r_gmpz_is_odd, 0);
|
data/test/tc_z_io.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class TC_Z_IO < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@two_pow_100 = GMP::Z.pow(GMP::Z(2), 100)
|
7
|
+
@three_pow_100 = GMP::Z.pow(GMP::Z(3), 100)
|
8
|
+
@rs = GMP::RandState.new
|
9
|
+
@rs.seed(13579)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_io_raw_with_two_pow_100
|
13
|
+
handle = File.new('test_io_raw', 'w')
|
14
|
+
@two_pow_100.out_raw(handle)
|
15
|
+
handle.close
|
16
|
+
|
17
|
+
handle = File.open('test_io_raw')
|
18
|
+
result = GMP::Z()
|
19
|
+
GMP::Z.inp_raw(result, handle)
|
20
|
+
FileUtils.rm('test_io_raw')
|
21
|
+
assert_equal(@two_pow_100, result, "GMP::Z should out_raw and inp_raw correctly")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_io_raw_with_three_pow_100
|
25
|
+
handle = File.new('test_io_raw', 'w')
|
26
|
+
@three_pow_100.out_raw(handle)
|
27
|
+
handle.close
|
28
|
+
|
29
|
+
handle = File.open('test_io_raw')
|
30
|
+
result = GMP::Z()
|
31
|
+
GMP::Z.inp_raw(result, handle)
|
32
|
+
FileUtils.rm('test_io_raw')
|
33
|
+
assert_equal(@three_pow_100, result, "GMP::Z should out_raw and inp_raw correctly")
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_io_raw_randoms
|
37
|
+
100.times do |i|
|
38
|
+
handle = File.new('test_io_raw', 'w')
|
39
|
+
z = @rs.urandomb(1024)
|
40
|
+
z.out_raw(handle)
|
41
|
+
handle.close
|
42
|
+
|
43
|
+
handle = File.open('test_io_raw')
|
44
|
+
result = GMP::Z()
|
45
|
+
GMP::Z.inp_raw(result, handle)
|
46
|
+
assert_equal(z, result, "GMP::Z should out_raw and inp_raw correctly")
|
47
|
+
end
|
48
|
+
FileUtils.rm('test_io_raw')
|
49
|
+
end
|
50
|
+
end
|
data/test/unit_tests.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.17
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-12-
|
13
|
+
date: 2012-12-13 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: gmp - providing Ruby bindings to the GMP library.
|
16
16
|
email:
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- test/tc_z_functional_mappings.rb
|
72
72
|
- test/tc_z_gcd_lcm_invert.rb
|
73
73
|
- test/tc_z_hamdist.rb
|
74
|
+
- test/tc_z_io.rb
|
74
75
|
- test/tc_z_jac_leg_rem.rb
|
75
76
|
- test/tc_z_logic.rb
|
76
77
|
- test/tc_z_shifts_last_bits.rb
|