Changeset 331 for EcnlProtoTool/trunk/mruby-1.3.0/mrblib/numeric.rb
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-1.3.0
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-1.3.0/mrblib/numeric.rb
r321 r331 101 101 # incremented by +step+ (default 1). 102 102 # 103 def step(num , step =1, &block)103 def step(num=nil, step=1, &block) 104 104 raise ArgumentError, "step can't be 0" if step == 0 105 105 return to_enum(:step, num, step) unless block_given? 106 106 107 107 i = if num.kind_of? Float then self.to_f else self end 108 if num == nil 109 while true 110 block.call(i) 111 i+=step 112 end 113 return self 114 end 108 115 if step > 0 109 116 while i <= num … … 161 168 # ISO 15.2.9 162 169 class Float 163 include Integral164 170 # mruby special - since mruby integers may be upgraded to floats, 165 171 # floats should be compatible to integers. 166 def >> other 167 n = self.to_i 168 other = other.to_i 169 if other < 0 170 n << -other 171 else 172 other.times { n /= 2 } 173 if n.abs < 1 174 if n >= 0 175 0 176 else 177 -1 178 end 179 else 180 n.to_i 181 end 182 end 183 end 184 def << other 185 n = self.to_i 186 other = other.to_i 187 if other < 0 188 n >> -other 189 else 190 other.times { n *= 2 } 191 n 192 end 193 end 172 include Integral 194 173 end
Note:
See TracChangeset
for help on using the changeset viewer.