File tree Expand file tree Collapse file tree 2 files changed +9
-9
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -155,7 +155,7 @@ def chr(enc=undefined)
155
155
String . from_codepoint self , enc
156
156
end
157
157
158
- def round ( ndigits = undefined )
158
+ def round ( ndigits = undefined , half : nil )
159
159
return self if undefined . equal? ndigits
160
160
161
161
if Float === ndigits && ndigits . infinite?
@@ -165,9 +165,7 @@ def round(ndigits=undefined)
165
165
ndigits = Truffle ::Type . coerce_to_int ( ndigits )
166
166
Truffle ::Type . check_int ( ndigits )
167
167
168
- if ndigits > 0
169
- to_f
170
- elsif ndigits == 0
168
+ if ndigits >= 0
171
169
self
172
170
else
173
171
ndigits = -ndigits
@@ -181,7 +179,13 @@ def round(ndigits=undefined)
181
179
182
180
if kind_of? Integer and f . kind_of? Integer
183
181
x = self < 0 ? -self : self
184
- x = ( x + f / 2 ) / f * f
182
+ x = if ( half == :down )
183
+ ( x - f / 2 ) / f
184
+ else
185
+ ( x + f / 2 ) / f
186
+ end
187
+ x = ( x / 2 ) * 2 if half == :even
188
+ x = x * f
185
189
x = -x if self < 0
186
190
return x
187
191
end
You can’t perform that action at this time.
0 commit comments