gmp 0.4.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +109 -0
- data/INSTALL +4 -0
- data/README.rdoc +357 -0
- data/benchmark/COPYING +674 -0
- data/benchmark/README +75 -0
- data/benchmark/divide +34 -0
- data/benchmark/gcd +38 -0
- data/benchmark/gexpr +0 -0
- data/benchmark/gexpr.c +359 -0
- data/benchmark/multiply +44 -0
- data/benchmark/rsa +93 -0
- data/benchmark/runbench +147 -0
- data/benchmark/version +1 -0
- data/ext/extconf.rb +30 -0
- data/ext/gmp.c +197 -0
- data/ext/gmpbench_timing.c +80 -0
- data/ext/gmpf.c +595 -0
- data/ext/gmpf.h +144 -0
- data/ext/gmpq.c +780 -0
- data/ext/gmpq.h +12 -0
- data/ext/gmprandstate.c +224 -0
- data/ext/gmpz.c +1968 -0
- data/ext/gmpz.h +20 -0
- data/ext/libgmp-10.dll +0 -0
- data/ext/ruby_gmp.h +243 -0
- data/ext/takeover.h +36 -0
- data/manual.pdf +0 -0
- data/manual.tex +804 -0
- data/test/README +34 -0
- data/test/tc_cmp.rb +74 -0
- data/test/tc_division.rb +109 -0
- data/test/tc_f_arithmetics_coersion.rb +71 -0
- data/test/tc_f_precision.rb +48 -0
- data/test/tc_fib_fac_nextprime.rb +51 -0
- data/test/tc_floor_ceil_truncate.rb +21 -0
- data/test/tc_logical_roots.rb +48 -0
- data/test/tc_q.rb +27 -0
- data/test/tc_q_basic.rb +41 -0
- data/test/tc_random.rb +54 -0
- data/test/tc_sgn_neg_abs.rb +47 -0
- data/test/tc_swap.rb +19 -0
- data/test/tc_z.rb +71 -0
- data/test/tc_z_basic.rb +35 -0
- data/test/tc_z_exponentiation.rb +22 -0
- data/test/tc_z_gcd_lcm_invert.rb +57 -0
- data/test/tc_z_jac_leg_rem.rb +73 -0
- data/test/tc_z_logic.rb +54 -0
- data/test/tc_z_shifts_last_bits.rb +22 -0
- data/test/tc_z_to_d_to_i.rb +24 -0
- data/test/tc_zerodivisionexceptions.rb +17 -0
- data/test/test-12.rb +14 -0
- data/test/test-19.rb +13 -0
- data/test/test-20.rb +29 -0
- data/test/test-21.rb +37 -0
- data/test/test-22.rb +12 -0
- data/test/test-23.rb +11 -0
- data/test/test_helper.rb +8 -0
- data/test/unit_tests.rb +39 -0
- metadata +115 -0
data/benchmark/multiply
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require '../ext/gmp'
|
4
|
+
|
5
|
+
multiplicands = ARGV
|
6
|
+
random_state = GMP::RandState.new
|
7
|
+
|
8
|
+
if multiplicands.size > 1
|
9
|
+
m, n = multiplicands[0].to_i, multiplicands[1].to_i
|
10
|
+
x = random_state.urandomb(m)
|
11
|
+
y = random_state.urandomb(n)
|
12
|
+
else
|
13
|
+
m = multiplicands[0].to_i
|
14
|
+
x = random_state.urandomb(m)
|
15
|
+
y = x
|
16
|
+
end
|
17
|
+
|
18
|
+
t = GMP::time { z = x * y }
|
19
|
+
iterations = (1 + (1e4 / t)).to_i
|
20
|
+
|
21
|
+
if multiplicands.size > 1
|
22
|
+
print "Multiplying %i-bit number with %i-bit number %i times..." % [m, n, iterations]
|
23
|
+
else
|
24
|
+
print "Squaring a %i-bit number %i times..." % [m, iterations]
|
25
|
+
end
|
26
|
+
STDOUT.flush
|
27
|
+
|
28
|
+
t0 = GMP::cputime
|
29
|
+
iterations.times do
|
30
|
+
z = x * y
|
31
|
+
end
|
32
|
+
ti = GMP::cputime - t0
|
33
|
+
|
34
|
+
puts "done!"
|
35
|
+
ops_per_sec = 1000.0 * iterations / ti
|
36
|
+
f = 100.0
|
37
|
+
decimals = 0
|
38
|
+
while true
|
39
|
+
decimals += 1
|
40
|
+
break if ops_per_sec > f
|
41
|
+
f = f * 0.1
|
42
|
+
end
|
43
|
+
|
44
|
+
puts "RESULT: %#{decimals}f operations per second\n" % ops_per_sec
|
data/benchmark/rsa
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require '../ext/gmp'
|
4
|
+
|
5
|
+
RSA_EXP = 0x10001
|
6
|
+
|
7
|
+
def rsa_sign(msg, p, q, pq, p_i_q, dp, dq)
|
8
|
+
pr = msg.powmod(dp, p)
|
9
|
+
qr = msg.powmod(dq, q)
|
10
|
+
|
11
|
+
qr_m_pr = qr - pr
|
12
|
+
|
13
|
+
t = qr_m_pr * p_i_q
|
14
|
+
o = t % q
|
15
|
+
|
16
|
+
t = o * p
|
17
|
+
smsg = pr + t
|
18
|
+
smsg % pq
|
19
|
+
end
|
20
|
+
|
21
|
+
n = ARGV[0].to_i
|
22
|
+
random_state = GMP::RandState.new
|
23
|
+
|
24
|
+
print "Generating p, q, d..."
|
25
|
+
STDOUT.flush
|
26
|
+
|
27
|
+
pq = GMP::Z()
|
28
|
+
while pq != 1
|
29
|
+
p = random_state.urandomb(n/2)
|
30
|
+
p[n/2 - 1] = true
|
31
|
+
p[n/2 - 2] = true
|
32
|
+
p[0] = true
|
33
|
+
|
34
|
+
q = random_state.urandomb(n/2)
|
35
|
+
q[n/2 - 1] = true
|
36
|
+
q[n/2 - 2] = true
|
37
|
+
q[0] = true
|
38
|
+
|
39
|
+
pq = p.gcd(q)
|
40
|
+
end
|
41
|
+
|
42
|
+
pq = p * q
|
43
|
+
|
44
|
+
e = GMP::Z(RSA_EXP)
|
45
|
+
|
46
|
+
pm1 = p - 1
|
47
|
+
qm1 = q - 1
|
48
|
+
phi = pm1 * qm1
|
49
|
+
d = e.invert(phi)
|
50
|
+
|
51
|
+
puts "done; pq is %i bits" % pq.sizeinbase(2)
|
52
|
+
puts "Precomputing CRT constants"
|
53
|
+
|
54
|
+
p_i_q = p.invert(q)
|
55
|
+
|
56
|
+
dp = d % pm1
|
57
|
+
dq = d % qm1
|
58
|
+
|
59
|
+
puts "Generating random messages"
|
60
|
+
|
61
|
+
msg = []
|
62
|
+
(0...1024).each do |i|
|
63
|
+
msg << random_state.urandomb(n)
|
64
|
+
end
|
65
|
+
|
66
|
+
print "Calibrating CPU speed..."
|
67
|
+
STDOUT.flush
|
68
|
+
t = GMP::time { smsg = rsa_sign(msg[0], p, q, pq, p_i_q, dp, dq) }
|
69
|
+
puts "done"
|
70
|
+
|
71
|
+
iterations = (1e4 / t).to_i
|
72
|
+
iterations = 1 if iterations == 0
|
73
|
+
|
74
|
+
print "Signing random messages %i times..." % iterations
|
75
|
+
STDOUT.flush
|
76
|
+
|
77
|
+
t0 = GMP::cputime
|
78
|
+
(1..iterations).to_a.reverse.each do |i|
|
79
|
+
smsg = rsa_sign(msg[i % 1024], p, q, pq, p_i_q, dp, dq)
|
80
|
+
end
|
81
|
+
ti = GMP::cputime - t0
|
82
|
+
|
83
|
+
puts "done!"
|
84
|
+
ops_per_sec = 1000.0 * iterations / ti
|
85
|
+
f = 100.0
|
86
|
+
decimals = 0
|
87
|
+
while true
|
88
|
+
decimals += 1
|
89
|
+
break if ops_per_sec > f
|
90
|
+
f = f * 0.1
|
91
|
+
end
|
92
|
+
|
93
|
+
puts "RESULT: %#{decimals}f operations per second\n" % ops_per_sec
|
data/benchmark/runbench
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
#! /bin/sh
|
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
|
+
|
22
|
+
echo "***** GMPbench version `cat version` *****"
|
23
|
+
|
24
|
+
|
25
|
+
default=false
|
26
|
+
|
27
|
+
if [ "$1" = -n ]
|
28
|
+
then
|
29
|
+
echo "Suppressing compilation"
|
30
|
+
else
|
31
|
+
if [ -z "$CFLAGS" ]
|
32
|
+
then
|
33
|
+
CFLAGS="-O3 -fomit-frame-pointer"
|
34
|
+
echo "Using default CFLAGS = \"$CFLAGS\""
|
35
|
+
default=true
|
36
|
+
else
|
37
|
+
echo "Using CFLAGS = \"$CFLAGS\" from your environment"
|
38
|
+
fi
|
39
|
+
if [ -z "$CC" ]
|
40
|
+
then
|
41
|
+
CC="gcc"
|
42
|
+
echo "Using default CC = \"$CC\""
|
43
|
+
default=true
|
44
|
+
else
|
45
|
+
echo "Using CC = \"$CC\" from your environment"
|
46
|
+
fi
|
47
|
+
if [ -z "$LIBS" ]
|
48
|
+
then
|
49
|
+
LIBS="-static -lgmp"
|
50
|
+
echo "Using default LIBS = \"$LIBS\""
|
51
|
+
default=true
|
52
|
+
else
|
53
|
+
echo "Using LIBS = \"$LIBS\" from your environment"
|
54
|
+
fi
|
55
|
+
|
56
|
+
echo "Using compilation command: $CC $CFLAGS foo.c -o foo $LIBS"
|
57
|
+
|
58
|
+
if $default
|
59
|
+
then
|
60
|
+
echo "You may want to override CC, CFLAGS, and LIBS"
|
61
|
+
fi
|
62
|
+
|
63
|
+
$CC $CFLAGS gmpver.c $LIBS
|
64
|
+
`mv a.exe a.out`
|
65
|
+
echo "Using `./a.out`"
|
66
|
+
|
67
|
+
echo "Compiling benchmarks"
|
68
|
+
$CC $CFLAGS gcd.c -o gcd $LIBS
|
69
|
+
$CC $CFLAGS gcdext.c -o gcdext $LIBS
|
70
|
+
$CC $CFLAGS multiply.c -o multiply $LIBS
|
71
|
+
$CC $CFLAGS divide.c -o divide $LIBS
|
72
|
+
$CC $CFLAGS rsa.c -o rsa $LIBS
|
73
|
+
$CC $CFLAGS pi.c -o pi $LIBS -lm
|
74
|
+
fi
|
75
|
+
|
76
|
+
multiply_args="128 512 8192 131072 2097152 128,128 512,512 8192,8192 131072,131072 2097152,2097152 15000,10000 20000,10000 30000,10000 16777216,512 16777216,262144"
|
77
|
+
multiply_weight=1
|
78
|
+
|
79
|
+
divide_args="8192,32 8192,64 8192,128 8192,4096 131072,65536 8388608,4194304 8192,8064 16777216,262144"
|
80
|
+
divide_weight=1
|
81
|
+
|
82
|
+
gcd_args="128,128 512,512 8192,8192 131072,131072 1048576,1048576"
|
83
|
+
gcd_weight=0.5
|
84
|
+
|
85
|
+
gcdext_args="128,128 512,512 8192,8192 131072,131072 1048576,1048576"
|
86
|
+
gcdext_weight=0.5
|
87
|
+
|
88
|
+
rsa_args="512 1024 2048"
|
89
|
+
rsa_weight=1
|
90
|
+
|
91
|
+
pi_args="10000 100000 1000000"
|
92
|
+
pi_weight=1
|
93
|
+
|
94
|
+
# base_tests="multiply divide gcd gcdext"
|
95
|
+
base_tests="multiply divide gcd"
|
96
|
+
# app_tests="rsa pi"
|
97
|
+
app_tests="rsa"
|
98
|
+
|
99
|
+
tests="base app"
|
100
|
+
|
101
|
+
echo "Running benchmarks (propagated score accuracy exceeds printed intermediates)"
|
102
|
+
|
103
|
+
acc2=1
|
104
|
+
n2=0
|
105
|
+
for cat in $tests
|
106
|
+
do
|
107
|
+
echo " Category $cat"
|
108
|
+
eval tests=\$${cat}_tests
|
109
|
+
|
110
|
+
acc1=1
|
111
|
+
n1=0
|
112
|
+
for t in $tests
|
113
|
+
do
|
114
|
+
eval weight=\$${t}_weight
|
115
|
+
echo " Program $t (weight=$weight)"
|
116
|
+
eval args=\$${t}_args
|
117
|
+
|
118
|
+
acc=1
|
119
|
+
n=0
|
120
|
+
for a in $args
|
121
|
+
do
|
122
|
+
ta=`echo $a | sed 's;,; ;g'`
|
123
|
+
printf ' %-48s' "GMPbench.$cat.$t($a)"
|
124
|
+
./$t $ta >RES-$t-$a
|
125
|
+
res=`grep "^RESULT" RES-$t-$a | sed 's;^RESULT: \([0-9.]*\).*$;\1;'`
|
126
|
+
printf '%12s\n' `gexpr -prec 4 "$res"`
|
127
|
+
acc=`gexpr -prec 10 "$acc * $res"`
|
128
|
+
n=`gexpr $n+1`
|
129
|
+
done
|
130
|
+
|
131
|
+
out=`gexpr -prec 10 "$acc^(1/$n)"`
|
132
|
+
printf ' %-40s%12s\n' "GMPbench.$cat.$t" `gexpr -prec 5 "$out"`
|
133
|
+
acc1=`gexpr -prec 10 "$acc1 * $out^$weight"`
|
134
|
+
n1=`gexpr $n1+$weight`
|
135
|
+
done
|
136
|
+
|
137
|
+
out=`gexpr -prec 10 "$acc1^(1/$n1)"`
|
138
|
+
printf ' %-32s%12s\n' "GMPbench.$cat" `gexpr -prec 5 "$out"`
|
139
|
+
acc2=`gexpr -prec 10 "$acc2 * $out"`
|
140
|
+
n2=`gexpr $n2+1`
|
141
|
+
done
|
142
|
+
|
143
|
+
|
144
|
+
out=`gexpr "$acc2^(1/$n2)"`
|
145
|
+
echo "GMPbench: $out"
|
146
|
+
|
147
|
+
exit 0
|
data/benchmark/version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'mkmf'
|
4
|
+
|
5
|
+
dir_config('gmp')
|
6
|
+
dir_config('mpfr')
|
7
|
+
|
8
|
+
ok = true
|
9
|
+
unless have_header('gmp.h')
|
10
|
+
$stderr.puts "can't find gmp.h, try --with-gmp-include=<path>"
|
11
|
+
ok = false
|
12
|
+
end
|
13
|
+
|
14
|
+
unless have_library('gmp', '__gmpz_init')
|
15
|
+
$stderr.puts "can't find -lgmp, try --with-gmp-lib=<path>"
|
16
|
+
ok = false
|
17
|
+
end
|
18
|
+
|
19
|
+
if (have_header('mpfr.h') and
|
20
|
+
have_header('mpf2mpfr.h') and
|
21
|
+
have_library('mpfr', 'mpfr_init'))
|
22
|
+
$CFLAGS += ' -DMPFR'
|
23
|
+
end
|
24
|
+
|
25
|
+
$CFLAGS += ' -Wall -W -O6 -g'
|
26
|
+
if ok
|
27
|
+
create_makefile('gmp')
|
28
|
+
else
|
29
|
+
raise "Unable to build, correct above errors and rerun"
|
30
|
+
end
|
data/ext/gmp.c
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
/*
|
2
|
+
* gmp.c
|
3
|
+
*
|
4
|
+
* This file contains everything you would expect from a C extension.
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <ruby_gmp.h>
|
8
|
+
|
9
|
+
VALUE mGMP, cGMP_Z, cGMP_Q, cGMP_F, cGMP_RandState;
|
10
|
+
|
11
|
+
void r_gmpz_free(void *ptr) { mpz_clear (ptr); free (ptr); }
|
12
|
+
void r_gmpq_free(void *ptr) { mpq_clear (ptr); free (ptr); }
|
13
|
+
void r_gmpf_free(void *ptr) { mpf_clear (ptr); free (ptr); }
|
14
|
+
void r_gmprandstate_free(void *ptr) { gmp_randclear (ptr); free (ptr); }
|
15
|
+
|
16
|
+
static void mpq_str_set(MP_RAT *ROP, char *str)
|
17
|
+
{
|
18
|
+
int i=0;
|
19
|
+
|
20
|
+
while (str[i] && str[i] != '/')
|
21
|
+
i++;
|
22
|
+
|
23
|
+
if (str[i])
|
24
|
+
{
|
25
|
+
str[i] = 0; /* You didn't see that :) */
|
26
|
+
mpz_set_str (mpq_numref(ROP), str, 0);
|
27
|
+
str[i] = '/';
|
28
|
+
mpz_set_str (mpq_denref(ROP), str+i+1, 0);
|
29
|
+
} else {
|
30
|
+
mpz_set_str (mpq_numref(ROP), str, 0);
|
31
|
+
mpz_set_ui (mpq_denref(ROP), 1);
|
32
|
+
}
|
33
|
+
mpq_canonicalize (ROP);
|
34
|
+
}
|
35
|
+
|
36
|
+
static VALUE r_gmpq_initialize(int argc, VALUE *argv, VALUE self)
|
37
|
+
{
|
38
|
+
MP_RAT *self_val, *arg_val;
|
39
|
+
|
40
|
+
if (argc != 0) {
|
41
|
+
mpq_get_struct(self, self_val);
|
42
|
+
if (argc == 1 && GMPQ_P(argv[0])) {
|
43
|
+
mpq_get_struct(argv[0], arg_val);
|
44
|
+
mpq_set (self_val, arg_val);
|
45
|
+
} else if (argc == 1 && STRING_P(argv[0])) {
|
46
|
+
mpq_str_set (self_val, STR2CSTR(argv[0]));
|
47
|
+
} else {
|
48
|
+
mpz_set_value (mpq_numref(self_val), argv[0]);
|
49
|
+
if (argc == 2) {
|
50
|
+
mpz_set_value (mpq_denref(self_val), argv[1]);
|
51
|
+
mpq_canonicalize(self_val);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
return Qnil;
|
56
|
+
}
|
57
|
+
|
58
|
+
/* don't pass GMP::F here, it should be handled separately */
|
59
|
+
void mpf_set_value(MP_FLOAT *self_val, VALUE arg)
|
60
|
+
{
|
61
|
+
MP_RAT *arg_val_q;
|
62
|
+
MP_INT *arg_val_z;
|
63
|
+
|
64
|
+
if (GMPQ_P(arg)) {
|
65
|
+
mpq_get_struct(arg, arg_val_q);
|
66
|
+
mpf_set_q(self_val, arg_val_q);
|
67
|
+
} else if (GMPZ_P(arg)) {
|
68
|
+
mpz_get_struct(arg, arg_val_z);
|
69
|
+
mpf_set_z(self_val, arg_val_z);
|
70
|
+
} else if (FLOAT_P(arg)) {
|
71
|
+
mpf_set_d(self_val, NUM2DBL(arg));
|
72
|
+
} else if (FIXNUM_P(arg)) {
|
73
|
+
mpf_set_si(self_val, FIX2INT(arg));
|
74
|
+
} else if (STRING_P(arg)) {
|
75
|
+
if (mpf_set_str(self_val, STR2CSTR(arg), 10) == -1) {
|
76
|
+
rb_raise(rb_eRuntimeError, "Badly formatted string");
|
77
|
+
}
|
78
|
+
} else if (BIGNUM_P(arg)) {
|
79
|
+
#if 1 /* GMP3 code */
|
80
|
+
mpz_temp_from_bignum(arg_val_z, arg);
|
81
|
+
mpf_set_z(self_val, arg_val_z);
|
82
|
+
mpz_temp_free(arg_val_z);
|
83
|
+
#endif
|
84
|
+
} else {
|
85
|
+
rb_raise(rb_eTypeError, "Don't know how to convert %s into GMP::F", rb_class2name(rb_class_of(arg)));
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
static VALUE r_gmpz_coerce(VALUE self, VALUE arg)
|
90
|
+
{
|
91
|
+
return rb_assoc_new(r_gmpzsg_new(1, &arg, cGMP_Z), self);
|
92
|
+
}
|
93
|
+
|
94
|
+
static VALUE r_gmpq_coerce(VALUE self, VALUE arg)
|
95
|
+
{
|
96
|
+
return rb_assoc_new(r_gmpqsg_new(1, &arg, cGMP_Q), self);
|
97
|
+
}
|
98
|
+
|
99
|
+
static VALUE r_gmpf_coerce(VALUE self, VALUE arg)
|
100
|
+
{
|
101
|
+
return rb_assoc_new(r_gmpfsg_new(1, &arg, cGMP_F), self);
|
102
|
+
}
|
103
|
+
|
104
|
+
static VALUE r_gmpfsg_get_default_prec(VALUE klass)
|
105
|
+
{
|
106
|
+
(void)klass;
|
107
|
+
return INT2NUM(mpf_get_default_prec());
|
108
|
+
}
|
109
|
+
|
110
|
+
static VALUE r_gmpfsg_set_default_prec(VALUE klass, VALUE arg)
|
111
|
+
{
|
112
|
+
(void)klass;
|
113
|
+
if (FIXNUM_P(arg)) {
|
114
|
+
if (FIX2INT(arg) <= 0) {
|
115
|
+
rb_raise(rb_eRangeError, "prec must be positive");
|
116
|
+
}
|
117
|
+
mpf_set_default_prec (FIX2INT(arg));
|
118
|
+
} else {
|
119
|
+
rb_raise(rb_eTypeError, "prec must be FixNum");
|
120
|
+
}
|
121
|
+
return Qnil;
|
122
|
+
}
|
123
|
+
|
124
|
+
#include "gmpf.h"
|
125
|
+
#include "gmpq.h"
|
126
|
+
/* #include "gmpz.h" */
|
127
|
+
#include "takeover.h"
|
128
|
+
|
129
|
+
#define REGISTER_TAKEOVER(fname, ruby_fname, old_fname) \
|
130
|
+
rb_define_alias(rb_cFixnum, old_fname, ruby_fname); \
|
131
|
+
rb_define_method(rb_cFixnum, ruby_fname, takeover_fixnum_##fname, -1); \
|
132
|
+
rb_define_alias(rb_cBignum, old_fname, ruby_fname); \
|
133
|
+
rb_define_method(rb_cBignum, ruby_fname, takeover_bignum_##fname, -1);
|
134
|
+
|
135
|
+
void Init_gmp() {
|
136
|
+
mGMP = rb_define_module("GMP");
|
137
|
+
rb_define_const(mGMP, "GMP_VERSION", rb_str_new2(gmp_version));
|
138
|
+
|
139
|
+
cGMP_Z = rb_define_class_under(mGMP, "Z", rb_cInteger);
|
140
|
+
init_gmpz();
|
141
|
+
rb_define_method(cGMP_Z, "coerce", r_gmpz_coerce, 1);
|
142
|
+
|
143
|
+
cGMP_Q = rb_define_class_under (mGMP, "Q", rb_cNumeric);
|
144
|
+
init_gmpq();
|
145
|
+
rb_define_method(cGMP_Q, "initialize", r_gmpq_initialize, -1);
|
146
|
+
rb_define_method(cGMP_Q, "coerce", r_gmpq_coerce, 1);
|
147
|
+
rb_define_method(cGMP_Q, "num", r_gmpq_num, 0);
|
148
|
+
rb_define_method(cGMP_Q, "den", r_gmpq_den, 0);
|
149
|
+
|
150
|
+
cGMP_F = rb_define_class_under (mGMP, "F", rb_cNumeric);
|
151
|
+
init_gmpf();
|
152
|
+
rb_define_singleton_method(cGMP_F, "default_prec", r_gmpfsg_get_default_prec, 0);
|
153
|
+
rb_define_singleton_method(cGMP_F, "default_prec=", r_gmpfsg_set_default_prec, 1);
|
154
|
+
rb_define_method(cGMP_F, "coerce", r_gmpf_coerce, 1); // new method - testing
|
155
|
+
|
156
|
+
/* rb_define_method(cGMP_F, "cmpabs", r_gmpf_cmpabs, 1);*/
|
157
|
+
|
158
|
+
cGMP_RandState = rb_define_class_under (mGMP, "RandState", rb_cObject);
|
159
|
+
init_gmprandstate();
|
160
|
+
|
161
|
+
init_gmpbench_timing();
|
162
|
+
|
163
|
+
#ifdef MPFR
|
164
|
+
rb_define_method(cGMP_F, "exp", r_gmpfr_exp, 0);
|
165
|
+
rb_define_method(cGMP_F, "log", r_gmpfr_log, 0);
|
166
|
+
rb_define_method(cGMP_F, "sqrt", r_gmpfr_sqrt, 0);
|
167
|
+
rb_define_method(cGMP_F, "cos", r_gmpfr_cos, 0);
|
168
|
+
rb_define_method(cGMP_F, "sin", r_gmpfr_sin, 0);
|
169
|
+
rb_define_method(cGMP_F, "tan", r_gmpfr_tan, 0);
|
170
|
+
rb_define_method(cGMP_F, "acos", r_gmpfr_acos, 0);
|
171
|
+
rb_define_method(cGMP_F, "asin", r_gmpfr_asin, 0);
|
172
|
+
rb_define_method(cGMP_F, "atan", r_gmpfr_atan, 0);
|
173
|
+
rb_define_method(cGMP_F, "cosh", r_gmpfr_cosh, 0);
|
174
|
+
rb_define_method(cGMP_F, "sinh", r_gmpfr_sinh, 0);
|
175
|
+
rb_define_method(cGMP_F, "tanh", r_gmpfr_tanh, 0);
|
176
|
+
rb_define_method(cGMP_F, "acosh", r_gmpfr_acosh, 0);
|
177
|
+
rb_define_method(cGMP_F, "asinh", r_gmpfr_asinh, 0);
|
178
|
+
rb_define_method(cGMP_F, "atanh", r_gmpfr_atanh, 0);
|
179
|
+
rb_define_method(cGMP_F, "log1p", r_gmpfr_log1p, 0);
|
180
|
+
rb_define_method(cGMP_F, "expm1", r_gmpfr_expm1, 0);
|
181
|
+
rb_define_method(cGMP_F, "log2", r_gmpfr_log2, 0);
|
182
|
+
rb_define_method(cGMP_F, "log10", r_gmpfr_log10, 0);
|
183
|
+
|
184
|
+
rb_define_method(cGMP_F, "nan?", r_gmpfr_nan_p, 0);
|
185
|
+
rb_define_method(cGMP_F, "infinite?", r_gmpfr_inf_p, 0);
|
186
|
+
rb_define_method(cGMP_F, "finite?", r_gmpfr_fin_p, 0);
|
187
|
+
rb_define_method(cGMP_F, "number?", r_gmpfr_number_p, 0);
|
188
|
+
|
189
|
+
rb_define_method(cGMP_F, "**", r_gmpfr_pow, 1);
|
190
|
+
#endif /* MPFR */
|
191
|
+
// more
|
192
|
+
|
193
|
+
REGISTER_TAKEOVER(and, "&", "old_and")
|
194
|
+
REGISTER_TAKEOVER(or, "|", "old_or")
|
195
|
+
REGISTER_TAKEOVER(xor, "^", "old_xor")
|
196
|
+
/* takeover cmpabs ? */
|
197
|
+
}
|