Skip to content

Commit 0ba6379

Browse files
authored
Update bundled bigdecimal version (ruby#14809)
* Update bigdecimal spec * Update bundled bigdecimal to 3.3.1
1 parent 4bf1475 commit 0ba6379

File tree

10 files changed

+42
-46
lines changed

10 files changed

+42
-46
lines changed

gems/bundled_gems

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ racc 1.8.1 https://github.com/ruby/racc
2525
mutex_m 0.3.0 https://github.com/ruby/mutex_m
2626
getoptlong 0.2.1 https://github.com/ruby/getoptlong
2727
base64 0.3.0 https://github.com/ruby/base64
28-
bigdecimal 3.2.2 https://github.com/ruby/bigdecimal
28+
bigdecimal 3.3.1 https://github.com/ruby/bigdecimal
2929
observer 0.1.2 https://github.com/ruby/observer
3030
abbrev 0.1.2 https://github.com/ruby/abbrev
3131
resolv-replace 0.1.1 https://github.com/ruby/resolv-replace

spec/ruby/library/bigdecimal/BigDecimal_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@
156156
BigDecimal("-12345.6E-1").should == -reference
157157
end
158158

159-
it "raises ArgumentError when Float is used without precision" do
160-
-> { BigDecimal(1.0) }.should raise_error(ArgumentError)
159+
version_is BigDecimal::VERSION, "3.3.0" do
160+
it "allows Float without precision" do
161+
BigDecimal(1.2).should == BigDecimal("1.2")
162+
end
161163
end
162164

163165
it "returns appropriate BigDecimal zero for signed zero" do
@@ -259,8 +261,8 @@ def to_s; "cheese"; end
259261
end
260262

261263
it "produces the expected result" do
262-
@c.should == BigDecimal("-0.666667e-9")
263-
@c.to_s.should == "-0.666667e-9"
264+
@c.round(15).should == BigDecimal("-0.666667e-9")
265+
@c.round(15).to_s.should == "-0.666667e-9"
264266
end
265267

266268
it "produces the correct class for other arithmetic operators" do

spec/ruby/library/bigdecimal/add_spec.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@
7373
# BigDecimal("0.88").add(0.0, 1).should == BigDecimal("0.9")
7474
# end
7575

76-
describe "with Object" do
77-
it "tries to coerce the other operand to self" do
78-
object = mock("Object")
79-
object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4])
80-
@frac_3.add(object, 1).should == BigDecimal("0.1E16")
81-
end
82-
end
83-
8476
describe "with Rational" do
8577
it "produces a BigDecimal" do
8678
(@three + Rational(500, 2)).should == BigDecimal("0.253e3")

spec/ruby/library/bigdecimal/core_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020

2121
describe "BigDecimal#log" do
2222
it "handles high-precision Rational arguments" do
23-
result = BigDecimal('0.22314354220170971436137296411949880462556361100856391620766259404746040597133837784E0')
23+
# log(BigDecimal(r, 50), 50)
24+
result1 = BigDecimal('0.22314354220170971436137296411949880462556361100856e0')
25+
# log(BigDecimal(r, 1000), 50)
26+
result2 = BigDecimal('0.22314354220170971436137296411949880462556361100853e0')
2427
r = Rational(1_234_567_890, 987_654_321)
25-
BigMath.log(r, 50).should == result
28+
[result1, result2].should include(BigMath.log(r, 50).mult(1, 50))
2629
end
2730
end
2831

spec/ruby/library/bigdecimal/divmod_spec.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,19 @@ class BigDecimal
154154
end
155155
end
156156

157-
it "returns an array of zero and the dividend if the divisor is Infinity" do
158-
@regular_vals.each do |val|
159-
array = val.divmod(@infinity)
160-
array.length.should == 2
161-
array[0].should == @zero
162-
array[1].should == val
157+
version_is BigDecimal::VERSION, "3.3.0" do
158+
it "returns an array of zero and the dividend or minus one and Infinity if the divisor is Infinity" do
159+
@regular_vals.each do |val|
160+
array = val.divmod(@infinity)
161+
array.length.should == 2
162+
if val >= 0
163+
array[0].should == @zero
164+
array[1].should == val
165+
else
166+
array[0].should == @one_minus
167+
array[1].should == @infinity
168+
end
169+
end
163170
end
164171
end
165172

