From efebbbbf260e8ac5b8efbd0d4336a777cfeac514 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 23 Nov 2016 09:45:50 +0900 Subject: Implement Float shift methods in C --- mrblib/numeric.rb | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'mrblib/numeric.rb') diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb index 6e4c5027f..17155bfd6 100644 --- a/mrblib/numeric.rb +++ b/mrblib/numeric.rb @@ -160,35 +160,7 @@ end # # ISO 15.2.9 class Float - include Integral # mruby special - since mruby integers may be upgraded to floats, # floats should be compatible to integers. - def >> other - n = self.to_i - 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 = other.to_i - if other < 0 - n >> -other - else - other.times { n *= 2 } - n - end - end + include Integral end -- cgit v1.2.3 From b23fb45f9ce3cb12b33eecc9cab37adc2890f49f Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 20 Jan 2017 17:58:29 +0900 Subject: Integral#step without arg should loop forever as CRuby does. --- mrblib/numeric.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'mrblib/numeric.rb') diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb index 17155bfd6..975ad973f 100644 --- a/mrblib/numeric.rb +++ b/mrblib/numeric.rb @@ -100,11 +100,18 @@ module Integral # Calls the given block from +self+ to +num+ # incremented by +step+ (default 1). # - def step(num, step = 1, &block) + def step(num=nil, step=1, &block) raise ArgumentError, "step can't be 0" if step == 0 return to_enum(:step, num, step) unless block_given? i = if num.kind_of? Float then self.to_f else self end + if num == nil + while true + block.call(i) + i+=step + end + return self + end if step > 0 while i <= num block.call(i) -- cgit v1.2.3