gmp 0.6.43 → 0.6.47
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +15 -0
- data/README.markdown +23 -13
- data/ext/gmp.c +13 -6
- data/ext/gmpf.c +377 -166
- data/ext/gmpq.c +17 -17
- data/ext/gmprandstate.c +72 -23
- data/ext/ruby_gmp.h +35 -19
- data/manual.pdf +0 -0
- data/manual.tex +140 -5
- data/test/gmp_troot.rb +4 -0
- data/test/mpfr_tcbrt.rb +3 -3
- data/test/mpfr_tconst_euler.rb +15 -24
- data/test/mpfr_tfac.rb +49 -0
- data/test/mpfr_tfrexp.rb +47 -0
- data/test/tc_f_abs_neg.rb +28 -0
- data/test/tc_f_to_s.rb +29 -15
- data/test/tc_mpfr_cmp.rb +29 -0
- data/test/tc_mpfr_inf_nan_zero.rb +29 -0
- data/test/tc_mpfr_new_rounding.rb +126 -0
- data/test/tc_mpfr_random.rb +63 -3
- data/test/tc_sgn_neg_abs.rb +3 -3
- data/test/test_helper.rb +12 -3
- data/test/unit_tests.rb +8 -4
- metadata +10 -3
data/test/gmp_troot.rb
CHANGED
@@ -5,6 +5,10 @@ class GMP_TRoot < Test::Unit::TestCase
|
|
5
5
|
Reps = 500
|
6
6
|
|
7
7
|
def one_test(root1, x2, nth, i)
|
8
|
+
# Travis revealed something weird on Linux. rootrem gives a different result:
|
9
|
+
#
|
10
|
+
# https://travis-ci.org/srawlins/gmp/jobs/15112258
|
11
|
+
skip if !RUBY_PLATFORM["darwin"]
|
8
12
|
root2, rem2 = x2.rootrem(nth)
|
9
13
|
temp = root1 ** nth
|
10
14
|
temp2 = temp + rem2
|
data/test/mpfr_tcbrt.rb
CHANGED
@@ -19,7 +19,7 @@ class MPFR_TCBRT < Test::Unit::TestCase
|
|
19
19
|
return 0 if exp < 0
|
20
20
|
f.to_s[2..(index_e-1)][0,exp]
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def special
|
24
24
|
x = @nan.cbrt(GMP::GMP_RNDN)
|
25
25
|
assert_true(x.nan?, "@nan.cbrt should be NaN")
|
@@ -69,12 +69,12 @@ class MPFR_TCBRT < Test::Unit::TestCase
|
|
69
69
|
y = GMP::F("1.0111E-1", 5, 2)
|
70
70
|
assert_equal(y, x, "cbrt should be correct")
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
def test_cbrt
|
74
74
|
special
|
75
75
|
|
76
76
|
(2..100).each do |p|
|
77
|
-
|
77
|
+
RND_MODES.each do |rnd|
|
78
78
|
x = GMP::F(1).cbrt(rnd)
|
79
79
|
assert_equal(GMP::F(1), x, "1.cbrt should be 1 (prec #{p}) in rounding mode #{rnd}")
|
80
80
|
x = GMP::F(-1).cbrt(rnd)
|
data/test/mpfr_tconst_euler.rb
CHANGED
@@ -1,18 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
2
|
|
3
3
|
class MPFR_TCONST_EULER < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@rand_state = GMP::RandState.new
|
6
|
-
|
7
|
-
if GMP::MPFR_VERSION >= "3.0.0"
|
8
|
-
@rnd_modes = [GMP::MPFR_RNDN, GMP::MPFR_RNDZ, GMP::MPFR_RNDU, GMP::MPFR_RNDD, GMP::MPFR_RNDA]
|
9
|
-
@mpfr_rnd_max = 5
|
10
|
-
else
|
11
|
-
@rnd_modes = [GMP::GMP_RNDN, GMP::GMP_RNDZ, GMP::GMP_RNDU, GMP::GMP_RNDD]
|
12
|
-
@mpfr_rnd_max = 4
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
4
|
def test_const_euler
|
17
5
|
prec = 53
|
18
6
|
|
@@ -20,20 +8,23 @@ class MPFR_TCONST_EULER < Test::Unit::TestCase
|
|
20
8
|
z = GMP::F("0.10010011110001000110011111100011", 32, 2)
|
21
9
|
assert_equal(z, y, "Const Euler to precision 32 should be accurate.")
|
22
10
|
|
23
|
-
(2..200).each do |
|
24
|
-
|
25
|
-
t = GMP::F(0, p)
|
26
|
-
yprec = p+10
|
11
|
+
(2..200).each do |prec|
|
12
|
+
yprec = prec + 10
|
27
13
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
14
|
+
(RND_MODES).each do |rnd|
|
15
|
+
y = GMP::F.const_euler(rnd, yprec)
|
16
|
+
err = rnd == GMP::GMP_RNDN ? yprec+1 : yprec
|
17
|
+
|
18
|
+
if y.can_round?(err, rnd, rnd, prec)
|
19
|
+
t = GMP::F(y, prec, rnd)
|
20
|
+
z = GMP::F.const_euler(rnd, prec)
|
21
|
+
assert_equal(t, z, "const_euler should be equal at prec=#{prec}, rnd_mode=#{rnd.inspect}")
|
22
|
+
end
|
36
23
|
end
|
37
24
|
end
|
38
25
|
end
|
26
|
+
|
27
|
+
def test_bad_prec
|
28
|
+
assert_raise(TypeError) { GMP::F.const_euler(GMP::GMP_RNDN, "not a precision") }
|
29
|
+
end
|
39
30
|
end
|
data/test/mpfr_tfac.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
|
+
|
3
|
+
class MPFR_TFAC < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@one = GMP::F(1)
|
6
|
+
@zero = GMP::F(0)
|
7
|
+
@inf = @one/@zero
|
8
|
+
@nan = @inf - @inf
|
9
|
+
@neg_one = GMP::F(-1)
|
10
|
+
@neg_inf = @neg_one/@zero
|
11
|
+
@neg_zero = GMP::F("-0")
|
12
|
+
@rand_state = GMP::RandState.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def special
|
16
|
+
x = GMP::F.fac(119, GMP::GMP_RNDZ, 21)
|
17
|
+
y = GMP::F("0.101111101110100110110E654", 21, 2)
|
18
|
+
assert_equal(y, x, "fac should be correct")
|
19
|
+
|
20
|
+
x = GMP::F("0.110111100001000001101010010001000111000100000100111000010011100011011111001100011110101000111101101100110001001100110100001001111110000101010000100100011100010011101110000001000010001100010000101001111E6250", 206, 2)
|
21
|
+
y = GMP::F.fac(767, GMP::GMP_RNDN, 206)
|
22
|
+
end
|
23
|
+
|
24
|
+
def int
|
25
|
+
f = GMP::Z.fac(0)
|
26
|
+
(1..80).each do |n|
|
27
|
+
f = f * n
|
28
|
+
prec = f.size_in_base(2) - f.scan1(0)
|
29
|
+
(GMP::MPFR_PREC_MIN..prec).each do |p|
|
30
|
+
RND_MODES.each do |rnd|
|
31
|
+
x = GMP::F.fac(n, rnd, p)
|
32
|
+
y = GMP::F.new(f, p, rnd)
|
33
|
+
assert_equal(y, x, "fac should be correct for integers")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_fac
|
40
|
+
special
|
41
|
+
|
42
|
+
int
|
43
|
+
|
44
|
+
assert_equal(1, GMP::F.fac(0), "fac(0) should give 1")
|
45
|
+
|
46
|
+
# There are more tests in tfactorial.c, but they rely on return values and
|
47
|
+
# mpfr_can_round... so not yet.
|
48
|
+
end
|
49
|
+
end
|
data/test/mpfr_tfrexp.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
|
+
|
3
|
+
class MPFR_TFrexp < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
end
|
6
|
+
|
7
|
+
def special
|
8
|
+
exp, y = GMP::F.nan.frexp
|
9
|
+
assert_true(y.nan?, "frexp of NaN should be correct")
|
10
|
+
|
11
|
+
exp, y = GMP::F.inf.frexp
|
12
|
+
assert_true(y.infinite? && y > 0, "frexp of Inf should be correct")
|
13
|
+
|
14
|
+
exp, y = GMP::F.inf(-1).frexp
|
15
|
+
assert_true(y.infinite? && y < 0, "frexp of -Inf should be correct")
|
16
|
+
|
17
|
+
exp, y = GMP::F.zero.frexp
|
18
|
+
assert_equal(y, GMP::F.zero, "frexp of zero should be correct")
|
19
|
+
|
20
|
+
exp, y = GMP::F.zero(-1).frexp
|
21
|
+
assert_equal(y, GMP::F.zero(-1), "frexp of -zero should be correct")
|
22
|
+
|
23
|
+
exp, y = GMP::F(17).frexp
|
24
|
+
assert_equal(exp, 5, "frexp of 17 should return exp of 5")
|
25
|
+
assert_equal(y, GMP::F("0.53125"), "frexp of 17 should return exp of 5")
|
26
|
+
|
27
|
+
exp, y = GMP::F(17).frexp(GMP::GMP_RNDN, 4)
|
28
|
+
assert_equal(exp, 5, "frexp of 17 should return exp of 5")
|
29
|
+
assert_equal(y, GMP::F("0.5", 4), "frexp of 17 should return exp of 5")
|
30
|
+
|
31
|
+
exp, y = GMP::F(17).frexp(GMP::GMP_RNDZ, 4)
|
32
|
+
assert_equal(exp, 5, "frexp of 17 should return exp of 5")
|
33
|
+
assert_equal(y, GMP::F("0.5", 4), "frexp of 17 should return exp of 5")
|
34
|
+
|
35
|
+
exp, y = GMP::F(17).frexp(GMP::GMP_RNDD, 4)
|
36
|
+
assert_equal(exp, 5, "frexp of 17 should return exp of 5")
|
37
|
+
assert_equal(y, GMP::F("0.5", 4), "frexp of 17 should return exp of 5")
|
38
|
+
|
39
|
+
exp, y = GMP::F(17).frexp(GMP::GMP_RNDU, 4)
|
40
|
+
assert_equal(exp, 5, "frexp of 17 should return exp of 5")
|
41
|
+
assert_equal(y, GMP::F("0.562", 4), "frexp of 17 should return exp of 5")
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_fac
|
45
|
+
special
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
|
+
|
3
|
+
class TC_f_abs_neg < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@a=GMP::F.new(3.14)
|
6
|
+
@b=GMP::F.new()
|
7
|
+
@c=GMP::F.new(-3.14)
|
8
|
+
@d=GMP::F.new(3.14)
|
9
|
+
@e=GMP::F.new()
|
10
|
+
@f=GMP::F.new(-3.14)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_neg
|
14
|
+
assert_equal(-@a, @c, "-(x : GMP::Z) should be calculated correctly.")
|
15
|
+
assert_equal(-@c, @a, "-(x : GMP::Z) should be calculated correctly.")
|
16
|
+
assert_equal(-@b, @b, "-GMP::Z.new() should equal GMP::Z.new().")
|
17
|
+
@d.neg!; @e.neg!; @f.neg!
|
18
|
+
assert_equal(@d, @c, "(x : GMP::Z).neg! should be calculated correctly.")
|
19
|
+
assert_equal(@e, @b, "(x : GMP::Z).neg! should be calculated correctly.")
|
20
|
+
assert_equal(@f, @a, "GMP::Z.new().neg! should equal GMP::Z.new().")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_abs
|
24
|
+
assert_equal([@a, 0, @a], [@a.abs, @b.abs, @c.abs], "(x : GMP::Z).abs should be calculated correctly.")
|
25
|
+
@a.abs!; @b.abs!; @c.abs!
|
26
|
+
assert_equal([@a, 0, @a], [@a, @b, @c], "(x : GMP::Z).abs! should be calculated correctly.")
|
27
|
+
end
|
28
|
+
end
|
data/test/tc_f_to_s.rb
CHANGED
@@ -10,7 +10,6 @@ class TC_F_to_s < Test::Unit::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_to_s_default_prec
|
13
|
-
return if not GMP.const_defined? :MPFR_VERSION # I might be able to add this one back in...
|
14
13
|
rs = GMP::RandState.new(11213)
|
15
14
|
if GMP.const_defined? :MPFR_VERSION
|
16
15
|
strings = [
|
@@ -26,7 +25,7 @@ class TC_F_to_s < Test::Unit::TestCase
|
|
26
25
|
]
|
27
26
|
end
|
28
27
|
# In this test, each numerator, n, and denominator, d, pair is generated in
|
29
|
-
# succession from
|
28
|
+
# succession from rs. Each pair is used to create a floating point number.
|
30
29
|
# The first pair are uniformly distributed random integers between 0 and
|
31
30
|
# 2^100 - 1. The next two are distributed between 0 and 2^110 - 1. The last
|
32
31
|
# are distributed between 0 and 2^190 - 1.
|
@@ -59,20 +58,35 @@ class TC_F_to_s < Test::Unit::TestCase
|
|
59
58
|
end
|
60
59
|
|
61
60
|
def test_different_bases
|
62
|
-
return if not GMP.const_defined? :MPFR_VERSION
|
63
61
|
f = GMP::F(0.5)
|
64
|
-
assert_equal("0.50000000000000000e+0", f.to_s)
|
65
|
-
assert_equal("0.10000000000000000000000000000000000000000000000000000e+0", f.to_s(2))
|
66
|
-
assert_equal("0.10000000000000000000000000000000000000000000000000000e+0", f.to_s(:bin))
|
67
|
-
assert_equal("0.11111111111111111111111111111111112e+0", f.to_s(3))
|
68
|
-
assert_equal("0.200000000000000000000000000e+0", f.to_s(4))
|
69
|
-
assert_equal("0.50000000000000000e+0", f.inspect)
|
70
|
-
|
71
62
|
g = GMP::F(0.8)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
63
|
+
|
64
|
+
if GMP.const_defined? :MPFR_VERSION
|
65
|
+
assert_equal("0.50000000000000000e+0", f.to_s)
|
66
|
+
assert_equal("0.10000000000000000000000000000000000000000000000000000e+0", f.to_s(2))
|
67
|
+
assert_equal("0.10000000000000000000000000000000000000000000000000000e+0", f.to_s(:bin))
|
68
|
+
assert_equal("0.11111111111111111111111111111111112e+0", f.to_s(3))
|
69
|
+
assert_equal("0.200000000000000000000000000e+0", f.to_s(4))
|
70
|
+
assert_equal("0.50000000000000000e+0", f.inspect)
|
71
|
+
|
72
|
+
assert_equal("0.80000000000000004e+0", g.to_s)
|
73
|
+
assert_equal("0.21012101210121012101210121012101220e+0", g.to_s(3))
|
74
|
+
assert_equal("0.400000000000000000000003e+0", g.to_s(5))
|
75
|
+
assert_equal("0.k00000000002ge+0", g.to_s(25))
|
76
|
+
assert_equal("0.80000000000000004e+0", g.inspect)
|
77
|
+
else
|
78
|
+
assert_equal("0.5e+0", f.to_s)
|
79
|
+
assert_equal("0.1e+0", f.to_s(2))
|
80
|
+
assert_equal("0.1e+0", f.to_s(:bin))
|
81
|
+
assert_equal("0.111111111111111111111111111111111111111111e+0", f.to_s(3))
|
82
|
+
assert_equal("0.2e+0", f.to_s(4))
|
83
|
+
assert_equal("0.5e+0", f.inspect)
|
84
|
+
|
85
|
+
assert_equal("0.800000000000000044409e+0", g.to_s)
|
86
|
+
assert_equal("0.21012101210121012101210121012101212211012e+0", g.to_s(3))
|
87
|
+
assert_equal("0.40000000000000000000000231042e+0", g.to_s(5))
|
88
|
+
assert_equal("0.k00000000002g49e+0", g.to_s(25))
|
89
|
+
assert_equal("0.800000000000000044409e+0", g.inspect)
|
90
|
+
end
|
77
91
|
end
|
78
92
|
end
|
data/test/tc_mpfr_cmp.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
|
+
|
3
|
+
class TC_MPFR_Cmp < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@neg_inf = GMP::F(0).log # -Inf
|
6
|
+
@inf = -@neg_inf # Inf
|
7
|
+
@nan = @neg_inf + @inf # NaN
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_mpfr_lessgreater
|
11
|
+
assert_true(GMP::F(5).lessgreater?(GMP::F(12)), "lessgreater? should work")
|
12
|
+
assert_true(GMP::F(5).lessgreater?(@inf), "lessgreater? should work")
|
13
|
+
assert_false(GMP::F(5).lessgreater?(@nan), "lessgreater? should work")
|
14
|
+
assert_false(@nan.lessgreater?(@nan), "lessgreater? should work")
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_mpfr_lessgreater_types
|
18
|
+
assert_raise(TypeError) { GMP::F(5).lessgreater? 3.14 }
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_mpfr_unordered
|
22
|
+
assert_true(@nan.unordered?(GMP::F(5)), "unordered? should work")
|
23
|
+
assert_false(@neg_inf.unordered?(GMP::F(5)), "unordered? should work")
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_mpfr_unordered_types
|
27
|
+
assert_raise(TypeError) { GMP::F(5).unordered? 3.14 }
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
|
+
|
3
|
+
class TC_MPFR_Inf_Nan_Zero < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@neg_inf = GMP::F(0).log # -Inf
|
6
|
+
@inf = -@neg_inf # Inf
|
7
|
+
@nan = @neg_inf + @inf # NaN
|
8
|
+
@zero = GMP::F(0)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_nan
|
12
|
+
assert_equal(@nan, GMP::F.nan, "NaN should be NaN")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_inf
|
16
|
+
assert_equal(@inf, GMP::F.inf, "inf should be inf")
|
17
|
+
assert_equal(@neg_inf, GMP::F.inf(-1), "neg_inf should be neg_inf")
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_zero
|
21
|
+
assert_equal(@zero, GMP::F.zero, "zero should be zero")
|
22
|
+
assert_equal(-@zero, GMP::F.zero(-1), "negaitve zero should be negative zero")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_type
|
26
|
+
assert_raise(TypeError) { GMP::F.inf(0.5); }
|
27
|
+
assert_raise(TypeError) { GMP::F.zero(0.5); }
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
|
+
|
3
|
+
class TC_MPFR_New_Rounding < Test::Unit::TestCase
|
4
|
+
def test_new_fixnum
|
5
|
+
ninety_six = GMP::F(96, 4)
|
6
|
+
one_hundred_four = GMP::F(104, 4)
|
7
|
+
|
8
|
+
a = GMP::F(100, 4)
|
9
|
+
assert_equal(a, ninety_six, "GMP::F.new should default round with RNDN")
|
10
|
+
|
11
|
+
a = GMP::F(100, 4, GMP::GMP_RNDN)
|
12
|
+
assert_equal(a, ninety_six, "GMP::F.new should round with RNDN")
|
13
|
+
|
14
|
+
a = GMP::F(100, 4, GMP::GMP_RNDD)
|
15
|
+
assert_equal(a, ninety_six, "GMP::F.new should round with RNDD")
|
16
|
+
|
17
|
+
a = GMP::F(100, 4, GMP::GMP_RNDZ)
|
18
|
+
assert_equal(a, ninety_six, "GMP::F.new should round with RNDZ")
|
19
|
+
|
20
|
+
a = GMP::F(100, 4, GMP::GMP_RNDU)
|
21
|
+
assert_equal(a, one_hundred_four, "GMP::F.new should round with RNDU")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_new_bignum
|
25
|
+
over = GMP::F(0.36472996384e+20, 32)
|
26
|
+
under = GMP::F(0.36472996375e+20, 32)
|
27
|
+
|
28
|
+
a = GMP::F(3**41, 32)
|
29
|
+
assert_equal(a, under, "GMP::F.new should default round with RNDN")
|
30
|
+
|
31
|
+
a = GMP::F(3**41, 32, GMP::GMP_RNDN)
|
32
|
+
assert_equal(a, under, "GMP::F.new should round with RNDN")
|
33
|
+
|
34
|
+
a = GMP::F(3**41, 32, GMP::GMP_RNDD)
|
35
|
+
assert_equal(a, under, "GMP::F.new should round with RNDD")
|
36
|
+
|
37
|
+
a = GMP::F(3**41, 32, GMP::GMP_RNDZ)
|
38
|
+
assert_equal(a, under, "GMP::F.new should round with RNDZ")
|
39
|
+
|
40
|
+
a = GMP::F(3**41, 32, GMP::GMP_RNDU)
|
41
|
+
assert_equal(a, over, "GMP::F.new should round with RNDU")
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_new_gmpz
|
45
|
+
z100 = GMP::Z(100)
|
46
|
+
ninety_six = GMP::F(96, 4)
|
47
|
+
one_hundred_four = GMP::F(104, 4)
|
48
|
+
|
49
|
+
a = GMP::F(z100, 4)
|
50
|
+
assert_equal(a, ninety_six, "GMP::F.new should default round with RNDN")
|
51
|
+
|
52
|
+
a = GMP::F(z100, 4, GMP::GMP_RNDN)
|
53
|
+
assert_equal(a, ninety_six, "GMP::F.new should round with RNDN")
|
54
|
+
|
55
|
+
a = GMP::F(z100, 4, GMP::GMP_RNDD)
|
56
|
+
assert_equal(a, ninety_six, "GMP::F.new should round with RNDD")
|
57
|
+
|
58
|
+
a = GMP::F(z100, 4, GMP::GMP_RNDZ)
|
59
|
+
assert_equal(a, ninety_six, "GMP::F.new should round with RNDZ")
|
60
|
+
|
61
|
+
a = GMP::F(z100, 4, GMP::GMP_RNDU)
|
62
|
+
assert_equal(a, one_hundred_four, "GMP::F.new should round with RNDU")
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_new_gmpq
|
66
|
+
pi = GMP::Q(22,7)
|
67
|
+
below = GMP::F(0.3141e+1, 8)
|
68
|
+
above = GMP::F(0.3156e+1, 8)
|
69
|
+
|
70
|
+
a = GMP::F(pi, 8)
|
71
|
+
assert_equal(a, below, "GMP::F.new should default round with RNDN")
|
72
|
+
|
73
|
+
a = GMP::F(pi, 8, GMP::GMP_RNDN)
|
74
|
+
assert_equal(a, below, "GMP::F.new should round with RNDN")
|
75
|
+
|
76
|
+
a = GMP::F(pi, 8, GMP::GMP_RNDD)
|
77
|
+
assert_equal(a, below, "GMP::F.new should round with RNDD")
|
78
|
+
|
79
|
+
a = GMP::F(pi, 8, GMP::GMP_RNDZ)
|
80
|
+
assert_equal(a, below, "GMP::F.new should round with RNDZ")
|
81
|
+
|
82
|
+
a = GMP::F(pi, 8, GMP::GMP_RNDU)
|
83
|
+
assert_equal(a, above, "GMP::F.new should round with RNDU")
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_new_float
|
87
|
+
ohoh977 = GMP::F(0.977e-2, 4)
|
88
|
+
oh107 = GMP::F(0.107e-1, 4)
|
89
|
+
|
90
|
+
a = GMP::F(0.01, 4)
|
91
|
+
assert_equal(a, ohoh977, "GMP::F.new should default round with RNDN")
|
92
|
+
|
93
|
+
a = GMP::F(0.01, 4, GMP::GMP_RNDN)
|
94
|
+
assert_equal(a, ohoh977, "GMP::F.new should round with RNDN")
|
95
|
+
|
96
|
+
a = GMP::F(0.01, 4, GMP::GMP_RNDD)
|
97
|
+
assert_equal(a, ohoh977, "GMP::F.new should round with RNDD")
|
98
|
+
|
99
|
+
a = GMP::F(0.01, 4, GMP::GMP_RNDZ)
|
100
|
+
assert_equal(a, ohoh977, "GMP::F.new should round with RNDZ")
|
101
|
+
|
102
|
+
a = GMP::F(0.01, 4, GMP::GMP_RNDU)
|
103
|
+
assert_equal(a, oh107, "GMP::F.new should round with RNDU")
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_new_mpfr
|
107
|
+
ohoh977 = GMP::F(-0.977e-2, 4)
|
108
|
+
oh107 = GMP::F(-0.107e-1, 4)
|
109
|
+
one_hundredth = GMP::F(-0.01)
|
110
|
+
|
111
|
+
a = GMP::F(one_hundredth, 4)
|
112
|
+
assert_equal(a, ohoh977, "GMP::F.new should default round with RNDN")
|
113
|
+
|
114
|
+
a = GMP::F(one_hundredth, 4, GMP::GMP_RNDN)
|
115
|
+
assert_equal(a, ohoh977, "GMP::F.new should round with RNDN")
|
116
|
+
|
117
|
+
a = GMP::F(one_hundredth, 4, GMP::GMP_RNDD)
|
118
|
+
assert_equal(a, oh107, "GMP::F.new should round with RNDD")
|
119
|
+
|
120
|
+
a = GMP::F(one_hundredth, 4, GMP::GMP_RNDZ)
|
121
|
+
assert_equal(a, ohoh977, "GMP::F.new should round with RNDZ")
|
122
|
+
|
123
|
+
a = GMP::F(one_hundredth, 4, GMP::GMP_RNDU)
|
124
|
+
assert_equal(a, ohoh977, "GMP::F.new should round with RNDU")
|
125
|
+
end
|
126
|
+
end
|