rubysl-bigdecimal 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +29 -0
  7. data/Rakefile +1 -0
  8. data/ext/rubysl/bigdecimal/bigdecimal.c +4760 -0
  9. data/ext/rubysl/bigdecimal/bigdecimal.h +220 -0
  10. data/ext/rubysl/bigdecimal/extconf.rb +6 -0
  11. data/lib/bigdecimal.rb +1 -0
  12. data/lib/bigdecimal/README +60 -0
  13. data/lib/bigdecimal/bigdecimal_en.html +796 -0
  14. data/lib/bigdecimal/bigdecimal_ja.html +799 -0
  15. data/lib/bigdecimal/jacobian.rb +85 -0
  16. data/lib/bigdecimal/ludcmp.rb +84 -0
  17. data/lib/bigdecimal/math.rb +235 -0
  18. data/lib/bigdecimal/newton.rb +77 -0
  19. data/lib/bigdecimal/sample/linear.rb +71 -0
  20. data/lib/bigdecimal/sample/nlsolve.rb +38 -0
  21. data/lib/bigdecimal/sample/pi.rb +20 -0
  22. data/lib/bigdecimal/util.rb +65 -0
  23. data/lib/rubysl/bigdecimal.rb +2 -0
  24. data/lib/rubysl/bigdecimal/version.rb +5 -0
  25. data/rubysl-bigdecimal.gemspec +24 -0
  26. data/spec/abs_spec.rb +49 -0
  27. data/spec/add_spec.rb +178 -0
  28. data/spec/case_compare_spec.rb +6 -0
  29. data/spec/ceil_spec.rb +122 -0
  30. data/spec/coerce_spec.rb +25 -0
  31. data/spec/comparison_spec.rb +80 -0
  32. data/spec/div_spec.rb +143 -0
  33. data/spec/divide_spec.rb +6 -0
  34. data/spec/divmod_spec.rb +233 -0
  35. data/spec/double_fig_spec.rb +8 -0
  36. data/spec/eql_spec.rb +5 -0
  37. data/spec/equal_value_spec.rb +6 -0
  38. data/spec/exponent_spec.rb +37 -0
  39. data/spec/finite_spec.rb +34 -0
  40. data/spec/fix_spec.rb +56 -0
  41. data/spec/fixtures/classes.rb +17 -0
  42. data/spec/floor_spec.rb +109 -0
  43. data/spec/frac_spec.rb +47 -0
  44. data/spec/gt_spec.rb +86 -0
  45. data/spec/gte_spec.rb +90 -0
  46. data/spec/induced_from_spec.rb +36 -0
  47. data/spec/infinite_spec.rb +31 -0
  48. data/spec/inspect_spec.rb +40 -0
  49. data/spec/limit_spec.rb +29 -0
  50. data/spec/lt_spec.rb +84 -0
  51. data/spec/lte_spec.rb +90 -0
  52. data/spec/minus_spec.rb +57 -0
  53. data/spec/mode_spec.rb +64 -0
  54. data/spec/modulo_spec.rb +11 -0
  55. data/spec/mult_spec.rb +23 -0
  56. data/spec/multiply_spec.rb +25 -0
  57. data/spec/nan_spec.rb +22 -0
  58. data/spec/new_spec.rb +120 -0
  59. data/spec/nonzero_spec.rb +28 -0
  60. data/spec/plus_spec.rb +49 -0
  61. data/spec/power_spec.rb +5 -0
  62. data/spec/precs_spec.rb +48 -0
  63. data/spec/quo_spec.rb +12 -0
  64. data/spec/remainder_spec.rb +83 -0
  65. data/spec/round_spec.rb +193 -0
  66. data/spec/shared/eql.rb +65 -0
  67. data/spec/shared/modulo.rb +146 -0
  68. data/spec/shared/mult.rb +97 -0
  69. data/spec/shared/power.rb +83 -0
  70. data/spec/shared/quo.rb +59 -0
  71. data/spec/shared/to_int.rb +27 -0
  72. data/spec/sign_spec.rb +46 -0
  73. data/spec/split_spec.rb +87 -0
  74. data/spec/sqrt_spec.rb +111 -0
  75. data/spec/sub_spec.rb +52 -0
  76. data/spec/to_f_spec.rb +54 -0
  77. data/spec/to_i_spec.rb +6 -0
  78. data/spec/to_int_spec.rb +7 -0
  79. data/spec/to_s_spec.rb +71 -0
  80. data/spec/truncate_spec.rb +100 -0
  81. data/spec/uminus_spec.rb +57 -0
  82. data/spec/uplus_spec.rb +19 -0
  83. data/spec/ver_spec.rb +10 -0
  84. data/spec/zero_spec.rb +27 -0
  85. metadata +243 -0
