summaryrefslogtreecommitdiffhomepage
path: root/mrblib/numeric.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2015-09-02 22:29:01 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2015-09-02 22:29:01 +0900
commit74696ffd9625e4dca43aa010d71020f10030de24 (patch)
treeeaea8d69d1645eef12b040b8532b504b6ba9d5c6 /mrblib/numeric.rb
parent6ddd79fd0ebfd88a9b36be08d509e665a9322567 (diff)
downloadmruby-74696ffd9625e4dca43aa010d71020f10030de24.tar.gz
mruby-74696ffd9625e4dca43aa010d71020f10030de24.zip
Float << and >> should be more compatible to Fixnum
Diffstat (limited to 'mrblib/numeric.rb')
-rw-r--r--mrblib/numeric.rb26
1 files changed, 22 insertions, 4 deletions
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