mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
BigDecimal#precs is deprecated
This commit is contained in:
parent
c01ad11f90
commit
ed4381d941
2 changed files with 72 additions and 62 deletions
|
@ -30,13 +30,15 @@ describe "Kernel#BigDecimal" do
|
|||
BigDecimal(rational, 100).to_s.should == "0.99999999999999999999e18"
|
||||
end
|
||||
|
||||
it "accepts significant digits >= given precision" do
|
||||
BigDecimal("3.1415923", 10).precs[1].should >= 10
|
||||
end
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "accepts significant digits >= given precision" do
|
||||
BigDecimal("3.1415923", 10).precs[1].should >= 10
|
||||
end
|
||||
|
||||
it "determines precision from initial value" do
|
||||
pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
|
||||
BigDecimal(pi_string).precs[1].should >= pi_string.size-1
|
||||
it "determines precision from initial value" do
|
||||
pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
|
||||
BigDecimal(pi_string).precs[1].should >= pi_string.size-1
|
||||
end
|
||||
end
|
||||
|
||||
it "ignores leading and trailing whitespace" do
|
||||
|
@ -223,12 +225,14 @@ describe "Kernel#BigDecimal" do
|
|||
Float(@b).to_s.should == "166.66666666666666"
|
||||
end
|
||||
|
||||
it "has the expected precision on the LHS" do
|
||||
@a.precs[0].should == 18
|
||||
end
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "has the expected precision on the LHS" do
|
||||
@a.precs[0].should == 18
|
||||
end
|
||||
|
||||
it "has the expected maximum precision on the LHS" do
|
||||
@a.precs[1].should == 27
|
||||
it "has the expected maximum precision on the LHS" do
|
||||
@a.precs[1].should == 27
|
||||
end
|
||||
end
|
||||
|
||||
it "produces the expected result when done via Float" do
|
||||
|
@ -241,32 +245,36 @@ describe "Kernel#BigDecimal" do
|
|||
|
||||
# Check underlying methods work as we understand
|
||||
|
||||
it "BigDecimal precision is the number of digits rounded up to a multiple of nine" do
|
||||
1.upto(100) do |n|
|
||||
b = BigDecimal('4' * n)
|
||||
precs, _ = b.precs
|
||||
(precs >= 9).should be_true
|
||||
(precs >= n).should be_true
|
||||
(precs % 9).should == 0
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "BigDecimal precision is the number of digits rounded up to a multiple of nine" do
|
||||
1.upto(100) do |n|
|
||||
b = BigDecimal('4' * n)
|
||||
precs, _ = b.precs
|
||||
(precs >= 9).should be_true
|
||||
(precs >= n).should be_true
|
||||
(precs % 9).should == 0
|
||||
end
|
||||
BigDecimal('NaN').precs[0].should == 9
|
||||
end
|
||||
BigDecimal('NaN').precs[0].should == 9
|
||||
end
|
||||
|
||||
it "BigDecimal maximum precision is nine more than precision except for abnormals" do
|
||||
1.upto(100) do |n|
|
||||
b = BigDecimal('4' * n)
|
||||
precs, max = b.precs
|
||||
max.should == precs + 9
|
||||
it "BigDecimal maximum precision is nine more than precision except for abnormals" do
|
||||
1.upto(100) do |n|
|
||||
b = BigDecimal('4' * n)
|
||||
precs, max = b.precs
|
||||
max.should == precs + 9
|
||||
end
|
||||
BigDecimal('NaN').precs[1].should == 9
|
||||
end
|
||||
BigDecimal('NaN').precs[1].should == 9
|
||||
end
|
||||
|
||||
it "BigDecimal(Rational, 18) produces the result we expect" do
|
||||
BigDecimal(@b, 18).to_s.should == "0.166666666666666667e3"
|
||||
end
|
||||
|
||||
it "BigDecimal(Rational, BigDecimal.precs[0]) produces the result we expect" do
|
||||
BigDecimal(@b, @a.precs[0]).to_s.should == "0.166666666666666667e3"
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "BigDecimal(Rational, BigDecimal.precs[0]) produces the result we expect" do
|
||||
BigDecimal(@b, @a.precs[0]).to_s.should == "0.166666666666666667e3"
|
||||
end
|
||||
end
|
||||
|
||||
# Check the top-level expression works as we expect
|
||||
|
|
|
@ -1,48 +1,50 @@
|
|||
require_relative '../../spec_helper'
|
||||
require 'bigdecimal'
|
||||
|
||||
describe "BigDecimal#precs" do
|
||||
ruby_version_is ""..."3.0" do
|
||||
describe "BigDecimal#precs" do
|
||||
|
||||
before :each do
|
||||
@infinity = BigDecimal("Infinity")
|
||||
@infinity_neg = BigDecimal("-Infinity")
|
||||
@nan = BigDecimal("NaN")
|
||||
@zero = BigDecimal("0")
|
||||
@zero_neg = BigDecimal("-0")
|
||||
before :each do
|
||||
@infinity = BigDecimal("Infinity")
|
||||
@infinity_neg = BigDecimal("-Infinity")
|
||||
@nan = BigDecimal("NaN")
|
||||
@zero = BigDecimal("0")
|
||||
@zero_neg = BigDecimal("-0")
|
||||
|
||||
@arr = [BigDecimal("2E40001"), BigDecimal("3E-20001"),\
|
||||
@infinity, @infinity_neg, @nan, @zero, @zero_neg]
|
||||
@precision = BigDecimal::BASE.to_s.length - 1
|
||||
end
|
||||
|
||||
it "returns array of two values" do
|
||||
@arr.each do |x|
|
||||
x.precs.kind_of?(Array).should == true
|
||||
x.precs.size.should == 2
|
||||
@arr = [BigDecimal("2E40001"), BigDecimal("3E-20001"),\
|
||||
@infinity, @infinity_neg, @nan, @zero, @zero_neg]
|
||||
@precision = BigDecimal::BASE.to_s.length - 1
|
||||
end
|
||||
end
|
||||
|
||||
it "returns Integers as array values" do
|
||||
@arr.each do |x|
|
||||
x.precs[0].kind_of?(Integer).should == true
|
||||
x.precs[1].kind_of?(Integer).should == true
|
||||
it "returns array of two values" do
|
||||
@arr.each do |x|
|
||||
x.precs.kind_of?(Array).should == true
|
||||
x.precs.size.should == 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "returns the current value of significant digits as the first value" do
|
||||
BigDecimal("3.14159").precs[0].should >= 6
|
||||
BigDecimal('1').precs[0].should == BigDecimal('1' + '0' * 100).precs[0]
|
||||
[@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
|
||||
value.precs[0].should <= @precision
|
||||
it "returns Integers as array values" do
|
||||
@arr.each do |x|
|
||||
x.precs[0].kind_of?(Integer).should == true
|
||||
x.precs[1].kind_of?(Integer).should == true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "returns the maximum number of significant digits as the second value" do
|
||||
BigDecimal("3.14159").precs[1].should >= 6
|
||||
BigDecimal('1').precs[1].should >= 1
|
||||
BigDecimal('1' + '0' * 100).precs[1].should >= 101
|
||||
[@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
|
||||
value.precs[1].should >= 1
|
||||
it "returns the current value of significant digits as the first value" do
|
||||
BigDecimal("3.14159").precs[0].should >= 6
|
||||
BigDecimal('1').precs[0].should == BigDecimal('1' + '0' * 100).precs[0]
|
||||
[@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
|
||||
value.precs[0].should <= @precision
|
||||
end
|
||||
end
|
||||
|
||||
it "returns the maximum number of significant digits as the second value" do
|
||||
BigDecimal("3.14159").precs[1].should >= 6
|
||||
BigDecimal('1').precs[1].should >= 1
|
||||
BigDecimal('1' + '0' * 100).precs[1].should >= 101
|
||||
[@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
|
||||
value.precs[1].should >= 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue