gmp 0.4.0-x86-mingw32 → 0.4.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 0.4.1:
2
+ * Fixed some gem dates
3
+ * Added urandomm(), documentation, and tests.
4
+
1
5
  0.4.0:
2
6
  * Support for Windows introduced. gmp-x86-mswin32 gem should be used.
3
7
  * All tests should pass under Windows.
Binary file
@@ -0,0 +1,165 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ # Copyright 2003 Free Software Foundation, Inc.
4
+
5
+ # This file is part of the GNU GMPbench.
6
+
7
+ # This program is free software; you can redistribute it and/or modify it under
8
+ # the terms of the GNU General Public License as published by the Free Software
9
+ # Foundation; either version 2 of the License, or (at your option) any later
10
+ # version.
11
+
12
+ # This program is distributed in the hope that it will be useful, but WITHOUT
13
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15
+ # details.
16
+
17
+ # You should have received a copy of the GNU General Public License along with
18
+ # this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19
+ # Place - Suite 330, Boston, MA 02111-1307, USA.
20
+
21
+ class String
22
+ def bs
23
+ gsub("/", "\\")
24
+ end
25
+
26
+ def sh_interpolate
27
+ gsub(/\$([A-Z]+)/) { |s| ENV[$1] }
28
+ end
29
+ end
30
+
31
+ puts "***** GMPbench version 0.2 *****"
32
+
33
+ no_compile = false
34
+ default = false
35
+ gnu_bin = "/cygwin/bin/"
36
+ gnu_bin = "/Ruby19/devkit/msys/1.0.11/bin/"
37
+
38
+ while ARGV[0] =~ /^-/
39
+ case ARGV[0]
40
+ when "-g" then gnu_bin = ARGV[1]; ARGV.shift; ARGV.shift
41
+ when "-n" then no_compile = true; ARGV.shift
42
+ else ARGV.shift
43
+ end
44
+ end
45
+
46
+ if RUBY_VERSION =~ /mingw/ and !( ENV["PATH"] =~ /;\.$|^\.;|;\.;/ )
47
+ ENV["PATH"] += ";."
48
+ end
49
+
50
+ if no_compile
51
+ puts "Suppressing compilation"
52
+ else
53
+ unless ENV["CFLAGS"]
54
+ ENV["CFLAGS"] = "-O3 -fomit-frame-pointer"
55
+ puts "Using default CFLAGS = \"$CFLAGS\"".sh_interpolate
56
+ default = true
57
+ else
58
+ puts "Using CFLAGS = \"$CFLAGS\" from your environment".sh_interpolate
59
+ end
60
+ unless ENV["CC"]
61
+ ENV["CC"] = "gcc"
62
+ puts "Using default CC = \"$CC\"".sh_interpolate
63
+ default = true
64
+ else
65
+ puts "Using CC = \"$CC\" from your environment".sh_interpolate
66
+ end
67
+ unless ENV["LIBS"]
68
+ ENV["LIBS"] = "-static -lgmp"
69
+ puts "Using default LIBS = \"$LIBS\"".sh_interpolate
70
+ default = true
71
+ else
72
+ puts "Using LIBS = \"$LIBS\" from your environment".sh_interpolate
73
+ end
74
+
75
+ puts "Using compilation command: $CC $CFLAGS foo.c -o foo $LIBS".sh_interpolate
76
+ if default
77
+ puts "You may want to override CC, CFLAGS, and LIBS"
78
+ end
79
+
80
+ `#{"$CC $CFLAGS gmpver.c $LIBS".sh_interpolate}`
81
+ puts "Using `./a.out`"
82
+
83
+ puts "Compiling benchmarks"
84
+ `#{"$CC $CFLAGS gcd.c -o gcd $LIBS".sh_interpolate}`
85
+ `#{"$CC $CFLAGS gcdext.c -o gcdext $LIBS".sh_interpolate}`
86
+ `#{"$CC $CFLAGS multiply.c -o multiply $LIBS".sh_interpolate}`
87
+ `#{"$CC $CFLAGS divide.c -o divide $LIBS".sh_interpolate}`
88
+ `#{"$CC $CFLAGS rsa.c -o rsa $LIBS".sh_interpolate}`
89
+ `#{"$CC $CFLAGS pi.c -o pi $LIBS -lm".sh_interpolate}`
90
+ end
91
+
92
+ multiply_args = "128 512 8192 131072 2097152 128,128 512,512 8192,8192 " +
93
+ "131072,131072 2097152,2097152 15000,10000 20000,10000 " +
94
+ "30000,10000 16777216,512 16777216,262144"
95
+ multiply_weight = 1
96
+
97
+ divide_args = "8192,32 8192,64 8192,128 8192,4096 131072,65536 " +
98
+ "8388608,4194304 8192,8064 16777216,262144"
99
+ divide_weight = 1
100
+
101
+ gcd_args = "128,128 512,512 8192,8192 131072,131072 1048576,1048576"
102
+ gcd_weight = 0.5
103
+
104
+ gcdext_args = "128,128 512,512 8192,8192 131072,131072 1048576,1048576"
105
+ gcdext_weight = 0.5
106
+
107
+ rsa_args = "512 1024 2048"
108
+ rsa_weight = 1
109
+
110
+ pi_args = "10000 100000 1000000"
111
+ pi_weight = 1
112
+
113
+ #base_tests = "multiply divide gcd gcdext"
114
+ base_tests = "multiply divide gcd"
115
+ #app_tests = "rsa pi"
116
+ app_tests = "rsa"
117
+
118
+ tests = "base app"
119
+
120
+ puts "Running benchmarks (propagated score accuracy exceeds printed intermediates)"
121
+
122
+ acc2 = 1
123
+ n2 = 0
124
+ tests.split(" ").each do |cat|
125
+ puts " Category #{cat}"
126
+ tests = eval "#{cat}_tests"
127
+
128
+ acc1 = 1
129
+ n1 = 0
130
+ tests.split(" ").each do |t|
131
+ weight = eval "#{t}_weight"
132
+ puts " Program #{t} (weight=#{weight})"
133
+ args = eval "#{t}_args"
134
+
135
+ acc = 1
136
+ n = 0
137
+ args.split(" ").each do |a|
138
+ ta = `echo #{a} | #{gnu_bin}sed 's;,; ;g'`.chomp
139
+ printf ' %-48s', "GMPbench.#{cat}.#{t}(#{a})"
140
+ `ruby #{t} #{ta} > "RES-#{t}-#{a}"`
141
+ sed_cmd = "#{gnu_bin}sed 's;^RESULT: \\([0-9.]*\\).*$;\\1;'"
142
+ res_cmd = "#{gnu_bin}grep \"^RESULT\" RES-#{t}-#{a} | #{sed_cmd}"
143
+ res = `#{res_cmd}`
144
+ printf "%12s\n", `gexpr -prec 4 "#{res}"`.chomp
145
+ acc = `gexpr -prec 10 "#{acc} * #{res}"`
146
+ n = `gexpr #{n}+1`
147
+ end
148
+
149
+ out = `gexpr -prec 10 "#{acc}^(1/#{n})"`
150
+ printf " %-40s%12s\n", "GMPbench.#{cat}.#{t}", `gexpr -prec 5 "#{out}"`
151
+ acc1 = `gexpr -prec 10 "#{acc1} * #{out}^#{weight}"`
152
+ n1 = `gexpr #{n1}+#{weight}`
153
+ end
154
+
155
+ out = `gexpr -prec 10 "#{acc1}^(1/#{n1})"`
156
+ printf " %-32s%12s\n", "GMPbench.#{cat}", `gexpr -prec 5 "#{out}"`
157
+ acc2 = `gexpr -prec 10 "#{acc2} * #{out}"`
158
+ n2 = `gexpr #{n2}+1`
159
+ end
160
+
161
+
162
+ out = `gexpr "#{acc2}^(1/#{n2})"`
163
+ puts "GMPbench: #{out}"
164
+
165
+ exit 0
@@ -90,7 +90,7 @@ VALUE r_gmprandstatesg_new(int argc, VALUE *argv, VALUE klass)
90
90
  rb_raise(rb_eArgError, "size must be within [0..128]");
