From 74696ffd9625e4dca43aa010d71020f10030de24 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 2 Sep 2015 22:29:01 +0900 Subject: Float << and >> should be more compatible to Fixnum --- mrblib/numeric.rb | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'mrblib/numeric.rb') diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb index 206185e78..6e4c5027f 100644 --- a/mrblib/numeric.rb +++ b/mrblib/numeric.rb @@ -165,12 +165,30 @@ class Float # floats should be compatible to integers. def >> other n = self.to_i - other.to_i.times { n /= 2 } - n + other = other.to_i + if other < 0 + n << -other + else + other.times { n /= 2 } + if n.abs < 1 + if n >= 0 + 0 + else + -1 + end + else + n.to_i + end + end end def << other n = self.to_i - other.to_i.times { n *= 2 } - n.to_i + other = other.to_i + if other < 0 + n >> -other + else + other.times { n *= 2 } + n + end end end -- cgit v1.2.3