@@ -0,0 +1,65 @@
1
+ require 'bigdecimal'
2
+
3
+ describe :bigdecimal_eql, :shared => true do
4
+ before(:each) do
5
+ @bg6543_21 = BigDecimal.new("6543.21")
6
+ @bg5667_19 = BigDecimal.new("5667.19")
7
+ @a = BigDecimal("1.0000000000000000000000000000000000000000005")
8
+ @b = BigDecimal("1.00000000000000000000000000000000000000000005")
9
+ @bigint = BigDecimal("1000.0")
10
+ @nan = BigDecimal("NaN")
11
+ @infinity = BigDecimal("Infinity")
12
+ @infinity_minus = BigDecimal("-Infinity")
13
+ end
14
+
15
+ it "tests for equality" do
16
+ @bg6543_21.send(@method, @bg6543_21).should == true
17
+ @a.send(@method, @a).should == true
18
+ @a.send(@method, @b).should == false
19
+ @bg6543_21.send(@method, @a).should == false
20
+ @bigint.send(@method, 1000).should == true
21
+ end
22
+
23
+ ruby_bug "redmine:2349", "1.8.7" do
24
+ it "NaN is never equal to any number" do
25
+ @nan.send(@method, @nan).should == false
26
+ @a.send(@method, @nan).should == false
27
+ @nan.send(@method, @a).should == false
28
+ @nan.send(@method, @infinity).should == false
29
+ @nan.send(@method, @infinity_minus).should == false
30
+ @infinity.send(@method, @nan).should == false
31
+ @infinity_minus.send(@method, @nan).should == false
32
+ end
33
+ end
34
+
35
+ it "returns true for infinity values with the same sign" do
36
+ @infinity.send(@method, @infinity).should == true
37
+ @infinity.send(@method, BigDecimal("Infinity")).should == true
38
+ BigDecimal("Infinity").send(@method, @infinity).should == true
39
+
40
+ @infinity_minus.send(@method, @infinity_minus).should == true
41
+ @infinity_minus.send(@method, BigDecimal("-Infinity")).should == true
42
+ BigDecimal("-Infinity").send(@method, @infinity_minus).should == true
43
+ end
44
+
45
+ it "returns false for infinity values with different signs" do
46
+ @infinity.send(@method, @infinity_minus).should == false
47
+ @infinity_minus.send(@method, @infinity).should == false
48
+ end
49
+
50
+ it "returns false when infinite value compared to finite one" do
51
+ @infinity.send(@method, @a).should == false
52
+ @infinity_minus.send(@method, @a).should == false
53
+
54
+ @a.send(@method, @infinity).should == false
55
+ @a.send(@method, @infinity_minus).should == false
56
+ end
57
+
58
+ ruby_bug "redmine:2349", "1.8.7" do
59
+ it "returns false when compared objects that can not be coerced into BigDecimal" do
60
+ @infinity.send(@method, nil).should == false
61
+ @bigint.send(@method, nil).should == false
62
+ @nan.send(@method, nil).should == false
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,146 @@
1
+ require 'bigdecimal'
2
+
3
+ describe :bigdecimal_modulo, :shared => true do
4
+ before(:each) do
5
+ @one = BigDecimal("1")
6
+ @zero = BigDecimal("0")
7
+ @zero_pos = BigDecimal("+0")
8
+ @zero_neg = BigDecimal("-0")
9
+ @two = BigDecimal("2")
10
+ @three = BigDecimal("3")
11
+ @mixed = BigDecimal("1.23456789")
12
+ @nan = BigDecimal("NaN")
13
+ @infinity = BigDecimal("Infinity")
14
+ @infinity_minus = BigDecimal("-Infinity")
15
+ @one_minus = BigDecimal("-1")
16
+ @frac_1 = BigDecimal("1E-9999")
17
+ @frac_2 = BigDecimal("0.9E-9999")
18
+ end
19
+
20
+ it "returns self modulo other" do
21
+ bd6543 = BigDecimal.new("6543.21")
22
+ bd5667 = BigDecimal.new("5667.19")
23
+ a = BigDecimal("1.0000000000000000000000000000000000000000005")
24
+ b = BigDecimal("1.00000000000000000000000000000000000000000005")
25
+
26
+ bd6543.send(@method, 137).should == BigDecimal("104.21")
27
+ bd5667.send(@method, bignum_value).should == 5667.19
28
+ bd6543.send(@method, BigDecimal("137.24")).should == BigDecimal("92.93")
29
+ bd6543.send(@method, 137).should be_close(6543.21.%(137), TOLERANCE)
30
+ bd6543.send(@method, 137).should == bd6543 % 137
31
+ bd5667.send(@method, bignum_value).should be_close(5667.19.%(0xffffffff), TOLERANCE)
32
+ bd5667.send(@method, bignum_value).should == bd5667.%(0xffffffff)
33
+ bd6543.send(@method, 137.24).should be_close(6543.21.%(137.24), TOLERANCE)
34
+ a.send(@method, b).should == BigDecimal("0.45E-42")
35
+ @zero.send(@method, @one).should == @zero
36
+ @zero.send(@method, @one_minus).should == @zero
37
+ @two.send(@method, @one).should == @zero
38
+ @one.send(@method, @two).should == @one
39
+ @frac_1.send(@method, @one).should == @frac_1
40
+ @frac_2.send(@method, @one).should == @frac_2
41
+ @one_minus.send(@method, @one_minus).should == @zero
42
+ @one_minus.send(@method, @one).should == @zero
43
+ @one_minus.send(@method, @two).should == @one
44
+ @one.send(@method, -@two).should == -@one
45
+
46
+ @one_minus.modulo(BigDecimal('0.9')).should == BigDecimal('0.8')
47
+ @one.modulo(BigDecimal('-0.9')).should == BigDecimal('-0.8')
48
+
49
+ @one_minus.modulo(BigDecimal('0.8')).should == BigDecimal('0.6')
50
+ @one.modulo(BigDecimal('-0.8')).should == BigDecimal('-0.6')
51
+
52
+ @one_minus.modulo(BigDecimal('0.6')).should == BigDecimal('0.2')
53
+ @one.modulo(BigDecimal('-0.6')).should == BigDecimal('-0.2')
54
+
55
+ @one_minus.modulo(BigDecimal('0.5')).should == @zero
56
+ @one.modulo(BigDecimal('-0.5')).should == @zero
57
+ @one_minus.modulo(BigDecimal('-0.5')).should == @zero
58
+
59
+ @one_minus.modulo(BigDecimal('0.4')).should == BigDecimal('0.2')
60
+ @one.modulo(BigDecimal('-0.4')).should == BigDecimal('-0.2')
61
+
62
+ @one_minus.modulo(BigDecimal('0.3')).should == BigDecimal('0.2')
63
+ @one_minus.modulo(BigDecimal('0.2')).should == @zero
64
+ end
65
+
66
+ ruby_bug "#", "1.9.2" do
67
+ it "returns a [Float value] when the argument is Float" do
68
+ @two.send(@method, 2.0).should == 0.0
69
+ @one.send(@method, 2.0).should == 1.0
70
+ res = @two.send(@method, 5.0)
71
+ res.kind_of?(BigDecimal).should == true
72
+ end
73
+ end
74
+
75
+ it "returns NaN if NaN is involved" do
76
+ @nan.send(@method, @nan).nan?.should == true
77
+ @nan.send(@method, @one).nan?.should == true
78
+ @one.send(@method, @nan).nan?.should == true
79
+ @infinity.send(@method, @nan).nan?.should == true
80
+ @nan.send(@method, @infinity).nan?.should == true
81
+ end
82
+
83
+ it "returns NaN if the dividend is Infinity" do
84
+ @infinity.send(@method, @infinity).nan?.should == true
85
+ @infinity.send(@method, @one).nan?.should == true
86
+ @infinity.send(@method, @mixed).nan?.should == true
87
+ @infinity.send(@method, @one_minus).nan?.should == true
88
+ @infinity.send(@method, @frac_1).nan?.should == true
89
+
90
+ @infinity_minus.send(@method, @infinity_minus).nan?.should == true
91
+ @infinity_minus.send(@method, @one).nan?.should == true
92
+
93
+ @infinity.send(@method, @infinity_minus).nan?.should == true
94
+ @infinity_minus.send(@method, @infinity).nan?.should == true
95
+ end
96
+
97
+ ruby_version_is "" ... "1.9" do
98
+ it "returns NaN if the divisor is Infinity" do
99
+ @one.send(@method, @infinity).nan?.should == true
100
+ @one.send(@method, @infinity_minus).nan?.should == true
101
+ @frac_2.send(@method, @infinity_minus).nan?.should == true
102
+ end
103
+ end
104
+
105
+ ruby_version_is "1.9" do
106
+ it "returns the dividend if the divisor is Infinity" do
107
+ @one.send(@method, @infinity).should == @one
108
+ @one.send(@method, @infinity_minus).should == @one
109
+ @frac_2.send(@method, @infinity_minus).should == @frac_2
110
+ end
111
+ end
112
+
113
+ it "raises TypeError if the argument cannot be coerced to BigDecimal" do
114
+ lambda {
115
+ @one.send(@method, '2')
116
+ }.should raise_error(TypeError)
117
+ end
118
+ end
119
+
120
+ describe :bigdecimal_modulo_zerodivisionerror, :shared => true do
121
+ ruby_version_is "" ... "1.9" do
122
+ it "does NOT raise ZeroDivisionError if other is zero" do
123
+ bd6543 = BigDecimal.new("6543.21")
124
+ bd5667 = BigDecimal.new("5667.19")
125
+ a = BigDecimal("1.0000000000000000000000000000000000000000005")
126
+ b = BigDecimal("1.00000000000000000000000000000000000000000005")
127
+
128
+ bd5667.send(@method, 0).nan?.should == true
129
+ bd5667.send(@method, BigDecimal("0")).nan?.should == true
130
+ @zero.send(@method, @zero).nan?.should == true
131
+ end
132
+ end
133
+
134
+ ruby_version_is "1.9" do
135
+ it "raises ZeroDivisionError if other is zero" do
136
+ bd6543 = BigDecimal.new("6543.21")
137
+ bd5667 = BigDecimal.new("5667.19")
138
+ a = BigDecimal("1.0000000000000000000000000000000000000000005")
139
+ b = BigDecimal("1.00000000000000000000000000000000000000000005")
140
+
141
+ lambda { bd5667.send(@method, 0) }.should raise_error(ZeroDivisionError)
142
+ lambda { bd5667.send(@method, BigDecimal("0")) }.should raise_error(ZeroDivisionError)
143
+ lambda { @zero.send(@method, @zero) }.should raise_error(ZeroDivisionError)
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,97 @@
1
+ require 'bigdecimal'
2
+
3
+ describe :bigdecimal_mult, :shared => true do
4
+ before :each do
5
+ @zero = BigDecimal "0"
6
+ @zero_pos = BigDecimal "+0"
7
+ @zero_neg = BigDecimal "-0"
8
+
9
+ @one = BigDecimal "1"
10
+ @mixed = BigDecimal "1.23456789"
11
+ @pos_int = BigDecimal "2E5555"
12
+ @neg_int = BigDecimal "-2E5555"
13
+ @pos_frac = BigDecimal "2E-9999"
14
+ @neg_frac = BigDecimal "-2E-9999"
15
+ @nan = BigDecimal "NaN"
16
+ @infinity = BigDecimal "Infinity"
17
+ @infinity_minus = BigDecimal "-Infinity"
18
+ @one_minus = BigDecimal "-1"
19
+ @frac_1 = BigDecimal "1E-99999"
20
+ @frac_2 = BigDecimal "0.9E-99999"
21
+
22
+ @e3_minus = BigDecimal "3E-20001"
23
+ @e = BigDecimal "1.00000000000000000000123456789"
24
+ @tolerance = @e.sub @one, 1000
25
+ @tolerance2 = BigDecimal "30001E-20005"
26
+
27
+ @special_vals = [@infinity, @infinity_minus, @nan]
28
+ @regular_vals = [ @one, @mixed, @pos_int, @neg_int,
29
+ @pos_frac, @neg_frac, @one_minus,
30
+ @frac_1, @frac_2
31
+ ]
32
+ @zeroes = [@zero, @zero_pos, @zero_neg]
33
+ end
34
+
35
+ it "returns zero of appropriate sign if self or argument is zero" do
36
+ @zero.send(@method, @zero, *@object).sign.should == BigDecimal::SIGN_POSITIVE_ZERO
37
+ @zero_neg.send(@method, @zero_neg, *@object).sign.should == BigDecimal::SIGN_POSITIVE_ZERO
38
+ @zero.send(@method, @zero_neg, *@object).sign.should == BigDecimal::SIGN_NEGATIVE_ZERO
39
+ @zero_neg.send(@method, @zero, *@object).sign.should == BigDecimal::SIGN_NEGATIVE_ZERO
40
+
41
+ @one.send(@method, @zero, *@object).sign.should == BigDecimal::SIGN_POSITIVE_ZERO
42
+ @one.send(@method, @zero_neg, *@object).sign.should == BigDecimal::SIGN_NEGATIVE_ZERO
43
+
44
+ @zero.send(@method, @one, *@object).sign.should == BigDecimal::SIGN_POSITIVE_ZERO
45
+ @zero.send(@method, @one_minus, *@object).sign.should == BigDecimal::SIGN_NEGATIVE_ZERO
46
+ @zero_neg.send(@method, @one_minus, *@object).sign.should == BigDecimal::SIGN_POSITIVE_ZERO
47
+ @zero_neg.send(@method, @one, *@object).sign.should == BigDecimal::SIGN_NEGATIVE_ZERO
48
+ end
49
+
50
+ it "returns NaN if NaN is involved" do
51
+ values = @regular_vals + @zeroes
52
+
53
+ values.each do |val|
54
+ @nan.send(@method, val, *@object).nan?.should == true
55
+ val.send(@method, @nan, *@object).nan?.should == true
56
+ end
57
+ end
58
+
59
+ it "returns zero if self or argument is zero" do
60
+ values = @regular_vals + @zeroes
61
+
62
+ values.each do |val|
63
+ @zeroes.each do |zero|
64
+ zero.send(@method, val, *@object).should == 0
65
+ zero.send(@method, val, *@object).zero?.should == true
66
+ val.send(@method, zero, *@object).should == 0
67
+ val.send(@method, zero, *@object).zero?.should == true
68
+ end
69
+ end
70
+ end
71
+
72
+ it "returns infinite value if self or argument is infinite" do
73
+ values = @regular_vals
74
+ infs = [@infinity, @infinity_minus]
75
+
76
+ values.each do |val|
77
+ infs.each do |inf|
78
+ inf.send(@method, val, *@object).finite?.should == false
79
+ val.send(@method, inf, *@object).finite?.should == false
80
+ end
81
+ end
82
+
83
+ @infinity.send(@method, @infinity, *@object).infinite?.should == 1
84
+ @infinity_minus.send(@method, @infinity_minus, *@object).infinite?.should == 1
85
+ @infinity.send(@method, @infinity_minus, *@object).infinite?.should == -1
86
+ @infinity_minus.send(@method, @infinity, *@object).infinite?.should == -1
87
+ @infinity.send(@method, @one, *@object).infinite?.should == 1
88
+ @infinity_minus.send(@method, @one, *@object).infinite?.should == -1
89
+ end
90
+
91
+ it "returns NaN if the result is undefined" do
92
+ @zero.send(@method, @infinity, *@object).nan?.should == true
93
+ @zero.send(@method, @infinity_minus, *@object).nan?.should == true
94
+ @infinity.send(@method, @zero, *@object).nan?.should == true
95
+ @infinity_minus.send(@method, @zero, *@object).nan?.should == true
96
+ end
97
+ end
@@ -0,0 +1,83 @@
1
+ require 'bigdecimal'
2
+
3
+ describe :bigdecimal_power, :shared => true do
4
+ it "powers of self" do
5
+ e3_minus = BigDecimal("3E-20001")
6
+ e3_minus_power_2 = BigDecimal("9E-40002")
7
+ e3_plus = BigDecimal("3E20001")
8
+ e2_plus = BigDecimal("2E40001")
9
+ e5_minus = BigDecimal("5E-40002")
10
+ e = BigDecimal("1.00000000000000000000123456789")
11
+ one = BigDecimal("1")
12
+ ten = BigDecimal("10")
13
+ # The tolerance is dependent upon the size of BASE_FIG
14
+ tolerance = BigDecimal("1E-70")
15
+ ten_powers = BigDecimal("1E10000")
16
+ pi = BigDecimal("3.14159265358979")
17
+ e3_minus.send(@method, 2).should == e3_minus_power_2
18
+ e3_plus.send(@method, 0).should == 1
19
+ e3_minus.send(@method, 1).should == e3_minus
20
+ e2_plus.send(@method, -1).should == e5_minus
21
+ e2_plus.send(@method, -1).should == e5_minus.power(1)
22
+ (e2_plus.send(@method, -1) * e5_minus.send(@method, -1)).should == 1
23
+ e.send(@method, 2).should == e * e
24
+ e.send(@method, -1).should be_close(one.div(e, 120), tolerance)
25
+ ten.send(@method, 10000).should == ten_powers
26
+ pi.send(@method, 10).should be_close(Math::PI ** 10, TOLERANCE)
27
+ end
28
+
29
+ it "powers of 1 equal 1" do
30
+ one = BigDecimal("1")
31
+ one.send(@method, 0).should == 1
32
+ one.send(@method, 1).should == 1
33
+ one.send(@method, 10).should == 1
34
+ one.send(@method, -10).should == 1
35
+ end
36
+
37
+ it "0 to power of 0 is 1" do
38
+ zero = BigDecimal("0")
39
+ zero.send(@method, 0).should == 1
40
+ end
41
+
42
+ it "0 to powers < 0 is Infinity" do
43
+ zero = BigDecimal("0")
44
+ infinity = BigDecimal("Infinity")
45
+ zero.send(@method, -10).should == infinity
46
+ zero.send(@method, -1).should == infinity
47
+ end
48
+
49
+ it "other powers of 0 are 0" do
50
+ zero = BigDecimal("0")
51
+ zero.send(@method, 1).should == 0
52
+ zero.send(@method, 10).should == 0
53
+ end
54
+
55
+ it "returns NaN if self is NaN" do
56
+ BigDecimal("NaN").send(@method, -5).nan?.should == true
57
+ BigDecimal("NaN").send(@method, 5).nan?.should == true
58
+ end
59
+
60
+ ruby_version_is "" ... "1.8.8" do
61
+ it "returns NaN if self is infinite" do
62
+ BigDecimal("Infinity").send(@method, -5).nan?.should == true
63
+ BigDecimal("-Infinity").send(@method, -5).nan?.should == true
64
+ BigDecimal("Infinity").send(@method, 5).nan?.should == true
65
+ BigDecimal("-Infinity").send(@method, 5).nan?.should == true
66
+ end
67
+ end
68
+
69
+ ruby_version_is "1.8.8" do # this behavior may be backported to 1.8.7 [ruby-dev:40182]
70
+ it "returns 0.0 if self is infinite and argument is negative" do
71
+ BigDecimal("Infinity").send(@method, -5).should == 0
72
+ BigDecimal("-Infinity").send(@method, -5).should == 0
73
+ end
74
+
75
+ it "returns infinite if self is infinite and argument is positive" do
76
+ infinity = BigDecimal("Infinity")
77
+ BigDecimal("Infinity").send(@method, 4).should == infinity
78
+ BigDecimal("-Infinity").send(@method, 4).should == infinity
79
+ BigDecimal("Infinity").send(@method, 5).should == infinity
80
+ BigDecimal("-Infinity").send(@method, 5).should == -infinity
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,59 @@
1
+ require 'bigdecimal'
2
+
3
+ describe :bigdecimal_quo, :shared => true do
4
+ before(:each) do
5
+ @one = BigDecimal("1")
6
+ @zero = BigDecimal("0")
7
+ @zero_plus = BigDecimal("+0")
8
+ @zero_minus = BigDecimal("-0")
9
+ @two = BigDecimal("2")
10
+ @three = BigDecimal("3")
11
+ @eleven = BigDecimal("11")
12
+ @nan = BigDecimal("NaN")
13
+ @infinity = BigDecimal("Infinity")
14
+ @infinity_minus = BigDecimal("-Infinity")
15
+ @one_minus = BigDecimal("-1")
16
+ @frac_1 = BigDecimal("1E-99999")
17
+ @frac_2 = BigDecimal("0.9E-99999")
18
+ end
19
+
20
+ it "returns a / b" do
21
+ @two.send(@method, @one, *@object).should == @two
22
+ @one.send(@method, @two, *@object).should == BigDecimal("0.5")
23
+ @eleven.send(@method, @three, *@object).should be_close(@three + (@two / @three), TOLERANCE)
24
+ @one.send(@method, @one_minus, *@object).should == @one_minus
25
+ @one_minus.send(@method, @one_minus, *@object).should == @one
26
+ @frac_2.send(@method, @frac_1, *@object).should == BigDecimal("0.9")
27
+ @frac_1.send(@method, @frac_1, *@object).should == @one
28
+ @one.send(@method, BigDecimal('-2E5555'), *@object).should == BigDecimal('-0.5E-5555')
29
+ @one.send(@method, BigDecimal('2E-5555'), *@object).should == BigDecimal('0.5E5555')
30
+ end
31
+
32
+ it "returns 0 if divided by Infinity" do
33
+ @zero.send(@method, @infinity, *@object).should == 0
34
+ @frac_2.send(@method, @infinity, *@object).should == 0
35
+ end
36
+
37
+ it "returns (+|-) Infinity if (+|-) Infinity divided by one" do
38
+ @infinity_minus.send(@method, @one, *@object).should == @infinity_minus
39
+ @infinity.send(@method, @one, *@object).should == @infinity
40
+ @infinity_minus.send(@method, @one_minus, *@object).should == @infinity
41
+ end
42
+
43
+ it "returns NaN if Infinity / ((+|-) Infinity)" do
44
+ @infinity.send(@method, @infinity_minus, *@object).nan?.should == true
45
+ @infinity_minus.send(@method, @infinity, *@object).nan?.should == true
46
+ end
47
+
48
+ it "returns (+|-) Infinity if divided by zero" do
49
+ @one.send(@method, @zero, *@object).should == @infinity
50
+ @one.send(@method, @zero_plus, *@object).should == @infinity
51
+ @one.send(@method, @zero_minus, *@object).should == @infinity_minus
52
+ end
53
+
54
+ it "returns NaN if zero is divided by zero" do
55
+ @zero.send(@method, @zero, *@object).nan?.should == true
56
+ @zero_minus.send(@method, @zero_plus, *@object).nan?.should == true
57
+ @zero_plus.send(@method, @zero_minus, *@object).nan?.should == true
58
+ end
59
+ end