spec/ruby/library/bigdecimal/mult_spec.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,4 @@
2121
@e.mult(@one, 1).should be_close(@one, @tolerance)
2222
@e3_minus.mult(@one, 1).should be_close(0, @tolerance2)
2323
end
24-
25-
describe "with Object" do
26-
it "tries to coerce the other operand to self" do
27-
object = mock("Object")
28-
object.should_receive(:coerce).with(@e3_minus).and_return([@e3_minus, @e3_plus])
29-
@e3_minus.mult(object, 1).should == BigDecimal("9")
30-
end
31-
end
3224
end

spec/ruby/library/bigdecimal/remainder_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@
3737
@neg_int.remainder(@pos_frac).should == @neg_int - @pos_frac * (@neg_int / @pos_frac).truncate
3838
end
3939

40-
it "returns NaN used with zero" do
41-
@mixed.remainder(@zero).should.nan?
42-
@zero.remainder(@zero).should.nan?
40+
version_is BigDecimal::VERSION, "3.3.0" do
41+
it "raises ZeroDivisionError used with zero" do
42+
-> { @mixed.remainder(@zero) }.should raise_error(ZeroDivisionError)
43+
-> { @zero.remainder(@zero) }.should raise_error(ZeroDivisionError)
44+
end
4345
end
4446

4547
it "returns zero if used on zero" do

spec/ruby/library/bigdecimal/shared/modulo.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,16 @@
101101
@infinity_minus.send(@method, @infinity).should.nan?
102102
end
103103

104-
it "returns the dividend if the divisor is Infinity" do
105-
@one.send(@method, @infinity).should == @one
106-
@one.send(@method, @infinity_minus).should == @one
107-
@frac_2.send(@method, @infinity_minus).should == @frac_2
104+
version_is BigDecimal::VERSION, "3.3.0" do
105+
it "returns the dividend if the divisor is Infinity and signs are same" do
106+
@one.send(@method, @infinity).should == @one
107+
(-@frac_2).send(@method, @infinity_minus).should == -@frac_2
108+
end
109+
110+
it "returns the divisor if the divisor is Infinity and signs are different" do
111+
(-@one).send(@method, @infinity).should == @infinity
112+
@frac_2.send(@method, @infinity_minus).should == @infinity_minus
113+
end
108114
end
109115

110116
it "raises TypeError if the argument cannot be coerced to BigDecimal" do

spec/ruby/library/bigdecimal/shared/power.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
e = BigDecimal("1.00000000000000000000123456789")
1111
one = BigDecimal("1")
1212
ten = BigDecimal("10")
13-
# The tolerance is dependent upon the size of BASE_FIG
14-
tolerance = BigDecimal("1E-70")
13+
# Accuracy is at least ndigits(== 30) + DOUBLE_FIG(== 16)
14+
tolerance = BigDecimal("1E-46")
1515
ten_powers = BigDecimal("1E10000")
1616
pi = BigDecimal("3.14159265358979")
1717
e3_minus.send(@method, 2).should == e3_minus_power_2

spec/ruby/library/bigdecimal/sub_spec.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@
3535
@frac_1.sub(@frac_1, 1000000).should == @zero
3636
end
3737

38-
describe "with Object" do
39-
it "tries to coerce the other operand to self" do
40-
object = mock("Object")
41-
object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4])
42-
@frac_3.sub(object, 1).should == BigDecimal("-0.9E15")
43-
end
44-
end
45-
4638
describe "with Rational" do
4739
it "produces a BigDecimal" do
4840
(@three - Rational(500, 2)).should == BigDecimal('-0.247e3')

0 commit comments

Comments
 (0)