gmp 0.4.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/CHANGELOG +109 -0
  2. data/INSTALL +4 -0
  3. data/README.rdoc +357 -0
  4. data/benchmark/COPYING +674 -0
  5. data/benchmark/README +75 -0
  6. data/benchmark/divide +34 -0
  7. data/benchmark/gcd +38 -0
  8. data/benchmark/gexpr +0 -0
  9. data/benchmark/gexpr.c +359 -0
  10. data/benchmark/multiply +44 -0
  11. data/benchmark/rsa +93 -0
  12. data/benchmark/runbench +147 -0
  13. data/benchmark/version +1 -0
  14. data/ext/extconf.rb +30 -0
  15. data/ext/gmp.c +197 -0
  16. data/ext/gmpbench_timing.c +80 -0
  17. data/ext/gmpf.c +595 -0
  18. data/ext/gmpf.h +144 -0
  19. data/ext/gmpq.c +780 -0
  20. data/ext/gmpq.h +12 -0
  21. data/ext/gmprandstate.c +224 -0
  22. data/ext/gmpz.c +1968 -0
  23. data/ext/gmpz.h +20 -0
  24. data/ext/libgmp-10.dll +0 -0
  25. data/ext/ruby_gmp.h +243 -0
  26. data/ext/takeover.h +36 -0
  27. data/manual.pdf +0 -0
  28. data/manual.tex +804 -0
  29. data/test/README +34 -0
  30. data/test/tc_cmp.rb +74 -0
  31. data/test/tc_division.rb +109 -0
  32. data/test/tc_f_arithmetics_coersion.rb +71 -0
  33. data/test/tc_f_precision.rb +48 -0
  34. data/test/tc_fib_fac_nextprime.rb +51 -0
  35. data/test/tc_floor_ceil_truncate.rb +21 -0
  36. data/test/tc_logical_roots.rb +48 -0
  37. data/test/tc_q.rb +27 -0
  38. data/test/tc_q_basic.rb +41 -0
  39. data/test/tc_random.rb +54 -0
  40. data/test/tc_sgn_neg_abs.rb +47 -0
  41. data/test/tc_swap.rb +19 -0
  42. data/test/tc_z.rb +71 -0
  43. data/test/tc_z_basic.rb +35 -0
  44. data/test/tc_z_exponentiation.rb +22 -0
  45. data/test/tc_z_gcd_lcm_invert.rb +57 -0
  46. data/test/tc_z_jac_leg_rem.rb +73 -0
  47. data/test/tc_z_logic.rb +54 -0
  48. data/test/tc_z_shifts_last_bits.rb +22 -0
  49. data/test/tc_z_to_d_to_i.rb +24 -0
  50. data/test/tc_zerodivisionexceptions.rb +17 -0
  51. data/test/test-12.rb +14 -0
  52. data/test/test-19.rb +13 -0
  53. data/test/test-20.rb +29 -0
  54. data/test/test-21.rb +37 -0
  55. data/test/test-22.rb +12 -0
  56. data/test/test-23.rb +11 -0
  57. data/test/test_helper.rb +8 -0
  58. data/test/unit_tests.rb +39 -0
  59. metadata +115 -0
