bitint 0.5.0 → 0.5.1

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: e690f5f11cfde4a4dce6c24ba3ab3257c8785fafff6d5ec704ed8e00399af273
4
+ data.tar.gz: 48145ab578471740f982c95b351d0c1ebf6f9cd764f058ef574e35634f5e2224
5
5
  SHA512:
6
- metadata.gz: 34c75a6b2b3ddfbdd910ffba7273a657a6d4486af4d7535325446fa430ac5acce4c9bf7e6475d2b53b31d4c194eabd46a58dfb6860b855cd6728d96ba32cace7
7
- data.tar.gz: e396e8080ef6ebef611d5c300863b9771e97d1552f8d690e48569756090c7c865edcf86e8721dad0e6bbb3b0108933becbbe5b7300a834008eaa65c87148d582
6
+ metadata.gz: 062c4a993dd220775779555dd65bbe334a1b460533b76e59aec831994c3272be09897ce4c5711ae1585907f45c050eb8288eb1771a01db2c19aa032dc7d927b6
7
+ data.tar.gz: 3a48c9aae6a186c2057fe4f8ee4f4e88576084a6148c29cbc316de7d4c29db849ea9935a21ecb8dd2c1b62752b02110f2a16d55a2745f330c2a282c7da93033e
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,34 @@ 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
+
282
+ # }.freeze
283
+ # private_constant :PACK_FMT
284
+
285
+ # def bytes(endian = :native)
286
+ # size = {
287
+ # 8 => 'C',
288
+ # 16 => 'S',
289
+ # 32 => 'L',
290
+ # 64 => 'Q'
291
+ # }[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"
292
+ # size = {8=>'C', 16=>}
293
+ # size = case self.class::BITS
294
+ # when 8 then 'C'
295
+ # when 8 then 'C'
296
+ # # sprintf "%0#{self.class::BYTES * 2}x",
297
+ # # mask = self.class::MASK_CHAR or raise ArgumentError, "bytes only works (rn) on "
298
+ # # pack_char = self.class.pack_Char
299
+ # # case endian
300
+ # # when :native then
301
+ # end
305
302
  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.1'
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Westerman