Skip to content

Commit 144365c

Browse files
aardvark179chrisseaton
authored andcommitted
Fix Integer truncate to match 2.6.
1 parent f0b9c70 commit 144365c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

spec/tags/core/integer/truncate_tags.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/main/ruby/truffleruby/core/integer.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939

4040
class Integer < Numeric
4141

42-
alias_method :truncate, :to_i
43-
4442
# Have a copy in Integer of the Numeric version, as MRI does
4543
public :remainder
4644

@@ -132,6 +130,14 @@ def times
132130
self
133131
end
134132

133+
def truncate(precision = 0)
134+
if precision >= 0
135+
self
136+
else
137+
round(precision, half: :down)
138+
end
139+
end
140+
135141
def chr(enc=undefined)
136142
if self < 0 || (self & 0xffff_ffff) != self
137143
raise RangeError, "#{self} is outside of the valid character range"
@@ -180,7 +186,7 @@ def round(ndigits=undefined, half: nil)
180186
if kind_of? Integer and f.kind_of? Integer
181187
x = self < 0 ? -self : self
182188
x = if (half == :down)
183-
(x - f / 2) / f
189+
(x) / f
184190
else
185191
(x + f / 2) / f
186192
end

0 commit comments

Comments
 (0)