gmp 0.6.47 → 0.7.19
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 +21 -1
- data/README.markdown +29 -9
- data/ext/extconf.rb +8 -0
- data/ext/gmp.c +7 -7
- data/ext/gmpf.c +620 -139
- data/ext/gmpq.c +218 -90
- data/ext/gmprandstate.c +57 -53
- data/ext/gmpz.c +492 -440
- data/ext/mprnd.c +44 -35
- data/ext/ruby_gmp.h +6 -6
- data/manual.pdf +0 -0
- data/manual.tex +2 -2
- data/test/mpfr_thypot.rb +60 -0
- data/test/tc_cmp.rb +1 -1
- data/test/tc_constants.rb +1 -1
- data/test/tc_division.rb +1 -1
- data/test/tc_f_abs_neg.rb +1 -1
- data/test/tc_f_arithmetics_coersion.rb +1 -1
- data/test/tc_f_precision.rb +2 -1
- data/test/tc_f_to_s.rb +1 -1
- data/test/tc_hashes.rb +1 -4
- data/test/tc_mpfr_cmp.rb +1 -1
- data/test/tc_mpfr_constants.rb +1 -1
- data/test/tc_mpfr_functions.rb +43 -10
- data/test/tc_mpfr_inf_nan_zero.rb +1 -1
- data/test/tc_mpfr_integer.rb +1 -1
- data/test/tc_mpfr_new_rounding.rb +24 -1
- data/test/tc_mpfr_pow.rb +17 -0
- data/test/tc_mpfr_random.rb +1 -1
- data/test/tc_mpfr_rounding.rb +1 -1
- data/test/tc_q.rb +53 -32
- data/test/tc_q_basic.rb +1 -1
- data/test/{tc_floor_ceil_truncate.rb → tc_q_floor_ceil_truncate.rb} +2 -2
- data/test/tc_q_num_den.rb +18 -0
- data/test/tc_random.rb +1 -4
- data/test/tc_sgn_neg_abs.rb +1 -1
- data/test/tc_swap.rb +1 -1
- data/test/tc_z.rb +1 -1
- data/test/tc_z_addmul.rb +1 -1
- data/test/tc_z_basic.rb +3 -2
- data/test/tc_z_exponentiation.rb +5 -5
- data/test/tc_z_export_import.rb +1 -1
- data/test/{tc_fib_fac_nextprime.rb → tc_z_fib_fac_nextprime.rb} +1 -1
- data/test/tc_z_functional_mappings.rb +2 -2
- data/test/tc_z_gcd_lcm_invert.rb +1 -1
- data/test/tc_z_hamdist.rb +1 -1
- data/test/tc_z_io.rb +2 -1
- data/test/tc_z_jac_leg_rem.rb +1 -1
- data/test/tc_z_logic.rb +1 -1
- data/test/{tc_logical_roots.rb → tc_z_logical_roots.rb} +7 -7
- data/test/tc_z_shifts_last_bits.rb +2 -2
- data/test/tc_z_submul.rb +1 -1
- data/test/tc_z_to_dis.rb +1 -1
- data/test/{tc_zerodivisionexceptions.rb → tc_zero_division_exceptions.rb} +2 -2
- data/test/unit_tests.rb +30 -17
- metadata +16 -16
- data/INSTALL +0 -4
data/ext/mprnd.c
CHANGED
@@ -11,8 +11,8 @@ VALUE r_mprndsg_new(int argc, VALUE *argv, VALUE klass)
|
|
11
11
|
(void)klass;
|
12
12
|
res_value = 0;
|
13
13
|
|
14
|
-
mprnd_make_struct(res, res_value);
|
15
|
-
rb_obj_call_init(res, argc, argv);
|
14
|
+
mprnd_make_struct (res, res_value);
|
15
|
+
rb_obj_call_init (res, argc, argv);
|
16
16
|
return res;
|
17
17
|
}
|
18
18
|
|
@@ -27,68 +27,77 @@ VALUE r_mprnd_initialize(int argc, VALUE *argv, VALUE self)
|
|
27
27
|
prefix = "GMP";
|
28
28
|
else
|
29
29
|
prefix = "MPFR";
|
30
|
-
switch (FIX2INT(mode)) {
|
30
|
+
switch (FIX2INT (mode)) {
|
31
31
|
case 0:
|
32
|
-
sprintf(name_val, "%s_RNDN", prefix);
|
33
|
-
ieee754 = rb_str_new2("roundTiesToEven");
|
32
|
+
sprintf (name_val, "%s_RNDN", prefix);
|
33
|
+
ieee754 = rb_str_new2 ("roundTiesToEven");
|
34
34
|
break;
|
35
35
|
case 1:
|
36
|
-
sprintf(name_val, "%s_RNDZ", prefix);
|
37
|
-
ieee754 = rb_str_new2("roundTowardZero");
|
36
|
+
sprintf (name_val, "%s_RNDZ", prefix);
|
37
|
+
ieee754 = rb_str_new2 ("roundTowardZero");
|
38
38
|
break;
|
39
39
|
case 2:
|
40
|
-
sprintf(name_val, "%s_RNDU", prefix);
|
41
|
-
ieee754 = rb_str_new2("roundTowardPositive");
|
40
|
+
sprintf (name_val, "%s_RNDU", prefix);
|
41
|
+
ieee754 = rb_str_new2 ("roundTowardPositive");
|
42
42
|
break;
|
43
43
|
case 3:
|
44
|
-
sprintf(name_val, "%s_RNDD", prefix);
|
45
|
-
ieee754 = rb_str_new2("roundTowardNegative");
|
44
|
+
sprintf (name_val, "%s_RNDD", prefix);
|
45
|
+
ieee754 = rb_str_new2 ("roundTowardNegative");
|
46
46
|
break;
|
47
47
|
case 4:
|
48
|
-
sprintf(name_val, "%s_RNDA", prefix);
|
49
|
-
ieee754 = rb_str_new2("roundAwayFromZero");
|
48
|
+
sprintf (name_val, "%s_RNDA", prefix);
|
49
|
+
ieee754 = rb_str_new2 ("roundAwayFromZero");
|
50
50
|
break;
|
51
51
|
default:
|
52
|
-
sprintf(name_val, "%s_RNDN", prefix);
|
53
|
-
ieee754 = rb_str_new2("roundTiesToEven");
|
52
|
+
sprintf (name_val, "%s_RNDN", prefix);
|
53
|
+
ieee754 = rb_str_new2 ("roundTiesToEven");
|
54
54
|
}
|
55
|
-
name = rb_str_new2(name_val);
|
56
|
-
rb_iv_set(self, "@mode", mode);
|
57
|
-
rb_iv_set(self, "@name", name);
|
58
|
-
rb_iv_set(self, "@ieee754", ieee754);
|
55
|
+
name = rb_str_new2 (name_val);
|
56
|
+
rb_iv_set (self, "@mode", mode);
|
57
|
+
rb_iv_set (self, "@name", name);
|
58
|
+
rb_iv_set (self, "@ieee754", ieee754);
|
59
59
|
return Qnil;
|
60
60
|
}
|
61
61
|
|
62
62
|
VALUE r_mprnd_inspect(VALUE self)
|
63
63
|
{
|
64
|
-
return rb_iv_get(self, "@name");
|
64
|
+
return rb_iv_get (self, "@name");
|
65
65
|
}
|
66
66
|
|
67
67
|
void init_gmprnd()
|
68
68
|
{
|
69
|
-
ID new_id = rb_intern("new");
|
70
|
-
mGMP = rb_define_module("GMP");
|
69
|
+
ID new_id = rb_intern ("new");
|
70
|
+
mGMP = rb_define_module ("GMP");
|
71
71
|
|
72
|
-
cGMP_Rnd = rb_define_class_under(mGMP, "Rnd", rb_cObject);
|
72
|
+
cGMP_Rnd = rb_define_class_under (mGMP, "Rnd", rb_cObject);
|
73
73
|
|
74
|
-
rb_define_singleton_method(cGMP_Rnd, "new", r_mprndsg_new, -1);
|
75
|
-
rb_define_method(cGMP_Rnd, "initialize", r_mprnd_initialize, -1);
|
76
|
-
rb_define_method(cGMP_Rnd, "inspect", r_mprnd_inspect, 0);
|
74
|
+
rb_define_singleton_method (cGMP_Rnd, "new", r_mprndsg_new, -1);
|
75
|
+
rb_define_method (cGMP_Rnd, "initialize", r_mprnd_initialize, -1);
|
76
|
+
rb_define_method (cGMP_Rnd, "inspect", r_mprnd_inspect, 0);
|
77
77
|
|
78
78
|
rb_define_attr (cGMP_Rnd, "mode", 1, 0);
|
79
79
|
rb_define_attr (cGMP_Rnd, "name", 1, 0);
|
80
80
|
rb_define_attr (cGMP_Rnd, "ieee754", 1, 0);
|
81
81
|
|
82
|
-
|
83
|
-
rb_define_const(mGMP, "
|
84
|
-
|
85
|
-
rb_define_const(mGMP, "
|
82
|
+
/* GMP_RNDN: MPFR rounding mode roundTiesToEven for MPFR < 3.0 */
|
83
|
+
rb_define_const (mGMP, "GMP_RNDN", rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX (0)));
|
84
|
+
/* GMP_RNDZ: MPFR rounding mode roundTowardZero for MPFR < 3.0 */
|
85
|
+
rb_define_const (mGMP, "GMP_RNDZ", rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX (1)));
|
86
|
+
/* GMP_RNDU: MPFR rounding mode roundTowardPositive for MPFR < 3.0 */
|
87
|
+
rb_define_const (mGMP, "GMP_RNDU", rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX (2)));
|
88
|
+
/* GMP_RNDD: MPFR rounding mode roundTowardNegative for MPFR < 3.0 */
|
89
|
+
rb_define_const (mGMP, "GMP_RNDD", rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX (3)));
|
86
90
|
/* MPFR 3.0.0 */
|
87
|
-
|
88
|
-
rb_define_const(mGMP, "
|
89
|
-
|
90
|
-
rb_define_const(mGMP, "
|
91
|
-
|
91
|
+
/* MPFR_RNDN: MPFR rounding mode roundTiesToEven */
|
92
|
+
rb_define_const (mGMP, "MPFR_RNDN", rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX (0)));
|
93
|
+
/* MPFR_RNDZ: MPFR rounding mode roundTowardZero */
|
94
|
+
rb_define_const (mGMP, "MPFR_RNDZ", rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX (1)));
|
95
|
+
/* MPFR_RNDU: MPFR rounding mode roundTowardPositive */
|
96
|
+
rb_define_const (mGMP, "MPFR_RNDU", rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX (2)));
|
97
|
+
/* MPFR_RNDU: MPFR rounding mode roundTowardNegative */
|
98
|
+
rb_define_const (mGMP, "MPFR_RNDD", rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX (3)));
|
99
|
+
/* MPFR_RNDA: MPFR rounding mode roundAwayFromZero */
|
100
|
+
rb_define_const (mGMP, "MPFR_RNDA", rb_funcall (cGMP_Rnd, new_id, 1, INT2FIX (4)));
|
92
101
|
/* end MPFR 3.0.0 */
|
93
102
|
}
|
94
103
|
|
data/ext/ruby_gmp.h
CHANGED
@@ -94,12 +94,12 @@ typedef __gmp_randstate_struct MP_RANDSTATE;
|
|
94
94
|
|
95
95
|
#if defined(MPFR) && defined(HAVE_MPFR_H)
|
96
96
|
#define mpf_get_struct_prec(ruby_var,c_var,prec) { \
|
97
|
-
mpf_get_struct (ruby_var,c_var);
|
97
|
+
mpf_get_struct (ruby_var, c_var); \
|
98
98
|
prec = mpfr_get_prec (c_var); \
|
99
99
|
}
|
100
100
|
#define mpf_make_struct_init(ruby_var,c_var,prec) { \
|
101
|
-
mpf_make_struct (ruby_var,c_var);
|
102
|
-
mpfr_init2 (c_var,prec);
|
101
|
+
mpf_make_struct (ruby_var, c_var); \
|
102
|
+
mpfr_init2 (c_var, prec); \
|
103
103
|
}
|
104
104
|
#define mpf_temp_init(var,prec) { mpf_temp_alloc(var); mpfr_init2(var,prec); }
|
105
105
|
#define mpf_temp_free(var) { mpfr_clear(var); free(var); }
|
@@ -264,8 +264,8 @@ extern int mpq_cmp_value(MP_RAT *OP, VALUE arg);
|
|
264
264
|
extern VALUE r_gmpq_sgn(VALUE self);
|
265
265
|
|
266
266
|
// Applying Integer Functions
|
267
|
-
extern VALUE
|
268
|
-
extern VALUE
|
267
|
+
extern VALUE r_gmpq_get_num(VALUE self);
|
268
|
+
extern VALUE r_gmpq_get_den(VALUE self);
|
269
269
|
|
270
270
|
// _unsorted_
|
271
271
|
|
@@ -307,7 +307,7 @@ extern int mpf_cmp_value(MP_FLOAT *OP, VALUE arg);
|
|
307
307
|
|
308
308
|
// MPFR
|
309
309
|
#ifdef MPFR
|
310
|
-
extern void mpf_set_value2(MP_FLOAT *self_val, VALUE arg, int base);
|
310
|
+
extern void mpf_set_value2(MP_FLOAT *self_val, VALUE arg, int base, mp_rnd_t rnd_mode_val);
|
311
311
|
|
312
312
|
extern VALUE r_gmpfr_sqrt(int argc, VALUE *argv, VALUE self);
|
313
313
|
extern VALUE r_gmpfr_rec_sqrt(int argc, VALUE *argv, VALUE self);
|
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.
|
38
|
-
\multicolumn{2}{r}{\large{
|
37
|
+
\multicolumn{2}{r}{\large{Edition 0.7.19}}\\
|
38
|
+
\multicolumn{2}{r}{\large{12 March 2014}}
|
39
39
|
\end{tabular}
|
40
40
|
|
41
41
|
\vfill
|
data/test/mpfr_thypot.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
|
+
|
3
|
+
class MpfrTHypot < Test::Unit::TestCase
|
4
|
+
def test_special
|
5
|
+
x = GMP::F.nan
|
6
|
+
y = GMP::F.new
|
7
|
+
assert_equal(GMP::F.nan, x.hypot(y), "NaN.hypot(...) is NaN")
|
8
|
+
|
9
|
+
x = GMP::F.inf
|
10
|
+
y = GMP::F.inf(-1)
|
11
|
+
assert_equal(GMP::F.inf, x.hypot(y), "Inf.hypot(-Inf) is Inf")
|
12
|
+
|
13
|
+
x = GMP::F.nan
|
14
|
+
y = GMP::F.inf(-1)
|
15
|
+
assert_equal(GMP::F.inf, x.hypot(y), "NaN.hypot(-Inf) is Inf")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_large
|
19
|
+
x = GMP::F(21)
|
20
|
+
y = GMP::F(28)
|
21
|
+
z = GMP::F(35)
|
22
|
+
|
23
|
+
# TODO: need mpfr_mul_2ui!!!
|
24
|
+
end
|
25
|
+
|
26
|
+
def small_tests
|
27
|
+
x = GMP::F.new_2exp(1, GMP::F.emin-1, 8)
|
28
|
+
y = GMP::F.new_2exp(1, GMP::F.emin-1, 8)
|
29
|
+
z1 = GMP::F.new(2, 8)
|
30
|
+
z1 = z1.sqrt * x
|
31
|
+
z2 = x.hypot(y)
|
32
|
+
|
33
|
+
assert_equal(z1, z2, "x.hypot(y) should == sqrt(2) * x")
|
34
|
+
end
|
35
|
+
|
36
|
+
def large_small_tests
|
37
|
+
x = GMP::F.new_2exp(1, GMP::F.emax/2, 3)
|
38
|
+
y = GMP::F.new_2exp(1, -1, 2)
|
39
|
+
z = x.hypot(y)
|
40
|
+
|
41
|
+
assert_equal(x, z, "hypot... something abount large_small")
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_hypot
|
45
|
+
small_tests
|
46
|
+
large_small_tests
|
47
|
+
|
48
|
+
emin = GMP::F.emin
|
49
|
+
emax = GMP::F.emax
|
50
|
+
GMP::F.emin = GMP::F.emin_min
|
51
|
+
GMP::F.emax = GMP::F.emax_max
|
52
|
+
|
53
|
+
if GMP::F.emin != emin || GMP::F.emax != emax
|
54
|
+
small_tests
|
55
|
+
large_small_tests
|
56
|
+
GMP::F.emin = emin
|
57
|
+
GMP::F.emax = emax
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/test/tc_cmp.rb
CHANGED
data/test/tc_constants.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
2
|
|
3
|
-
class
|
3
|
+
class TcConstants < Test::Unit::TestCase
|
4
4
|
def test_constants
|
5
5
|
assert_instance_of(String, GMP::GMP_VERSION, "GMP::GMP_VERSION should be a String")
|
6
6
|
assert_instance_of(String, GMP::GMP_CC, "GMP::GMP_CC should be a String")
|
data/test/tc_division.rb
CHANGED
data/test/tc_f_abs_neg.rb
CHANGED
data/test/tc_f_precision.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
2
|
|
3
|
-
class
|
3
|
+
class TcFloatPrecision < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
+
# TODO: um... what?
|
5
6
|
begin
|
6
7
|
GMP::MPFR_VERSION
|
7
8
|
@initial_default_prec = GMP::F.default_prec
|
data/test/tc_f_to_s.rb
CHANGED
data/test/tc_hashes.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
2
|
|
3
|
-
class
|
4
|
-
def setup
|
5
|
-
end
|
6
|
-
|
3
|
+
class TcHashes < Test::Unit::TestCase
|
7
4
|
def test_z_hashes
|
8
5
|
h = {}
|
9
6
|
h[GMP::Z(131)] = [GMP::Z(41), GMP::Z(43), GMP::Z(47)]
|
data/test/tc_mpfr_cmp.rb
CHANGED
data/test/tc_mpfr_constants.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
2
|
|
3
|
-
class
|
3
|
+
class TcMpfrConstants < Test::Unit::TestCase
|
4
4
|
def test_mpfr_constants
|
5
5
|
assert_instance_of(String, GMP::MPFR_VERSION, "GMP::MPFR_VERSION should be a String")
|
6
6
|
assert_instance_of(Fixnum, GMP::MPFR_PREC_MIN, "GMP::MPFR_PREC_MIN should be a Fixnum")
|
data/test/tc_mpfr_functions.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
2
|
|
3
|
-
class
|
3
|
+
class TcMpfrFunctions < Test::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
@a = GMP::F(1)
|
6
6
|
@b = GMP::F(2)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def test_const_existence
|
10
10
|
constants = ["const_log2", "const_pi", "const_euler", "const_catalan"]
|
11
11
|
|
@@ -30,7 +30,7 @@ class TC_MPFR_Functions < Test::Unit::TestCase
|
|
30
30
|
}
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def test_function_existence
|
35
35
|
assert_nothing_raised("GMP::F.nan? should be callable.") { @a.nan? }
|
36
36
|
assert_nothing_raised("GMP::F.infinite? should be callable.") { @a.infinite? }
|
@@ -43,7 +43,7 @@ class TC_MPFR_Functions < Test::Unit::TestCase
|
|
43
43
|
assert_nothing_raised("GMP::F.sqrt should be callable.") { @a.sqrt }
|
44
44
|
assert_nothing_raised("GMP::F.rec_sqrt should be callable.") { @a.rec_sqrt }
|
45
45
|
assert_nothing_raised("GMP::F.cbrt should be callable.") { @a.cbrt }
|
46
|
-
|
46
|
+
|
47
47
|
assert_nothing_raised("GMP::F.log should be callable.") { @a.log }
|
48
48
|
assert_nothing_raised("GMP::F.log2 should be callable.") { @a.log2 }
|
49
49
|
assert_nothing_raised("GMP::F.log10 should be callable.") { @a.log10 }
|
@@ -61,7 +61,8 @@ class TC_MPFR_Functions < Test::Unit::TestCase
|
|
61
61
|
assert_nothing_raised("GMP::F.asin should be callable.") { @a.asin }
|
62
62
|
assert_nothing_raised("GMP::F.atan should be callable.") { @a.atan }
|
63
63
|
assert_nothing_raised("GMP::F.atan2 should be callable.") { @a.atan2(@b) }
|
64
|
-
|
64
|
+
assert_nothing_raised("GMP::F.atan2 should be callable with float arg") { @a.atan2(2.0) }
|
65
|
+
|
65
66
|
assert_nothing_raised("GMP::F.cosh should be callable.") { @a.cosh }
|
66
67
|
assert_nothing_raised("GMP::F.sinh should be callable.") { @a.sinh }
|
67
68
|
assert_nothing_raised("GMP::F.tanh should be callable.") { @a.tanh }
|
@@ -72,14 +73,14 @@ class TC_MPFR_Functions < Test::Unit::TestCase
|
|
72
73
|
assert_nothing_raised("GMP::F.acosh should be callable.") { @a.acosh }
|
73
74
|
assert_nothing_raised("GMP::F.asinh should be callable.") { @a.asinh }
|
74
75
|
assert_nothing_raised("GMP::F.atanh should be callable.") { @a.atanh }
|
75
|
-
|
76
|
+
|
76
77
|
assert_nothing_raised("GMP::F.log1p should be callable.") { @a.log1p }
|
77
78
|
assert_nothing_raised("GMP::F.expm1 should be callable.") { @a.expm1 }
|
78
79
|
assert_nothing_raised("GMP::F.eint should be callable.") { @a.eint }
|
79
80
|
assert_nothing_raised("GMP::F.li2 should be callable.") { @a.li2 }
|
80
81
|
assert_nothing_raised("GMP::F.gamma should be callable.") { @a.gamma }
|
81
82
|
assert_nothing_raised("GMP::F.lngamma should be callable.") { @a.lngamma }
|
82
|
-
#assert_nothing_raised("GMP::F.lgamma should be callable.") { @a.lgamma }
|
83
|
+
# TODO: assert_nothing_raised("GMP::F.lgamma should be callable.") { @a.lgamma }
|
83
84
|
if GMP::MPFR_VERSION >= "3.0.0"
|
84
85
|
assert_nothing_raised("GMP::F.digamma should be callable.") { @a.digamma }
|
85
86
|
end
|
@@ -98,11 +99,40 @@ class TC_MPFR_Functions < Test::Unit::TestCase
|
|
98
99
|
assert_nothing_raised("GMP::F.yn should be callable.") { @a.yn(0) }
|
99
100
|
assert_nothing_raised("GMP::F.yn should be callable.") { @a.yn(1) }
|
100
101
|
assert_nothing_raised("GMP::F.yn should be callable.") { @a.yn(2) }
|
101
|
-
|
102
|
+
|
102
103
|
assert_nothing_raised("GMP::F.agm should be callable.") { @a.agm(@b) }
|
103
104
|
assert_nothing_raised("GMP::F.hypot should be callable.") { @a.hypot(@b) }
|
104
105
|
end
|
105
|
-
|
106
|
+
|
107
|
+
def test_atan2
|
108
|
+
assert_in_delta @a.atan2(@b), Math.atan2(@a.to_f, @b.to_f), 0.0001
|
109
|
+
assert_in_delta (-@a).atan2((-@b)), Math.atan2((-@a).to_f, (-@b).to_f), 0.0001
|
110
|
+
assert_in_delta @a.atan2(3.0), Math.atan2(@a.to_f, 3.0), 0.0001
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_class_methods
|
114
|
+
assert_true(GMP::F.emin.is_a?(Integer), "GMP::F.emin is callable")
|
115
|
+
assert_true(GMP::F.emax.is_a?(Integer), "GMP::F.emax is callable")
|
116
|
+
assert_true(GMP::F.emin_min.is_a?(Integer), "GMP::F.emin_min is callable")
|
117
|
+
assert_true(GMP::F.emin_max.is_a?(Integer), "GMP::F.emin_max is callable")
|
118
|
+
assert_true(GMP::F.emax_min.is_a?(Integer), "GMP::F.emax_min is callable")
|
119
|
+
assert_true(GMP::F.emax_max.is_a?(Integer), "GMP::F.emax_max is callable")
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_emin
|
123
|
+
emin = GMP::F.emin
|
124
|
+
assert_nothing_raised("GMP::F.emin= works with good exp") { GMP::F.emin = emin/2 }
|
125
|
+
assert_equal(emin/2, GMP::F.emin, "GMP::F.emin= sets emin")
|
126
|
+
assert_raise(TypeError) { GMP::F.emin = :not_a_number }
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_emax
|
130
|
+
emax = GMP::F.emax
|
131
|
+
assert_nothing_raised("GMP::F.emax= works with good exp") { GMP::F.emax = emax/2 }
|
132
|
+
assert_equal(emax/2, GMP::F.emax, "GMP::F.emax= sets emax")
|
133
|
+
assert_raise(TypeError) { GMP::F.emax = :not_a_number }
|
134
|
+
end
|
135
|
+
|
106
136
|
def test_function_parameters
|
107
137
|
single_functions = [:sqrt, :rec_sqrt, :cbrt,
|
108
138
|
:log, :log2, :log10, :exp, :exp2, :exp10,
|
@@ -117,14 +147,17 @@ class TC_MPFR_Functions < Test::Unit::TestCase
|
|
117
147
|
single_functions += [:digamma] if GMP::MPFR_VERSION >= "3.0.0"
|
118
148
|
double_functions = [:sin_cos, :sinh_cosh]
|
119
149
|
single_mpf_functions = [:atan2, :agm, :hypot]
|
120
|
-
|
150
|
+
|
121
151
|
(single_functions + double_functions).each do |f|
|
122
152
|
assert_nothing_raised("GMP::F.#{f} can be called w/ 1 arg: rounding_mode.") { @a.send(f, GMP::GMP_RNDN) }
|
123
153
|
assert_nothing_raised("GMP::F.#{f} can be called w/ 1 arg: rounding_mode.") { @a.send(f, GMP::GMP_RNDZ) }
|
124
154
|
assert_nothing_raised("GMP::F.#{f} can be called w/ 2 args: rounding_mode, prec.") { @a.send(f, GMP::GMP_RNDN, 32) }
|
125
155
|
assert_nothing_raised("GMP::F.#{f} can be called w/ 2 args: rounding_mode, prec.") { @a.send(f, GMP::GMP_RNDN, 128) }
|
126
156
|
assert_nothing_raised("GMP::F.#{f} can be called w/ 2 args: rounding_mode, prec.") { @a.send(f, GMP::GMP_RNDN, 200) }
|
157
|
+
|
158
|
+
assert_raise(TypeError) { @a.send(f, GMP::GMP_RNDN, "not a Fixnum") }
|
127
159
|
end
|
160
|
+
|
128
161
|
double_functions.each do |f|
|
129
162
|
assert_nothing_raised("GMP::F.#{f} can be called w/ 3 args: rounding_mode, prec, prec.") { @a.send(f, GMP::GMP_RNDN, 64, 64) }
|
130
163
|
assert_nothing_raised("GMP::F.#{f} can be called w/ 3 args: rounding_mode, prec, prec.") { @a.send(f, GMP::GMP_RNDN, 128, 64) }
|