bitint 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b4702d20c7d5f3523dda0748265809d4d581ba33a217ac33ca116c82062fed5
4
- data.tar.gz: c710ff424901df06d602dc2f29b5860664583320289ea19a10cdf752eaba5980
3
+ metadata.gz: 66e650638e0715aa47439d6fc808da63ab437cf8861b2d309c5205a44427ab24
4
+ data.tar.gz: 72dccf88fd548cfea40033fc32f1ff67d0408dff5c51fb67b61e64f663486921
5
5
  SHA512:
6
- metadata.gz: 34c75a6b2b3ddfbdd910ffba7273a657a6d4486af4d7535325446fa430ac5acce4c9bf7e6475d2b53b31d4c194eabd46a58dfb6860b855cd6728d96ba32cace7
7
- data.tar.gz: e396e8080ef6ebef611d5c300863b9771e97d1552f8d690e48569756090c7c865edcf86e8721dad0e6bbb3b0108933becbbe5b7300a834008eaa65c87148d582
6
+ metadata.gz: e0896c0813dd92ada9c2fda9c9a7cd72f03db1c7bce0f8729289b12ab564edc25d8369ae6a48109b35b6a23134612aa516b543e36c6abf99decbe1dcbf09ce24
7
+ data.tar.gz: 14489ac974de4591940baefc17516bffbf2bcf96ffb4f7c037aa73e836ba60f65f0edcbfb284f61548a5c021ca5917043b831292bfd48c942fa7d7617aa7f4ad
data/lib/bitint/bitint.rb CHANGED
@@ -211,25 +211,6 @@ class BitInt < Numeric
211
211
  # Modulos +self+ by +rhs+.
212
212
  def %(rhs) = self.class.new(@int % rhs.to_i)
213
213
 
214
- # Raises +self+ to the +rhs+th power.
215
- # Note that `Numeric` only defines `.to_int` (not `.to_i`)
216
- def **(rhs) = self.class.new((@int ** rhs.to_i).to_int)
217
-
218
- # Shifts +self+ left by +rhs+ bits.
219
- def <<(rhs) = self.class.new(@int << rhs.to_i)
220
-
221
- # Shifts +self+ right by +rhs+ bits.
222
- def >>(rhs) = self.class.new(@int >> rhs.to_i)
223
-
224
- # Bitwise ANDs +self+ and +rhs+.
225
- def &(rhs) = self.class.new(@int & rhs.to_i)
226
-
227
- # Bitwise ORs +self+ and +rhs+.
228
- def |(rhs) = self.class.new(@int | rhs.to_i)
229
-
230
- # Bitwise XORs +self+ and +rhs+.
231
- def ^(rhs) = self.class.new(@int ^ rhs.to_i)
232
-
233
214
  # :section:
234
215
 
235
216
  # Returns whether +self+ is a positive integer. Zero is not positive.
@@ -254,6 +235,27 @@ class BitInt < Numeric
254
235
  # :section: Bit-level operations #
255
236
  ##################################
256
237
 
238
+ # Raises +self+ to the +rhs+th power.
239
+ #--
240
+ # Note that `Numeric` only defines `.to_int` (not `.to_i`)
241
+ #++
242
+ def **(rhs) = self.class.new((@int ** rhs.to_i).to_int)
243
+
244
+ # Shifts +self+ left by +rhs+ bits.
245
+ def <<(rhs) = self.class.new(@int << rhs.to_i)
246
+
247
+ # Shifts +self+ right by +rhs+ bits.
248
+ def >>(rhs) = self.class.new(@int >> rhs.to_i)
249
+
250
+ # Bitwise ANDs +self+ and +rhs+.
251
+ def &(rhs) = self.class.new(@int & rhs.to_i)
252
+
253
+ # Bitwise ORs +self+ and +rhs+.
254
+ def |(rhs) = self.class.new(@int | rhs.to_i)
255
+
256
+ # Bitwise XORs +self+ and +rhs+.
257
+ def ^(rhs) = self.class.new(@int ^ rhs.to_i)
258
+
257
259
  # Gets the bit at index +idx+ or returns +nil+.
258
260
  #
259
261
  # This is equivalent to +Integer#[]+
@@ -267,39 +269,33 @@ class BitInt < Numeric
267
269
  def size = (self.class::BITS / 8.0).ceil
268
270
 
269
271
 
270
- PACK_FMT = {
271
- [:native, 8, false].freeze => 'C',
272
- [:native, 16, false].freeze => 'S',
273
- [:native, 32, false].freeze => 'L',
274
- [:native, 64, false].freeze => 'Q',
275
- [:native, 8, true].freeze => 'c',
276
- [:native, 16, true].freeze => 's',
277
- [:native, 32, true].freeze => 'l',
278
- [:native, 64, true].freeze => 'q',
279
-
280
- }.freeze
281
- private_constant :PACK_FMT
282
-
283
- def bytes(endian = :native)
284
- size = {
285
- 8 => 'C',
286
- 16 => 'S',
287
- 32 => 'L',
288
- 64 => 'Q'
289
- }[self.class::BITS] or raise ArgumentError, "bytes only works for 8, 16, 32, or 64 rn." or raise ArgumentError, "endian must be :big, :little, or :native"
290
- size = {8=>'C', 16=>}
291
- size = case self.class::BITS
292
- when 8 then 'C'
293
- when 8 then 'C'
294
- # sprintf "%0#{self.class::BYTES * 2}x",
295
- # mask = self.class::MASK_CHAR or raise ArgumentError, "bytes only works (rn) on "
296
- # pack_char = self.class.pack_Char
297
- # case endian
298
- # when :native then
299
- end
300
- end
301
-
302
-
303
- (-128..127).each do |n|
304
- puts (BitInt::I(8).new(n)).to_s(2)
272
+ # PACK_FMT = {
273
+ # [:native, 8, false].freeze => 'C',
274
+ # [:native, 16, false].freeze => 'S',
275
+ # [:native, 32, false].freeze => 'L',
276
+ # [:native, 64, false].freeze => 'Q',
277
+ # [:native, 8, true].freeze => 'c',
278
+ # [:native, 16, true].freeze => 's',
279
+ # [:native, 32, true].freeze => 'l',
280
+ # [:native, 64, true].freeze => 'q',
281
+ # }.freeze
282
+ # private_constant :PACK_FMT
283
+
284
+ # def bytes(endian = :native)
285
+ # size = {
286
+ # 8 => 'C',
287
+ # 16 => 'S',
288
+ # 32 => 'L',
289
+ # 64 => 'Q'
290
+ # }[self.class::BITS] or raise ArgumentError, "bytes only works for 8, 16, 32, or 64 rn." or raise ArgumentError, "endian must be :big, :little, or :native"
291
+ # size = {8=>'C', 16=>}
292
+ # size = case self.class::BITS
293
+ # when 8 then 'C'
294
+ # when 8 then 'C'
295
+ # # sprintf "%0#{self.class::BYTES * 2}x",
296
+ # # mask = self.class::MASK_CHAR or raise ArgumentError, "bytes only works (rn) on "
297
+ # # pack_char = self.class.pack_Char
298
+ # # case endian
299
+ # # when :native then
300
+ # end
305
301
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  class BitInt
4
4
  # The current version of BitInt.
5
- VERSION = '0.5.0'
5
+ VERSION = '0.5.2'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Westerman