@@ -0,0 +1,34 @@
1
+ Tests:
2
+ 1* initializations and to_s
3
+ 2* basic integer arithmetics and coersion to Z
4
+ 3* integer logical operators
5
+ 4* comparisions between Z, Q, FixNum and BigNum
6
+ 5* basic rational arithmetics and coersion to Q
7
+ 6 bit operations, scan0, scan1
8
+ 7* exponentiation and exponentiation modulo
9
+ 8* divide by zero exceptions
10
+ 9* sgn, neg, abs
11
+ 10* fibonacci, factorial, nextprime
12
+ 11* swap
13
+ 12* floor, ceil, truncate
14
+ 13* to_i, to_d
15
+ 14* shifts, last_bits
16
+ 15* logical tests, roots
17
+ 16* floating point init with and without explicit precision
18
+ 17* basic floating point arithmetics and coersion to F
19
+ 18* default_prec and default_prec=
20
+ 19* integer division methods
21
+ 20 mpfr - exp and log
22
+ 21 mpfr - trigonometry
23
+ 22 mpfr - type tests
24
+ 23 mpfr - sqrt and power
25
+ 24* jacobi, legendre, remove
26
+ 25* gcd, gcdext, lcm, invert
27
+ TODO:
28
+ gcd, lcm
29
+ cmpabs
30
+ integer and integer->rational division, modulo
31
+ more number theoretic functions
32
+ random numbers
33
+ range errors
34
+ full coverage?
@@ -0,0 +1,74 @@
1
+ require 'test_helper'
2
+
3
+ class TC_Cmp < Test::Unit::TestCase
4
+ def setup
5
+ @a=GMP::Z.new(180)
6
+ @c=GMP::Q.new(2000,11) # ~181.82
7
+ @d=GMP::Q.new(3000,17) # ~176.47
8
+ @e=700
9
+ @f=2**32
10
+ @g=GMP::Q(360,2)
11
+ end
12
+
13
+ def test_cmp_q_q
14
+ assert_equal(@c > @d, true, "GMP::Q should compare correctly")
15
+ assert_equal(@c >= @d, true, "GMP::Q should compare correctly")
16
+ assert_equal(@c < @d, false, "GMP::Q should compare correctly")
17
+ assert_equal(@c <= @d, false, "GMP::Q should compare correctly")
18
+ assert_equal(@c == @d, false, "GMP::Q should == correctly")
19
+ assert_equal(@c == @c, true, "GMP::Q should == correctly")
20
+ assert_equal(@c != @d, true, "GMP::Q should != correctly")
21
+ assert_equal(@c != @c, false, "GMP::Q should != correctly")
22
+
23
+ assert_equal(@c <=> @d, 1, "GMP::Q should <=> correctly")
24
+ assert_equal(@c <=> @c, 0, "GMP::Q should <=> correctly")
25
+ assert_equal(@d <=> @c, -1, "GMP::Q should <=> correctly")
26
+ end
27
+
28
+ def test_cmp_q_z
29
+ assert_equal(@c > @a, true, "GMP::Q should compare correctly with GMP::Z")
30
+ assert_equal(@c >= @a, true, "GMP::Q should compare correctly with GMP::Z")
31
+ assert_equal(@c < @a, false, "GMP::Q should compare correctly with GMP::Z")
32
+ assert_equal(@c <= @a, false, "GMP::Q should compare correctly with GMP::Z")
33
+ assert_equal(@c == @a, false, "GMP::Q should == correctly with GMP::Z")
34
+ assert_equal(@c != @a, true, "GMP::Q should != correctly with GMP::Z")
35
+
36
+ assert_equal(@a < @c, true, "GMP::Z should compare correctly with GMP::Q")
37
+ assert_equal(@a <= @c, true, "GMP::Z should compare correctly with GMP::Q")
38
+ assert_equal(@a > @c, false, "GMP::Z should compare correctly with GMP::Q")
39
+ assert_equal(@a >= @c, false, "GMP::Z should compare correctly with GMP::Q")
40
+ assert_equal(@a == @c, false, "GMP::Z should == correctly with GMP::Q")
41
+ assert_equal(@a != @c, true, "GMP::Z should != correctly with GMP::Q")
42
+
43
+ assert_equal(@g == @a, true, "GMP::Q should == correctly with GMP::Z")
44
+ assert_equal(@g != @a, false, "GMP::Q should != correctly with GMP::Z")
45
+
46
+ assert_equal(@d > @a, false, "GMP::Q should compare correctly with GMP::Z")
47
+ assert_equal(@d >= @a, false, "GMP::Q should compare correctly with GMP::Z")
48
+ assert_equal(@d < @a, true, "GMP::Q should compare correctly with GMP::Z")
49
+ assert_equal(@d <= @a, true, "GMP::Q should compare correctly with GMP::Z")
50
+
51
+ assert_equal(@a < @d, false, "GMP::Z should compare correctly with GMP::Q")
52
+ assert_equal(@a <= @d, false, "GMP::Z should compare correctly with GMP::Q")
53
+ assert_equal(@a > @d, true, "GMP::Z should compare correctly with GMP::Q")
54
+ assert_equal(@a >= @d, true, "GMP::Z should compare correctly with GMP::Q")
55
+
56
+ assert_equal(@c <=> @a, 1, "GMP::Q should <=> correctly with GMP::Z")
57
+ assert_equal(@g <=> @a, 0, "GMP::Q should <=> correctly with GMP::Z")
58
+ assert_equal(@a <=> @c, -1, "GMP::Q should <=> correctly with GMP::Z")
59
+ end
60
+
61
+ def test_cmp_z_int
62
+ assert_equal(@a <=> @e, -1, "GMP::Z should <=> correctly with Fixnum")
63
+ assert_equal(@e <=> @a, 1, "Fixnum should <=> correctly with GMP::Z")
64
+ assert_equal(@a <=> @f, -1, "GMP::Z should <=> correctly with Bignum")
65
+ assert_equal(@f <=> @a, 1, "Bignum should <=> correctly with GMP::Z")
66
+ end
67
+
68
+ def test_cmp_q_int
69
+ assert_equal(@c <=> @e, -1, "GMP::Q should <=> correctly with Fixnum")
70
+ assert_equal(@e <=> @c, 1, "Fixnum should <=> correctly with GMP::Q")
71
+ assert_equal(@c <=> @f, -1, "GMP::Q should <=> correctly with Bignum")
72
+ assert_equal(@f <=> @c, 1, "Bignum should <=> correctly with GMP::Q")
73
+ end
74
+ end
@@ -0,0 +1,109 @@
1
+ require 'test_helper'
2
+
3
+ class TC_division < Test::Unit::TestCase
4
+ def setup
5
+ @a = GMP::Z.new(5)
6
+ @b = GMP::Z.new(7)
7
+ @c = GMP::Z.new(25)
8
+ @d = GMP::Q.new(3,11)
9
+ @e = GMP::F.new(3.14)
10
+ @f = 2**32
11
+ end
12
+
13
+ def test_z_div
14
+ assert_equal(GMP::Q, (@a / @b ).class, "GMP::Z / GMP::Z should be GMP::Q.")
15
+ assert_equal(GMP::Q, (@a / 3 ).class, "GMP::Z / Fixnum should be GMP::Q.")
16
+ assert_equal(GMP::Q, (@a / 2**32).class, "GMP::Z / Bignum should be GMP::Q.")
17
+ assert_equal(GMP::Q, (@a / @c ).class, "GMP::Z / GMP::Z should be GMP::Q.")
18
+ assert_in_delta(0.7142857142, @a / @b, 1e-7, "GMP::Z./ should work.")
19
+ assert_in_delta(1.4 , @b / @a, 1e-7, "GMP::Z./ should work.")
20
+ assert_in_delta(1.6666666667, @a / 3, 1e-7, "GMP::Z./ should work.")
21
+ assert_in_delta(0.6 , 3 / @a, 1e-7, "GMP::Z./ should work.")
22
+ assert_in_delta(0.2 , @a / @c, 1e-7, "GMP::Z./ should work.")
23
+ assert_in_delta(5.0 , @c / @a, 1e-7, "GMP::Z./ should work.")
24
+ end
25
+
26
+ def test_z_tdiv
27
+ assert_equal(GMP::Z, @a.tdiv(@b).class, "GMP::Z.tdiv GMP::Z should be GMP::Z.")
28
+ assert_equal(GMP::Z, @a.tdiv(3).class, "GMP::Z.tdiv Fixnum should be GMP::Z.")
29
+ assert_equal(GMP::Z, @a.tdiv(2**32).class, "GMP::Z.tdiv Bignum should be GMP::Z.")
30
+ assert_equal(GMP::Z, @a.tdiv(@c).class, "GMP::Z.tdiv GMP::Z should be GMP::Z.")
31
+ assert_equal(0, @a.tdiv(@b), "GMP::Z.tdiv should work.")
32
+ assert_equal(1, @b.tdiv(@a), "GMP::Z.tdiv should work.")
33
+ assert_equal(1, @a.tdiv( 3), "GMP::Z.tdiv should work.")
34
+ assert_equal(0, @a.tdiv(@c), "GMP::Z.tdiv should work.")
35
+ assert_equal(5, @c.tdiv(@a), "GMP::Z.tdiv should work.")
36
+ end
37
+
38
+ def test_z_fdiv
39
+ assert_equal(GMP::Z, @a.fdiv(@b).class, "GMP::Z.fdiv GMP::Z should be GMP::Z.")
40
+ assert_equal(GMP::Z, @a.fdiv(3).class, "GMP::Z.fdiv Fixnum should be GMP::Z.")
41
+ assert_equal(GMP::Z, @a.fdiv(2**32).class, "GMP::Z.fdiv Bignum should be GMP::Z.")
42
+ assert_equal(0, @a.fdiv(@b), "GMP::Z.fdiv should work.")
43
+ assert_equal(1, @b.fdiv(@a), "GMP::Z.fdiv should work.")
44
+ assert_equal(1, @a.fdiv( 3), "GMP::Z.fdiv should work.")
45
+ assert_equal(0, @a.fdiv(@c), "GMP::Z.fdiv should work.")
46
+ assert_equal(5, @c.fdiv(@a), "GMP::Z.fdiv should work.")
47
+ end
48
+
49
+ def test_z_cdiv
50
+ assert_equal(GMP::Z, @a.cdiv(@b).class, "GMP::Z.cdiv GMP::Z should be GMP::Z.")
51
+ assert_equal(GMP::Z, @a.cdiv(3).class, "GMP::Z.cdiv Fixnum should be GMP::Z.")
52
+ assert_equal(GMP::Z, @a.cdiv(2**32).class, "GMP::Z.cdiv Bignum should be GMP::Z.")
53
+ assert_equal(1, @a.cdiv(@b), "GMP::Z.cdiv should work.")
54
+ assert_equal(2, @b.cdiv(@a), "GMP::Z.cdiv should work.")
55
+ assert_equal(2, @a.cdiv( 3), "GMP::Z.cdiv should work.")
56
+ assert_equal(1, @a.cdiv(@c), "GMP::Z.cdiv should work.")
57
+ assert_equal(5, @c.cdiv(@a), "GMP::Z.cdiv should work.")
58
+ end
59
+
60
+ def test_z_tmod
61
+ assert_equal(GMP::Z, @a.tmod(@b).class, "GMP::Z.tmod GMP::Z should be GMP::Z.")
62
+ assert_equal(GMP::Z, @a.tmod(3).class, "GMP::Z.tmod Fixnum should be GMP::Z.")
63
+ assert_equal(GMP::Z, @a.tmod(2**32).class, "GMP::Z.tmod Bignum should be GMP::Z.")
64
+ assert_equal(GMP::Z, @a.tmod(@c).class, "GMP::Z.tmod GMP::Z should be GMP::Z.")
65
+ assert_equal(5, @a.tmod(@b), "GMP::Z.tmod should work.")
66
+ assert_equal(2, @b.tmod(@a), "GMP::Z.tmod should work.")
67
+ assert_equal(2, @a.tmod( 3), "GMP::Z.tmod should work.")
68
+ assert_equal(5, @a.tmod(@c), "GMP::Z.tmod should work.")
69
+ assert_equal(0, @c.tmod(@a), "GMP::Z.tmod should work.")
70
+ end
71
+
72
+ def test_z_fmod
73
+ assert_equal(GMP::Z, @a.fmod(@b).class, "GMP::Z.fmod GMP::Z should be GMP::Z.")
74
+ assert_equal(GMP::Z, @a.fmod(3).class, "GMP::Z.fmod Fixnum should be GMP::Z.")
75
+ assert_equal(GMP::Z, @a.fmod(2**32).class, "GMP::Z.fmod Bignum should be GMP::Z.")
76
+ assert_equal(GMP::Z, @a.fmod(@c).class, "GMP::Z.fmod GMP::Z should be GMP::Z.")
77
+ assert_equal(5, @a.fmod(@b), "GMP::Z.fmod should work.")
78
+ assert_equal(2, @b.fmod(@a), "GMP::Z.fmod should work.")
79
+ assert_equal(2, @a.fmod( 3), "GMP::Z.fmod should work.")
80
+ assert_equal(5, @a.fmod(@c), "GMP::Z.fmod should work.")
81
+ assert_equal(0, @c.fmod(@a), "GMP::Z.fmod should work.")
82
+ end
83
+
84
+ def test_z_cmod
85
+ assert_equal(GMP::Z, @a.cmod(@b).class, "GMP::Z.cmod GMP::Z should be GMP::Z.")
86
+ assert_equal(GMP::Z, @a.cmod(3).class, "GMP::Z.cmod Fixnum should be GMP::Z.")
87
+ assert_equal(GMP::Z, @a.cmod(2**32).class, "GMP::Z.cmod Bignum should be GMP::Z.")
88
+ assert_equal(GMP::Z, @a.cmod(@c).class, "GMP::Z.cmod GMP::Z should be GMP::Z.")
89
+ assert_equal( -2, @a.cmod(@b), "GMP::Z.cmod should work.")
90
+ assert_equal( -3, @b.cmod(@a), "GMP::Z.cmod should work.")
91
+ assert_equal( -1, @a.cmod( 3), "GMP::Z.cmod should work.")
92
+ assert_equal(-20, @a.cmod(@c), "GMP::Z.cmod should work.")
93
+ assert_equal( 0, @c.cmod(@a), "GMP::Z.cmod should work.")
94
+ end
95
+
96
+ def test_z_mod
97
+ assert_equal(5, @a % @b, "GMP::Z should % GMP::Z correctly.")
98
+ assert_equal(2, @b % @a, "GMP::Z should % GMP::Z correctly.")
99
+ assert_equal(2, @b % 5, "GMP::Z should % Fixnum correctly.")
100
+ assert_equal(0, @b % @b, "GMP::Z should % to 0 correctly.")
101
+ assert_equal(0, @c % @a, "GMP::Z should % to 0 correctly.")
102
+ assert_equal(0, @f % @f, "GMP::Z should % Bignum correctly.")
103
+ assert_equal(0, 2*@f % @f, "GMP::Z should % Bignum correctly.")
104
+ assert_equal(5, (5*@f+5) % @f, "GMP::Z should % Bignum correctly.")
105
+ assert_raise(TypeError) { @a % 3.14 }
106
+ assert_raise(TypeError) { @a % GMP::Q(22,3) }
107
+ assert_raise(TypeError) { @a % GMP::F(3.14) }
108
+ end
109
+ end
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+
3
+ class TC_F_arithmetics_coersion < Test::Unit::TestCase
4
+ def setup
5
+ @a = GMP::F.new(3.14, 100)
6
+ @b = GMP::F.new(2.71, 200)
7
+ @c = GMP::Z(3)
8
+ @d = GMP::Q(7,2)
9
+ @e = 2**32
10
+ end
11
+
12
+ def test_add
13
+ assert_in_delta( 5.85, @a + @b, 1e-6)
14
+ assert_in_delta( 5.85, @b + @a, 1e-6)
15
+ assert_in_delta( 6.14, @a + @c, 1e-6)
16
+ assert_in_delta( 6.14, @c + @a, 1e-6)
17
+ assert_in_delta( 6.64, @a + @d, 1e-6)
18
+ assert_in_delta( 6.64, @d + @a, 1e-6)
19
+ assert_in_delta( 5.14, @a + 2, 1e-6)
20
+ assert_in_delta( 5.14, 2 + @a, 1e-6)
21
+ assert_in_delta(4294967299.14, @a + @e, 1e-6)
22
+ assert_in_delta(4294967299.14, @e + @a, 1e-6)
23
+ assert_in_delta( 7.65, @a + 4.51, 1e-6)
24
+ assert_in_delta( 7.65, 4.51 + @a, 1e-6)
25
+ end
26
+
27
+ def test_sub
28
+ assert_in_delta( 0.43, @a - @b, 1e-6)
29
+ assert_in_delta( -0.43, @b - @a, 1e-6)
30
+ assert_in_delta( 0.14, @a - @c, 1e-6)
31
+ assert_in_delta( -0.14, @c - @a, 1e-6)
32
+ assert_in_delta( -0.36, @a - @d, 1e-6)
33
+ assert_in_delta( 0.36, @d - @a, 1e-6)
34
+ assert_in_delta( 1.14, @a - 2, 1e-6)
35
+ assert_in_delta( -1.14, 2 - @a, 1e-6)
36
+ assert_in_delta(-4294967292.86, @a - @e, 1e-6)
37
+ assert_in_delta( 4294967292.86, @e - @a, 1e-6)
38
+ assert_in_delta( -1.37, @a - 4.51, 1e-6)
39
+ assert_in_delta( 1.37, 4.51 - @a, 1e-6)
40
+ end
41
+
42
+ def test_mul
43
+ assert_in_delta( 8.5094, @a * @b, 1e-6)
44
+ assert_in_delta( 8.5094, @b * @a, 1e-6)
45
+ assert_in_delta( 9.42 , @a * @c, 1e-6)
46
+ assert_in_delta( 9.42 , @c * @a, 1e-6)
47
+ assert_in_delta( 10.99 , @a * @d, 1e-6)
48
+ assert_in_delta( 10.99 , @d * @a, 1e-6)
49
+ assert_in_delta( 6.28 , @a * 2, 1e-6)
50
+ assert_in_delta( 6.28 , 2 * @a, 1e-6)
51
+ assert_in_delta(13486197309.44 , @a * @e, 1e-6)
52
+ assert_in_delta(13486197309.44 , @e * @a, 1e-6)
53
+ assert_in_delta( 14.1614, @a * 4.51, 1e-6)
54
+ assert_in_delta( 14.1614, 4.51 * @a, 1e-6)
55
+ end
56
+
57
+ def test_div
58
+ assert_in_delta( 1.1586715867, @a / @b, 1e-6)
59
+ assert_in_delta( 0.8630573248, @b / @a, 1e-6)
60
+ assert_in_delta( 1.0466666667, @a / @c, 1e-6)
61
+ assert_in_delta( 0.9554140127, @c / @a, 1e-6)
62
+ assert_in_delta( 0.8971428571, @a / @d, 1e-6)
63
+ assert_in_delta( 1.1146496815, @d / @a, 1e-6)
64
+ assert_in_delta( 1.57 , @a / 2, 1e-6)
65
+ assert_in_delta( 0.6369426752, 2 / @a, 1e-6)
66
+ assert_in_delta( 0.0000000007, @a / @e, 1e-6)
67
+ assert_in_delta( 1367823979.6178343949, @e / @a, 1e-6)
68
+ assert_in_delta( 0.6962305987, @a / 4.51, 1e-6)
69
+ assert_in_delta( 1.4363057325, 4.51 / @a, 1e-6)
70
+ end
71
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class TC_precision < Test::Unit::TestCase
4
+ def setup
5
+ @pi = GMP::F.new(3.14)
6
+ @seven_halves = GMP::F.new(GMP::Q.new(7,2), 1000)
7
+ end
8
+
9
+ def test_default_precision
10
+ assert_equal("0.e+0", GMP::F.new().to_s)
11
+ assert_equal(64, GMP::F.new().prec)
12
+ assert_equal("0.314000000000000012434e+1", @pi.to_s)
13
+ assert_equal(64, @pi.prec)
14
+ assert_equal("0.1e+1", GMP::F.new(1).to_s)
15
+ assert_equal(64, GMP::F.new(1).prec)
16
+ assert_equal("0.314e+1", GMP::F.new("3.14").to_s)
17
+ assert_equal(64, GMP::F.new("3.14").prec)
18
+ assert_equal("0.4294967296e+10", GMP::F.new(2**32).to_s)
19
+ assert_equal(64, GMP::F.new(2**32).prec)
20
+ assert_equal("0.3e+1", GMP::F.new(GMP::Z.new(3)).to_s)
21
+ assert_equal(64, GMP::F.new(GMP::Z.new(3)).prec)
22
+ assert_equal("0.35e+1", GMP::F.new(GMP::Q.new(7,2)).to_s)
23
+ assert_equal(64, GMP::F.new(GMP::Q.new(7,2)).prec)
24
+ assert_equal("0.314000000000000012434e+1", GMP::F.new(@pi).to_s)
25
+ assert_equal(64, GMP::F.new(@pi).prec)
26
+ end
27
+
28
+ def test_specific_precision
29
+ assert_equal("0.3140000000000000124344978758017532527446746826171875e+1", GMP::F.new(3.14, 1000).to_s)
30
+ assert_equal(1024, GMP::F.new(3.14, 1000).prec)
31
+ assert_equal("0.1e+1", GMP::F.new(1, 1000).to_s)
32
+ assert_equal(1024, GMP::F.new(1, 1000).prec)
33
+ assert_equal("0.314e+1", GMP::F.new("3.14", 1000).to_s)
34
+ assert_equal(1024, GMP::F.new("3.14", 1000).prec)
35
+ assert_equal("0.4294967296e+10", GMP::F.new(2**32, 1000).to_s)
36
+ assert_equal(1024, GMP::F.new(2**32, 1000).prec)
37
+ assert_equal("0.3e+1", GMP::F.new(GMP::Z.new(3), 1000).to_s)
38
+ assert_equal(1024, GMP::F.new(GMP::Z.new(3), 1000).prec)
39
+ assert_equal("0.35e+1", @seven_halves.to_s)
40
+ assert_equal(1024, @seven_halves.prec)
41
+ assert_equal("0.35e+1", GMP::F.new(@seven_halves).to_s)
42
+ assert_equal(1024, GMP::F.new(@seven_halves).prec)
43
+ assert_equal("0.3140000000000000124344978758017532527446746826171875e+1", GMP::F.new(@pi, 1000).to_s)
44
+ assert_equal(1024, GMP::F.new(@pi, 1000).prec)
45
+ assert_equal("0.35e+1", GMP::F.new(@seven_halves, 0).to_s)
46
+ assert_equal(64, GMP::F.new(@seven_halves, 0).prec)
47
+ end
48
+ end
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ class TC_fib_fac_nextprime < Test::Unit::TestCase
4
+ def setup
5
+ @z10 = GMP::Z.new(10)
6
+ @z7 = GMP::Z.new( 7)
7
+ @z8 = GMP::Z.new( 8)
8
+ @z11 = GMP::Z.new(11)
9
+ @z13 = GMP::Z.new(13)
10
+ @z17 = GMP::Z.new(17)
11
+ @z19 = GMP::Z.new(19)
12
+ end
13
+
14
+ def test_fib
15
+ assert_equal( 1, GMP::Z.fib( 1), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
16
+ assert_equal( 1, GMP::Z.fib( 2), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
17
+ assert_equal( 2, GMP::Z.fib( 3), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
18
+ assert_equal( 3, GMP::Z.fib( 4), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
19
+ assert_equal( 5, GMP::Z.fib( 5), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
20
+ assert_equal( 8, GMP::Z.fib( 6), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
21
+ assert_equal( 13, GMP::Z.fib( 7), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
22
+ assert_equal( 21, GMP::Z.fib( 8), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
23
+ assert_equal( 34, GMP::Z.fib( 9), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
24
+ assert_equal( 55, GMP::Z.fib( 10), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
25
+ assert_equal( 55, GMP::Z.fib(@z10), "GMP::Z::fib(x : GMP::Z) should be calculated correctly.")
26
+ assert_equal( 89, GMP::Z.fib( 11), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
27
+ assert_equal(144, GMP::Z.fib( 12), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
28
+ assert_equal(233, GMP::Z.fib( 13), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
29
+ assert_equal(377, GMP::Z.fib( 14), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
30
+ end
31
+
32
+ def test_fac
33
+ assert_equal( 1, GMP::Z.fac( 0), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
34
+ assert_equal( 1, GMP::Z.fac( 1), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
35
+ assert_equal( 2, GMP::Z.fac( 2), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
36
+ assert_equal( 6, GMP::Z.fac( 3), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
37
+ assert_equal( 24, GMP::Z.fac( 4), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
38
+ assert_equal( 120, GMP::Z.fac( 5), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
39
+ assert_equal( 720, GMP::Z.fac( 6), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
40
+ assert_equal(5040, GMP::Z.fac( 7), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
41
+ end
42
+
43
+ def test_nextprime
44
+ assert_equal(@z11, @z7.next_prime, "GMP::Z.nextprime should work.")
45
+ assert_equal(@z11, @z8.nextprime, "GMP::Z.nextprime should work.")
46
+ assert_equal(@z11, @z8.next_prime, "GMP::Z.nextprime should work.")
47
+ assert_equal(@z13, @z11.nextprime, "GMP::Z.nextprime should work.")
48
+ assert_equal(@z17, @z13.next_prime, "GMP::Z.nextprime should work.")
49
+ assert_equal(@z19, @z17.nextprime, "GMP::Z.nextprime should work.")
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class TC_floor_ceil_truncate < Test::Unit::TestCase
4
+ def setup
5
+ @a = GMP::Q.new(200,11)
6
+ @b = -@a
7
+ @c = GMP::Q.new(70,10)
8
+ end
9
+
10
+ def test_floor_ceil_truncate
11
+ assert_equal(@a.floor, 18, "GMP::Q should floor.")
12
+ assert_equal(@a.ceil, 19, "GMP::Q should ceil.")
13
+ assert_equal(@a.trunc, 18, "GMP::Q should truncate.")
14
+ assert_equal(@b.floor, -19, "GMP::Q (negative) should floor.")
15
+ assert_equal(@b.ceil, -18, "GMP::Q (negative) should ceil.")
16
+ assert_equal(@b.trunc, -18, "GMP::Q (negative) should truncate.")
17
+ assert_equal(@c.floor, 7, "GMP::Q (integer) should floor.")
18
+ assert_equal(@c.ceil, 7, "GMP::Q (integer) should ceil.")
19
+ assert_equal(@c.trunc, 7, "GMP::Q (integer) should truncate.")
20
+ end
21
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class TC_logical_roots < Test::Unit::TestCase
4
+ def setup
5
+ @a = GMP::Z.new(100)
6
+ @b = GMP::Z.new( 27)
7
+ @c = GMP::Z.new( 99)
8
+ end
9
+
10
+ def test_parity
11
+ assert @a.even?, "GMP::Z should even? correctly."
12
+ assert !@b.even?, "GMP::Z should even? correctly."
13
+ assert !@c.even?, "GMP::Z should even? correctly."
14
+ assert !@a.odd?, "GMP::Z should odd? correctly."
15
+ assert @b.odd?, "GMP::Z should odd? correctly."
16
+ assert @c.odd?, "GMP::Z should odd? correctly."
17
+ end
18
+
19
+ def test_square
20
+ assert @a.square?, "GMP::Z should square? correctly."
21
+ assert !@b.square?, "GMP::Z should square? correctly."
22
+ assert !@c.square?, "GMP::Z should square? correctly."
23
+ end
24
+
25
+ def test_power
26
+ assert @a.power?, "GMP::Z should power? correctly."
27
+ assert @b.power?, "GMP::Z should power? correctly."
28
+ assert !@c.power?, "GMP::Z should power? correctly."
29
+ end
30
+
31
+ def sqrtrem
32
+ assert_equal([10, 0], @a.sqrtrem, "GMP::Z should sqrtrem correctly.")
33
+ assert_equal([ 5, 2], @b.sqrtrem, "GMP::Z should sqrtrem correctly.")
34
+ assert_equal([ 9, 18], @c.sqrtrem, "GMP::Z should sqrtrem correctly.")
35
+ end
36
+
37
+ def sqrt
38
+ assert_equal(10, @a.sqrt, "GMP::Z should sqrt correctly.")
39
+ assert_equal( 5, @b.sqrt, "GMP::Z should sqrt correctly.")
40
+ assert_equal( 9, @c.sqrt, "GMP::Z should sqrt correctly.")
41
+ end
42
+
43
+ def root
44
+ assert_equal(4, @a.root(3), "GMP::Z should root correctly.")
45
+ assert_equal(3, @b.root(3), "GMP::Z should root correctly.")
46
+ assert_equal(4, @c.root(3), "GMP::Z should root correctly.")
47
+ end
48
+ end