91
91
  int rv = gmp_randinit_lc_2exp_size(rs_val, size_val);
92
92
  if (rv == 0)
93
- rb_raise(rb_eArgError, "could not gmp_randinit_lc_2exp_size with %d", size_val);
93
+ rb_raise(rb_eArgError, "could not gmp_randinit_lc_2exp_size with %lu", size_val);
94
94
  }
95
95
 
96
96
  if (free_a_val) { mpz_temp_free(a_val); }
@@ -193,7 +193,7 @@ VALUE r_gmprandstate_urandomb(VALUE self, VALUE arg)
193
193
 
194
194
  mprandstate_get_struct(self,self_val);
195
195
 
196
- if (FIXNUM_P(arg)) {
196
+ if (FIXNUM_P(arg)) {
197
197
  mpz_make_struct_init(res, res_val);
198
198
  mpz_urandomb(res_val, self_val, FIX2INT(arg));
199
199
  } else {
@@ -203,6 +203,43 @@ VALUE r_gmprandstate_urandomb(VALUE self, VALUE arg)
203
203
  return res;
204
204
  }
205
205
 
206
+ /*
207
+ * call-seq:
208
+ * rand_state.urandomm(fixnum)
209
+ *
210
+ * From the GMP Manual:
211
+ *
212
+ * Generate a uniformly distributed random integer in the range 0 to
213
+ * fixnum-1, inclusive.
214
+ */
215
+ VALUE r_gmprandstate_urandomm(VALUE self, VALUE arg)
216
+ {
217
+ MP_RANDSTATE *self_val;
218
+ MP_INT *res_val, *arg_val;
219
+ int free_arg_val = 0;
220
+ VALUE res;
221
+
222
+ mprandstate_get_struct(self,self_val);
223
+
224
+ if (GMPZ_P(arg)) {
225
+ mpz_get_struct(arg, arg_val);
226
+ } else if (FIXNUM_P(arg)) {
227
+ mpz_temp_alloc(arg_val);
228
+ mpz_init_set_ui(arg_val, FIX2INT(arg));
229
+ free_arg_val = 1;
230
+ } else if (BIGNUM_P(arg)) {
231
+ mpz_temp_from_bignum(arg_val, arg);
232
+ free_arg_val = 1;
233
+ } else {
234
+ typeerror_as(ZXB, "arg");
235
+ }
236
+
237
+ mpz_make_struct_init(res, res_val);
238
+ mpz_urandomm(res_val, self_val, arg_val);
239
+ if (free_arg_val) { mpz_temp_free(arg_val); }
240
+
241
+ return res;
242
+ }
206
243
 
207
244
  void init_gmprandstate()
208
245
  {
@@ -220,5 +257,5 @@ void init_gmprandstate()
220
257
 
221
258
  // Integer Random Numbers
222
259
  rb_define_method(cGMP_RandState, "urandomb", r_gmprandstate_urandomb, 1);
223
-
260
+ rb_define_method(cGMP_RandState, "urandomm", r_gmprandstate_urandomm, 1);
224
261
  }
@@ -224,6 +224,7 @@ extern VALUE r_gmprandstate_seed(VALUE self, VALUE arg);
224
224
 
225
225
  // Integer Random Numbers
226
226
  extern VALUE r_gmprandstate_urandomb(VALUE self, VALUE arg);
227
+ extern VALUE r_gmprandstate_urandomm(VALUE self, VALUE arg);
227
228
 
228
229
 
229
230
  /* from gmpbench_timing.c */
data/manual.tex CHANGED
@@ -28,8 +28,8 @@
28
28
  \huge{gmp} &\\
29
29
  \midrule[3pt]
30
30
  \multicolumn{2}{r}{\large{Ruby bindings to the GMP library}}\\
31
- \multicolumn{2}{r}{\large{Edition 0.4.0}}\\
32
- \multicolumn{2}{r}{\large{26 February 2010}}
31
+ \multicolumn{2}{r}{\large{Edition 0.4.1}}\\
32
+ \multicolumn{2}{r}{\large{1 March 2010}}
33
33
  \end{tabular}
34
34
 
35
35
  \vfill
@@ -22,6 +22,25 @@ class TC_Random < Test::Unit::TestCase
22
22
  end
23
23
  end
24
24
 
25
+ def test_urandomm
26
+ @a = GMP::RandState.new
27
+ @a.seed(8675309)
28
+ g1 = [21, 849, 6428, 7329, 288845, 7712337, 9, 613, 5710, 3880, 246305, 9623186,
29
+ 22, 47, 5055, 5189, 32571, 2585012, 19, 415, 4940, 3658, 248890, 2180120]
30
+ n1 = [32, 1024, 6563, 11213, 362880, 9699690]
31
+ g1.size.times do |i|
32
+ assert_equal(g1[i], @a.urandomm(n1[i%6]), "GMP::RandState should urandomm predictably.")
33
+ end
34
+
35
+ @b = GMP::RandState.new
36
+ @b.seed(67898771)
37
+ g2 = [ 1, 2, 3, 182, 393, 1232, 238, 10168, 10671, 28310,
38
+ 72259, 70015, 27964, 363191, 371324, 66644, 188620, 1241121, 263944, 1357676]
39
+ g2.size.times do |i|
40
+ assert_equal(g2[i], @b.urandomm(GMP::Z(i**5+5)), "GMP::RandState should urandomb predictably.")
41
+ end
42
+ end
43
+
25
44
  def test_reseed
26
45
  @c = GMP::RandState.new
27
46
  @c.seed(1000)
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.4.0
4
+ version: 0.4.1
5
5
  platform: x86-mingw32
6
6
  authors:
7
7
  - Tomasz Wegrzanowski
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-03 00:00:00 -07:00
13
+ date: 2010-03-01 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -71,12 +71,13 @@ files:
71
71
  - benchmark/COPYING
72
72
  - benchmark/divide
73
73
  - benchmark/gcd
74
- - benchmark/gexpr
75
74
  - benchmark/gexpr.c
75
+ - benchmark/gexpr.exe
76
76
  - benchmark/multiply
77
77
  - benchmark/README
78
78
  - benchmark/rsa
79
79
  - benchmark/runbench
80
+ - benchmark/runbench.rb
80
81
  - benchmark/version
81
82
  - CHANGELOG
82
83
  - INSTALL
Binary file