|
103 | 103 | 5.55.round(1, half: :up).should eql(5.6)
|
104 | 104 | 5.55.round(1, half: :down).should eql(5.5)
|
105 | 105 | 5.55.round(1, half: :even).should eql(5.6)
|
| 106 | + -5.55.round(1, half: nil).should eql(-5.6) |
| 107 | + -5.55.round(1, half: :up).should eql(-5.6) |
| 108 | + -5.55.round(1, half: :down).should eql(-5.5) |
| 109 | + -5.55.round(1, half: :even).should eql(-5.6) |
| 110 | + end |
| 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 | + |
| 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. |
| 144 | + it "does not lose precision during the rounding process" do |
| 145 | + 767573.1875850001.round(5, half: nil).should eql(767573.18759) |
| 146 | + 767573.1875850001.round(5, half: :up).should eql(767573.18759) |
| 147 | + 767573.1875850001.round(5, half: :down).should eql(767573.18759) |
| 148 | + 767573.1875850001.round(5, half: :even).should eql(767573.18759) |
| 149 | + -767573.1875850001.round(5, half: nil).should eql(-767573.18759) |
| 150 | + -767573.1875850001.round(5, half: :up).should eql(-767573.18759) |
| 151 | + -767573.1875850001.round(5, half: :down).should eql(-767573.18759) |
| 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) |
| 161 | + 767573.1875849998.round(5, half: nil).should eql(767573.18758) |
| 162 | + 767573.1875849998.round(5, half: :up).should eql(767573.18758) |
| 163 | + 767573.1875849998.round(5, half: :down).should eql(767573.18758) |
| 164 | + 767573.1875849998.round(5, half: :even).should eql(767573.18758) |
| 165 | + -767573.1875849998.round(5, half: nil).should eql(-767573.18758) |
| 166 | + -767573.1875849998.round(5, half: :up).should eql(-767573.18758) |
| 167 | + -767573.1875849998.round(5, half: :down).should eql(-767573.18758) |
| 168 | + -767573.1875849998.round(5, half: :even).should eql(-767573.18758) |
| 169 | + end |
106 | 170 | end
|
107 | 171 |
|
108 | 172 | it "raises FloatDomainError for exceptional values with a half option" do
|
|
0 commit comments