diff options
author | Benoit Daloze <[email protected]> | 2022-06-26 14:50:14 +0200 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2022-06-26 14:50:14 +0200 |
commit | d3d5ef0cca160fca538c7f556c5a6e08df5847e6 (patch) | |
tree | 57358b4b9cdd6f429d0383005ac393cb74dd3bff /spec/ruby/core/float | |
parent | f616e816372d14e605879d2e43c7fbdda29ef837 (diff) |
Update to ruby/spec@ab32a1a
Diffstat (limited to 'spec/ruby/core/float')
-rw-r--r-- | spec/ruby/core/float/divide_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/float/round_spec.rb | 64 |
2 files changed, 68 insertions, 0 deletions
diff --git a/spec/ruby/core/float/divide_spec.rb b/spec/ruby/core/float/divide_spec.rb index d8f71a6b98..72ab7527bd 100644 --- a/spec/ruby/core/float/divide_spec.rb +++ b/spec/ruby/core/float/divide_spec.rb @@ -36,4 +36,8 @@ describe "Float#/" do -> { 13.0 / "10" }.should raise_error(TypeError) -> { 13.0 / :symbol }.should raise_error(TypeError) end + + it "divides correctly by Rational numbers" do + (1.2345678901234567 / Rational(1, 10000000000000000000)).should == 1.2345678901234567e+19 + end end diff --git a/spec/ruby/core/float/round_spec.rb b/spec/ruby/core/float/round_spec.rb index 4bd2dc460c..e5a8f534e7 100644 --- a/spec/ruby/core/float/round_spec.rb +++ b/spec/ruby/core/float/round_spec.rb @@ -103,6 +103,70 @@ describe "Float#round" do 5.55.round(1, half: :up).should eql(5.6) 5.55.round(1, half: :down).should eql(5.5) 5.55.round(1, half: :even).should eql(5.6) + -5.55.round(1, half: nil).should eql(-5.6) + -5.55.round(1, half: :up).should eql(-5.6) + -5.55.round(1, half: :down).should eql(-5.5) + -5.55.round(1, half: :even).should eql(-5.6) + end + + it "preserves cases where neighbouring floating pointer number increase the decimal places" do + 4.8100000000000005.round(5, half: nil).should eql(4.81) + 4.8100000000000005.round(5, half: :up).should eql(4.81) + 4.8100000000000005.round(5, half: :down).should eql(4.81) + 4.8100000000000005.round(5, half: :even).should eql(4.81) + -4.8100000000000005.round(5, half: nil).should eql(-4.81) + -4.8100000000000005.round(5, half: :up).should eql(-4.81) + -4.8100000000000005.round(5, half: :down).should eql(-4.81) + -4.8100000000000005.round(5, half: :even).should eql(-4.81) + 4.81.round(5, half: nil).should eql(4.81) + 4.81.round(5, half: :up).should eql(4.81) + 4.81.round(5, half: :down).should eql(4.81) + 4.81.round(5, half: :even).should eql(4.81) + -4.81.round(5, half: nil).should eql(-4.81) + -4.81.round(5, half: :up).should eql(-4.81) + -4.81.round(5, half: :down).should eql(-4.81) + -4.81.round(5, half: :even).should eql(-4.81) + 4.809999999999999.round(5, half: nil).should eql(4.81) + 4.809999999999999.round(5, half: :up).should eql(4.81) + 4.809999999999999.round(5, half: :down).should eql(4.81) + 4.809999999999999.round(5, half: :even).should eql(4.81) + -4.809999999999999.round(5, half: nil).should eql(-4.81) + -4.809999999999999.round(5, half: :up).should eql(-4.81) + -4.809999999999999.round(5, half: :down).should eql(-4.81) + -4.809999999999999.round(5, half: :even).should eql(-4.81) + end + + ruby_bug "", ""..."3.3" do + # These numbers are neighbouring floating point numbers round a + # precise value. They test that the rounding modes work correctly + # round that value and precision is not lost which might cause + # incorrect results. + it "does not lose precision during the rounding process" do + 767573.1875850001.round(5, half: nil).should eql(767573.18759) + 767573.1875850001.round(5, half: :up).should eql(767573.18759) + 767573.1875850001.round(5, half: :down).should eql(767573.18759) + 767573.1875850001.round(5, half: :even).should eql(767573.18759) + -767573.1875850001.round(5, half: nil).should eql(-767573.18759) + -767573.1875850001.round(5, half: :up).should eql(-767573.18759) + -767573.1875850001.round(5, half: :down).should eql(-767573.18759) + -767573.1875850001.round(5, half: :even).should eql(-767573.18759) + 767573.187585.round(5, half: nil).should eql(767573.18759) + 767573.187585.round(5, half: :up).should eql(767573.18759) + 767573.187585.round(5, half: :down).should eql(767573.18758) + 767573.187585.round(5, half: :even).should eql(767573.18758) + -767573.187585.round(5, half: nil).should eql(-767573.18759) + -767573.187585.round(5, half: :up).should eql(-767573.18759) + -767573.187585.round(5, half: :down).should eql(-767573.18758) + -767573.187585.round(5, half: :even).should eql(-767573.18758) + 767573.1875849998.round(5, half: nil).should eql(767573.18758) + 767573.1875849998.round(5, half: :up).should eql(767573.18758) + 767573.1875849998.round(5, half: :down).should eql(767573.18758) + 767573.1875849998.round(5, half: :even).should eql(767573.18758) + -767573.1875849998.round(5, half: nil).should eql(-767573.18758) + -767573.1875849998.round(5, half: :up).should eql(-767573.18758) + -767573.1875849998.round(5, half: :down).should eql(-767573.18758) + -767573.1875849998.round(5, half: :even).should eql(-767573.18758) + end end it "raises FloatDomainError for exceptional values with a half option" do |