|
109 | 109 | -5.55.round(1, half: :even).should eql(-5.6)
|
110 | 110 | end
|
111 | 111 |
|
| 112 | + it "preserves cases where neighbouring floating pointer number increase the decimal places" do |
| 113 | + 4.8100000000000005.round(5, half: nil).should eql(4.81) |
| 114 | + 4.8100000000000005.round(5, half: :up).should eql(4.81) |
| 115 | + 4.8100000000000005.round(5, half: :down).should eql(4.81) |
| 116 | + 4.8100000000000005.round(5, half: :even).should eql(4.81) |
| 117 | + -4.8100000000000005.round(5, half: nil).should eql(-4.81) |
| 118 | + -4.8100000000000005.round(5, half: :up).should eql(-4.81) |
| 119 | + -4.8100000000000005.round(5, half: :down).should eql(-4.81) |
| 120 | + -4.8100000000000005.round(5, half: :even).should eql(-4.81) |
| 121 | + 4.81.round(5, half: nil).should eql(4.81) |
| 122 | + 4.81.round(5, half: :up).should eql(4.81) |
| 123 | + 4.81.round(5, half: :down).should eql(4.81) |
| 124 | + 4.81.round(5, half: :even).should eql(4.81) |
| 125 | + -4.81.round(5, half: nil).should eql(-4.81) |
| 126 | + -4.81.round(5, half: :up).should eql(-4.81) |
| 127 | + -4.81.round(5, half: :down).should eql(-4.81) |
| 128 | + -4.81.round(5, half: :even).should eql(-4.81) |
| 129 | + 4.809999999999999.round(5, half: nil).should eql(4.81) |
| 130 | + 4.809999999999999.round(5, half: :up).should eql(4.81) |
| 131 | + 4.809999999999999.round(5, half: :down).should eql(4.81) |
| 132 | + 4.809999999999999.round(5, half: :even).should eql(4.81) |
| 133 | + -4.809999999999999.round(5, half: nil).should eql(-4.81) |
| 134 | + -4.809999999999999.round(5, half: :up).should eql(-4.81) |
| 135 | + -4.809999999999999.round(5, half: :down).should eql(-4.81) |
| 136 | + -4.809999999999999.round(5, half: :even).should eql(-4.81) |
| 137 | + end |
| 138 | + |
112 | 139 | ruby_bug "", ""..."3.2" do
|
| 140 | + # These numbers are neighbouring floating point numbers round a |
| 141 | + # precise value. They test that the rounding modes work correctly |
| 142 | + # round that value and precision is not lost which might cause |
| 143 | + # incorrect results. |
113 | 144 | it "does not lose precision during the rounding process" do
|
114 | 145 | 767573.1875850001.round(5, half: nil).should eql(767573.18759)
|
115 | 146 | 767573.1875850001.round(5, half: :up).should eql(767573.18759)
|
|
119 | 150 | -767573.1875850001.round(5, half: :up).should eql(-767573.18759)
|
120 | 151 | -767573.1875850001.round(5, half: :down).should eql(-767573.18759)
|
121 | 152 | -767573.1875850001.round(5, half: :even).should eql(-767573.18759)
|
| 153 | + 767573.187585.round(5, half: nil).should eql(767573.18759) |
| 154 | + 767573.187585.round(5, half: :up).should eql(767573.18759) |
| 155 | + 767573.187585.round(5, half: :down).should eql(767573.18758) |
| 156 | + 767573.187585.round(5, half: :even).should eql(767573.18758) |
| 157 | + -767573.187585.round(5, half: nil).should eql(-767573.18759) |
| 158 | + -767573.187585.round(5, half: :up).should eql(-767573.18759) |
| 159 | + -767573.187585.round(5, half: :down).should eql(-767573.18758) |
| 160 | + -767573.187585.round(5, half: :even).should eql(-767573.18758) |
122 | 161 | 767573.1875849998.round(5, half: nil).should eql(767573.18758)
|
123 | 162 | 767573.1875849998.round(5, half: :up).should eql(767573.18758)
|
124 | 163 | 767573.1875849998.round(5, half: :down).should eql(767573.18758)
|
|
0 commit comments