bitint 0.6.1 → 0.7.0
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 +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +30 -0
- data/Steepfile +3 -3
- data/lib/bitint/base.rb +552 -0
- data/lib/bitint/bitint.rb +33 -300
- data/lib/bitint/constants.rb +18 -2
- data/lib/bitint/native.rb +99 -43
- data/lib/bitint/overflow_error.rb +15 -0
- data/lib/bitint/refinements.rb +17 -16
- data/lib/bitint/version.rb +3 -2
- data/lib/bitint.rb +3 -1
- data/sig/{bitint/version.rbs → bitint.rbs} +0 -1
- data/sig/generated/bitint/base.rbs +422 -0
- data/sig/generated/bitint/bitint.rbs +51 -0
- data/sig/generated/bitint/constants.rbs +33 -0
- data/sig/generated/bitint/native.rbs +74 -0
- data/sig/generated/bitint/overflow_error.rbs +12 -0
- data/sig/generated/bitint/refinements.rbs +72 -0
- data/sig/generated/bitint/version.rbs +6 -0
- metadata +14 -11
- data/sig/bitint/bitint.rbs +0 -62
- data/sig/bitint/error.rbs +0 -4
- data/sig/bitint/refinements.rb +0 -4
data/lib/bitint.rb
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
module BitInt
|
|
4
4
|
end
|
|
5
5
|
|
|
6
6
|
require_relative 'bitint/version'
|
|
7
|
+
require_relative 'bitint/base'
|
|
7
8
|
require_relative 'bitint/bitint'
|
|
8
9
|
require_relative 'bitint/refinements'
|
|
9
10
|
require_relative 'bitint/constants'
|
|
11
|
+
require_relative 'bitint/overflow_error'
|
|
10
12
|
require_relative 'bitint/native'
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
# Generated from lib/bitint/base.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module BitInt
|
|
4
|
+
# @abstract Subclasses must be created via `Base.create`
|
|
5
|
+
class Base < Numeric
|
|
6
|
+
@int: Integer
|
|
7
|
+
|
|
8
|
+
@wrap: bool
|
|
9
|
+
|
|
10
|
+
self.@signed: bool
|
|
11
|
+
|
|
12
|
+
self.@bits: Integer
|
|
13
|
+
|
|
14
|
+
self.@classes: Hash[[ Integer, bool ], Class]
|
|
15
|
+
|
|
16
|
+
BITS: Integer
|
|
17
|
+
|
|
18
|
+
BYTES: Integer
|
|
19
|
+
|
|
20
|
+
MASK: Integer
|
|
21
|
+
|
|
22
|
+
ZERO: Base
|
|
23
|
+
|
|
24
|
+
ONE: Base
|
|
25
|
+
|
|
26
|
+
MIN: Base
|
|
27
|
+
|
|
28
|
+
MAX: Base
|
|
29
|
+
|
|
30
|
+
BOUNDS: Range[Base]
|
|
31
|
+
|
|
32
|
+
# Creates a new {BitInt::Base} subclass.
|
|
33
|
+
#
|
|
34
|
+
# @param bits [Integer?] the amount of bits the subclass should have. Must be at least +1+.
|
|
35
|
+
# @param bytes [Integer?] convenience argument; if supplied, sets +bits+ to +bytes * 8+. Cannot be used with +bits+
|
|
36
|
+
# @param signed [bool] Whether the subclass is a signed.
|
|
37
|
+
#
|
|
38
|
+
# @return [singleton(Base)] A subclass of {BitInt::Base}; subclasses are cached, so repeated calls return the same subclass.
|
|
39
|
+
#
|
|
40
|
+
# @raise [ArgumentError] When +bits+ is negative or zero
|
|
41
|
+
# @raise [ArgumentError] If both +bits+ and +bytes+ are supplied
|
|
42
|
+
#
|
|
43
|
+
# === Example
|
|
44
|
+
# puts BitInt::Base.create(bits: 8, signed: true).new(128) #=> -127
|
|
45
|
+
# puts BitInt::Base.create(bytes: 1, signed: false).new(256) #=> 0
|
|
46
|
+
#
|
|
47
|
+
# @rbs (bits: Integer, signed: bool) -> untyped
|
|
48
|
+
# | (bytes: Integer, signed: bool) -> untyped
|
|
49
|
+
def self.create: (bits: Integer, signed: bool) -> untyped
|
|
50
|
+
| (bytes: Integer, signed: bool) -> untyped
|
|
51
|
+
|
|
52
|
+
# :stopdoc:
|
|
53
|
+
# @rbs (Integer, bool) -> void
|
|
54
|
+
def self.setup!: (Integer, bool) -> void
|
|
55
|
+
|
|
56
|
+
# Returns whether this class represents a signed integer.
|
|
57
|
+
#
|
|
58
|
+
# @abstract Only defined on subclasses
|
|
59
|
+
#
|
|
60
|
+
# === Example
|
|
61
|
+
# puts BitInt::U8.signed? #=> false
|
|
62
|
+
# puts BitInt::I8.signed? #=> true
|
|
63
|
+
#
|
|
64
|
+
# @rbs () -> bool
|
|
65
|
+
def self.signed?: () -> bool
|
|
66
|
+
|
|
67
|
+
# Returns whether this class represents an unsigned integer.
|
|
68
|
+
#
|
|
69
|
+
# @abstract Only defined on subclasses
|
|
70
|
+
#
|
|
71
|
+
# === Example
|
|
72
|
+
# puts BitInt::U8.unsigned? #=> true
|
|
73
|
+
# puts BitInt::I8.unsigned? #=> false
|
|
74
|
+
#
|
|
75
|
+
# @rbs () -> bool
|
|
76
|
+
def self.unsigned?: () -> bool
|
|
77
|
+
|
|
78
|
+
# Returns a debugging string representation of this class
|
|
79
|
+
#
|
|
80
|
+
# If the class is one of the builtins (eg +BitInt::U16+), it uses its name
|
|
81
|
+
# as the string, otherwise it uses a debugging representation
|
|
82
|
+
#
|
|
83
|
+
# === Example
|
|
84
|
+
# p BitInt::U16 #=> BitInt::U16
|
|
85
|
+
# p BitInt::U(17) #=> #<BitInt::Base @bits=17 @signed=false>
|
|
86
|
+
#
|
|
87
|
+
# @rbs () -> String
|
|
88
|
+
def self.inspect: () -> String
|
|
89
|
+
|
|
90
|
+
alias self.to_s self.inspect
|
|
91
|
+
|
|
92
|
+
# Wraps an +integer+ to be within the bounds of +self+
|
|
93
|
+
#
|
|
94
|
+
# @param integer [Integer] the integer to wrap
|
|
95
|
+
# @return [Integer] an integer guaranteed to be within +self::BOUNDS+.
|
|
96
|
+
#
|
|
97
|
+
# @abstract Only defined on subclasses
|
|
98
|
+
#
|
|
99
|
+
# === Example
|
|
100
|
+
# puts BitInt::I8.wrap(127) #=> 127
|
|
101
|
+
# puts BitInt::I8.wrap(128) #=> -128
|
|
102
|
+
# puts BitInt::I8.wrap(0xFF_FF_FF_FF_FF) #=> -1
|
|
103
|
+
#
|
|
104
|
+
# @rbs (Integer) -> Integer
|
|
105
|
+
def self.wrap: (Integer) -> Integer
|
|
106
|
+
|
|
107
|
+
# Check to see if +integer+ is in bounds for +self+
|
|
108
|
+
#
|
|
109
|
+
# @abstract Only defined on subclasses
|
|
110
|
+
#
|
|
111
|
+
# @param integer [Integer] the integer to check
|
|
112
|
+
# @return [bool] whether the integer is in bounds
|
|
113
|
+
#
|
|
114
|
+
# === Example
|
|
115
|
+
# puts BitInt::I16.in_bounds?(32767) #=> true
|
|
116
|
+
# puts BitInt::I16.in_bounds?(32768) #=> false
|
|
117
|
+
# puts BitInt::U32.in_bounds?(-1) #=> false
|
|
118
|
+
#
|
|
119
|
+
# @rbs (Integer) -> bool
|
|
120
|
+
def self.in_bounds?: (Integer) -> bool
|
|
121
|
+
|
|
122
|
+
# Creates a new instance with the +integer+.
|
|
123
|
+
#
|
|
124
|
+
# @param integer [Integer] the integer to use
|
|
125
|
+
# @param wrap [bool] changes how {Base.in_bounds? out-of-bounds} integers are handled. When true,
|
|
126
|
+
# they're {Base.wrap wrapped}; when false, an +OverflowError+ to be raised.
|
|
127
|
+
# @raise [OverflowError] raised when +wrap+ is +false+ and +integer+ is out of bounds.
|
|
128
|
+
#
|
|
129
|
+
# === Example
|
|
130
|
+
# puts BitInt::U8.new(27) #=> 27
|
|
131
|
+
# puts BitInt::U8.new(-1) #=> 255
|
|
132
|
+
# puts BitInt::U8.new(-1, wrap: false) #=> OverflowError
|
|
133
|
+
# puts BitInt::I8.new(255) #=> -1
|
|
134
|
+
#
|
|
135
|
+
# @rbs (Integer, ?wrap: boolish) -> void
|
|
136
|
+
def initialize: (Integer, ?wrap: boolish) -> void
|
|
137
|
+
|
|
138
|
+
# Returns the underlying integer.
|
|
139
|
+
#
|
|
140
|
+
# @rbs () -> Integer
|
|
141
|
+
def to_i: () -> Integer
|
|
142
|
+
|
|
143
|
+
alias to_int to_i
|
|
144
|
+
|
|
145
|
+
# Converts +self+ to a +Float+.
|
|
146
|
+
#
|
|
147
|
+
# @rbs () -> Float
|
|
148
|
+
def to_f: () -> Float
|
|
149
|
+
|
|
150
|
+
# Converts +self+ to a +Rational+.
|
|
151
|
+
#
|
|
152
|
+
# @rbs () -> Rational
|
|
153
|
+
def to_r: () -> Rational
|
|
154
|
+
|
|
155
|
+
# Converts +self+ to a +String+.
|
|
156
|
+
#
|
|
157
|
+
# If no +base+ is given, it just returns a normal String in base 10.
|
|
158
|
+
# If a base is given, a string padded with `0`s will be returned.
|
|
159
|
+
#
|
|
160
|
+
# === Examples
|
|
161
|
+
# puts BitInt::U16.new(1234).to_s #=> 1234
|
|
162
|
+
# puts BitInt::U16.new(1234).to_s(16) #=> 04d2
|
|
163
|
+
#
|
|
164
|
+
# @rbs (?int? base) -> String
|
|
165
|
+
def to_s: (?int? base) -> String
|
|
166
|
+
|
|
167
|
+
alias inspect to_s
|
|
168
|
+
|
|
169
|
+
# Returns a base-16 string of +self+. Equivalent to +to_s(16)+.
|
|
170
|
+
#
|
|
171
|
+
# If +upper: true+ is passed, returns an upper-case version.
|
|
172
|
+
#
|
|
173
|
+
# === Examples
|
|
174
|
+
# puts BitInt::U16.new(1234).hex #=> 04d2
|
|
175
|
+
# puts BitInt::U16.new(1234, upper: true).hex #=> 04D2
|
|
176
|
+
#
|
|
177
|
+
# @rbs (?upper: boolish) -> String
|
|
178
|
+
def hex: (?upper: boolish) -> String
|
|
179
|
+
|
|
180
|
+
# Returns a base-8 string of +self+. Equivalent to +to_s(8)+.
|
|
181
|
+
#
|
|
182
|
+
# === Example
|
|
183
|
+
# puts BitInt::U16.new(12345).oct #=> 30071
|
|
184
|
+
#
|
|
185
|
+
# @rbs () -> String
|
|
186
|
+
def oct: () -> String
|
|
187
|
+
|
|
188
|
+
# Returns a base-2 string of +self+. Equivalent to +to_s(2)+.
|
|
189
|
+
#
|
|
190
|
+
# === Example
|
|
191
|
+
# puts BitInt::U16.new(54321).bin #=> 0000010011010010
|
|
192
|
+
#
|
|
193
|
+
# @rbs () -> String
|
|
194
|
+
def bin: () -> String
|
|
195
|
+
|
|
196
|
+
# Converts +other+ to an instance of +self+, and returns a tuple of +[<converted>, self]+
|
|
197
|
+
#
|
|
198
|
+
# @rbs (int) -> [instance, self]
|
|
199
|
+
def coerce: (int) -> [ instance, self ]
|
|
200
|
+
|
|
201
|
+
# Checks to see if +rhs+ is equal to +selF+
|
|
202
|
+
#
|
|
203
|
+
# === Example
|
|
204
|
+
# U64 = BitInt::U(64)
|
|
205
|
+
# twelve = U64.new(12)
|
|
206
|
+
#
|
|
207
|
+
# # Behaves as you'd expect.
|
|
208
|
+
# puts twelve == U64.new(12) #=> true
|
|
209
|
+
# puts twelve == U64.new(13) #=> false
|
|
210
|
+
# puts twelve == 12 #=> true
|
|
211
|
+
# puts twelve == 12.0 #=> true
|
|
212
|
+
# puts twelve == 13 #=> false
|
|
213
|
+
# puts twelve == Object.new #=> false
|
|
214
|
+
#
|
|
215
|
+
# @rbs (untyped) -> boolish
|
|
216
|
+
def ==: (untyped) -> boolish
|
|
217
|
+
|
|
218
|
+
# Checks to see if +rhs+ is another +BitInt::Base+ of the same class, and
|
|
219
|
+
# have the same contents.
|
|
220
|
+
#
|
|
221
|
+
# @rbs (untyped) -> bool
|
|
222
|
+
def eql?: (untyped) -> bool
|
|
223
|
+
|
|
224
|
+
# Returns a hash code for this class.
|
|
225
|
+
#
|
|
226
|
+
# @rbs () -> Integer
|
|
227
|
+
def hash: () -> Integer
|
|
228
|
+
|
|
229
|
+
# Always return +true+, as +BitInt::Base+s are always integers.
|
|
230
|
+
#
|
|
231
|
+
# @rbs () -> true
|
|
232
|
+
def integer?: () -> true
|
|
233
|
+
|
|
234
|
+
# @rbs (Integer, ?wrap: bool) -> instance
|
|
235
|
+
private def new_instance: (Integer, ?wrap: bool) -> instance
|
|
236
|
+
|
|
237
|
+
# Numerically negates +self+.
|
|
238
|
+
#
|
|
239
|
+
# @rbs () -> instance
|
|
240
|
+
def -@: () -> instance
|
|
241
|
+
|
|
242
|
+
# Compares +self+ to +rhs+.
|
|
243
|
+
#
|
|
244
|
+
# @rbs (_ToI) -> (-1 | 0 | 1)
|
|
245
|
+
# | (untyped) -> Integer?
|
|
246
|
+
def <=>: (_ToI) -> (-1 | 0 | 1)
|
|
247
|
+
| (untyped) -> Integer?
|
|
248
|
+
|
|
249
|
+
# Adds +self+ to +rhs+.
|
|
250
|
+
#
|
|
251
|
+
# @rbs (int) -> instance
|
|
252
|
+
def +: (int) -> instance
|
|
253
|
+
|
|
254
|
+
# Subtracts +rhs+ from +self+.
|
|
255
|
+
#
|
|
256
|
+
# @rbs (int) -> instance
|
|
257
|
+
def -: (int) -> instance
|
|
258
|
+
|
|
259
|
+
# Multiplies +self+ by +rhs+.
|
|
260
|
+
#
|
|
261
|
+
# @rbs (int) -> instance
|
|
262
|
+
def *: (int) -> instance
|
|
263
|
+
|
|
264
|
+
# Divides +self+ by +rhs+.
|
|
265
|
+
#
|
|
266
|
+
# @rbs (int) -> instance
|
|
267
|
+
def /: (int) -> instance
|
|
268
|
+
|
|
269
|
+
# Modulos +self+ by +rhs+.
|
|
270
|
+
#
|
|
271
|
+
# @rbs (int) -> instance
|
|
272
|
+
def %: (int) -> instance
|
|
273
|
+
|
|
274
|
+
# Raises +self+ to the +rhs+th power.
|
|
275
|
+
#
|
|
276
|
+
# @rbs (int) -> instance
|
|
277
|
+
def **: (int) -> instance
|
|
278
|
+
|
|
279
|
+
# Returns whether +self+ is a positive integer. Zero is not positive.
|
|
280
|
+
#
|
|
281
|
+
# @rbs () -> bool
|
|
282
|
+
def positive?: () -> bool
|
|
283
|
+
|
|
284
|
+
# Return whether +self+ is a negative integer. Zero is not negative.
|
|
285
|
+
#
|
|
286
|
+
# @rbs () -> bool
|
|
287
|
+
def negative?: () -> bool
|
|
288
|
+
|
|
289
|
+
# Returns whether +self+ is zero.
|
|
290
|
+
#
|
|
291
|
+
# @rbs () -> bool
|
|
292
|
+
def zero?: () -> bool
|
|
293
|
+
|
|
294
|
+
# Returns a falsey value if zero, otherwise returns +self+.
|
|
295
|
+
#
|
|
296
|
+
# @rbs () -> self?
|
|
297
|
+
def nonzero?: () -> self?
|
|
298
|
+
|
|
299
|
+
# Checks to see if +self+ is even.
|
|
300
|
+
#
|
|
301
|
+
# @rbs () -> bool
|
|
302
|
+
def even?: () -> bool
|
|
303
|
+
|
|
304
|
+
# Checks to see if +self+ is odd.
|
|
305
|
+
#
|
|
306
|
+
# @rbs () -> bool
|
|
307
|
+
def odd?: () -> bool
|
|
308
|
+
|
|
309
|
+
# Same as +Integer#times+, but returns instances of +self+.
|
|
310
|
+
#
|
|
311
|
+
# @rbs () -> Enumerator[instance, self]
|
|
312
|
+
# | () { (instance) -> void } -> self
|
|
313
|
+
def times: () -> Enumerator[instance, self]
|
|
314
|
+
| () { (instance) -> void } -> self
|
|
315
|
+
|
|
316
|
+
# Same as +Integer#downto+, but returns instances of +self+.
|
|
317
|
+
#
|
|
318
|
+
# @rbs (Numeric) -> Enumerator[instance, self]
|
|
319
|
+
# | (Numeric) { (instance) -> void } -> self
|
|
320
|
+
def downto: (Numeric) -> Enumerator[instance, self]
|
|
321
|
+
| (Numeric) { (instance) -> void } -> self
|
|
322
|
+
|
|
323
|
+
# Same as +Integer#downto+, but returns instances of +self+.
|
|
324
|
+
#
|
|
325
|
+
# @rbs (Numeric) -> Enumerator[instance, self]
|
|
326
|
+
# | (Numeric) { (instance) -> void } -> self
|
|
327
|
+
def upto: (Numeric) -> Enumerator[instance, self]
|
|
328
|
+
| (Numeric) { (instance) -> void } -> self
|
|
329
|
+
|
|
330
|
+
# Gets the next value, or throws a {OverFlowError} if at the top.
|
|
331
|
+
#
|
|
332
|
+
# @rbs () -> instance
|
|
333
|
+
def succ: () -> instance
|
|
334
|
+
|
|
335
|
+
# Gets the next value, or throws a {OverFlowError} if at the top.
|
|
336
|
+
#
|
|
337
|
+
# @rbs () -> instance
|
|
338
|
+
def pred: () -> instance
|
|
339
|
+
|
|
340
|
+
# Bitwise negates +self+.
|
|
341
|
+
#
|
|
342
|
+
# @rbs () -> instance
|
|
343
|
+
def ~: () -> instance
|
|
344
|
+
|
|
345
|
+
# Shifts +self+ left by +rhs+ bits.
|
|
346
|
+
#
|
|
347
|
+
# @rbs (int) -> instance
|
|
348
|
+
def <<: (int) -> instance
|
|
349
|
+
|
|
350
|
+
# Shifts +self+ right by +rhs+ bits.
|
|
351
|
+
#
|
|
352
|
+
# @rbs (int) -> instance
|
|
353
|
+
def >>: (int) -> instance
|
|
354
|
+
|
|
355
|
+
# Bitwise ANDs +self+ and +rhs+.
|
|
356
|
+
#
|
|
357
|
+
# @rbs (int) -> instance
|
|
358
|
+
def &: (int) -> instance
|
|
359
|
+
|
|
360
|
+
# Bitwise ORs +self+ and +rhs+.
|
|
361
|
+
#
|
|
362
|
+
# @rbs (int) -> instance
|
|
363
|
+
def |: (int) -> instance
|
|
364
|
+
|
|
365
|
+
# Bitwise XORs +self+ and +rhs+.
|
|
366
|
+
#
|
|
367
|
+
# @rbs (int) -> instance
|
|
368
|
+
def ^: (int) -> instance
|
|
369
|
+
|
|
370
|
+
# Gets the bit at index +idx+ or returns +nil+.
|
|
371
|
+
#
|
|
372
|
+
# This is equivalent to +Integer#[]+
|
|
373
|
+
# @rbs (int, ?int) -> Integer?
|
|
374
|
+
# | (range[int]) -> Integer?
|
|
375
|
+
def []: (int, ?int) -> Integer?
|
|
376
|
+
| (range[int]) -> Integer?
|
|
377
|
+
|
|
378
|
+
# Returns true if any bit in `mask` is set in +self+.
|
|
379
|
+
#
|
|
380
|
+
# @rbs (int) -> bool
|
|
381
|
+
def anybits?: (int) -> bool
|
|
382
|
+
|
|
383
|
+
# Returns true if all bits in `mask` are set in +self+.
|
|
384
|
+
#
|
|
385
|
+
# @rbs (int) -> bool
|
|
386
|
+
def allbits?: (int) -> bool
|
|
387
|
+
|
|
388
|
+
# Returns true if no bits in `mask` are set in +self+.
|
|
389
|
+
#
|
|
390
|
+
# @rbs (int) -> bool
|
|
391
|
+
def nobits?: (int) -> bool
|
|
392
|
+
|
|
393
|
+
# Returns the amount of bits required to represent +self+
|
|
394
|
+
#
|
|
395
|
+
# Unlike +Integer#bit_length+, this never changes and is equivalent
|
|
396
|
+
# to +self.class::BITS+.
|
|
397
|
+
#
|
|
398
|
+
# @rbs () -> Integer
|
|
399
|
+
def bit_length: () -> Integer
|
|
400
|
+
|
|
401
|
+
# Returns the amount of bytes required to represent +self+
|
|
402
|
+
#
|
|
403
|
+
# This is equivalent to +self.class::BYTES+
|
|
404
|
+
#
|
|
405
|
+
# @rbs () -> Integer
|
|
406
|
+
def byte_length: () -> Integer
|
|
407
|
+
|
|
408
|
+
# Returns all the bytes that're used represent +self+
|
|
409
|
+
#
|
|
410
|
+
# @rbs (?:native | :big | :little) -> Array[U8]
|
|
411
|
+
def bytes: (?:native | :big | :little) -> Array[U8]
|
|
412
|
+
|
|
413
|
+
# Executes the block once for each byte in +self+.
|
|
414
|
+
#
|
|
415
|
+
# Bytes are converted to +U8+. If no block is given, returns an +Enumerator+
|
|
416
|
+
#
|
|
417
|
+
# @rbs (?:native | :big | :little) { (U8) -> void } -> self
|
|
418
|
+
# | (?:native | :big | :little) -> Enumerator[U8, self]
|
|
419
|
+
def each_byte: (?:native | :big | :little) { (U8) -> void } -> self
|
|
420
|
+
| (?:native | :big | :little) -> Enumerator[U8, self]
|
|
421
|
+
end
|
|
422
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Generated from lib/bitint/bitint.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module BitInt
|
|
4
|
+
# Helper to create new unsigned {BitInt::Base} classes.
|
|
5
|
+
#
|
|
6
|
+
# This method just wraps {Base.create}
|
|
7
|
+
#
|
|
8
|
+
# @param bits [Integer] number of bits; must be nonzero
|
|
9
|
+
# @return [subclass of Base] a +Class+ that inherits from +Base+
|
|
10
|
+
#
|
|
11
|
+
# === Example
|
|
12
|
+
# puts BitInt::U(16)::MAX #=> 65535
|
|
13
|
+
#
|
|
14
|
+
# @rbs (Integer) -> untyped
|
|
15
|
+
def self?.U: (Integer) -> untyped
|
|
16
|
+
|
|
17
|
+
alias unsigned U
|
|
18
|
+
|
|
19
|
+
# Helper to create new signed {BitInt::Base} classes.
|
|
20
|
+
#
|
|
21
|
+
# This method just wraps {Base.create}
|
|
22
|
+
#
|
|
23
|
+
# @param bits [Integer] number of bits; must be nonzero
|
|
24
|
+
# @return [subclass of Base] a +Class+ that inherits from +Base+
|
|
25
|
+
#
|
|
26
|
+
# === Example
|
|
27
|
+
# puts BitInt::I(16)::MAX #=> 32767
|
|
28
|
+
#
|
|
29
|
+
# @rbs (Integer) -> untyped
|
|
30
|
+
def self?.I: (Integer) -> untyped
|
|
31
|
+
|
|
32
|
+
alias signed I
|
|
33
|
+
|
|
34
|
+
alias S I
|
|
35
|
+
|
|
36
|
+
# Helper to create new {BitInt::Base} classes.
|
|
37
|
+
#
|
|
38
|
+
# This method just wraps {Base.create}.
|
|
39
|
+
#
|
|
40
|
+
# @param bits [Integer] number of bits; must be nonzero
|
|
41
|
+
# @param signed [bool] whether the subclass should be signed
|
|
42
|
+
# @return [subclass of Base] a +Class+ that inherits from +Base+
|
|
43
|
+
#
|
|
44
|
+
# === Example
|
|
45
|
+
# puts BitInt[9]::MAX #=> 511
|
|
46
|
+
# puts BitInt[9, signed: false]::MAX #=> 511
|
|
47
|
+
# puts BitInt[9, signed: true]::MAX #=> 255
|
|
48
|
+
#
|
|
49
|
+
# @rbs (Integer, ?signed: bool) -> untyped
|
|
50
|
+
def self?.[]: (Integer, ?signed: bool) -> untyped
|
|
51
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Generated from lib/bitint/constants.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module BitInt
|
|
4
|
+
class U8 < Base
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class U16 < Base
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class U32 < Base
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class U64 < Base
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class U128 < Base
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class I8 < Base
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class I16 < Base
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class I32 < Base
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class I64 < Base
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class I128 < Base
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Generated from lib/bitint/native.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module BitInt
|
|
4
|
+
# +BitInt+s that correspond to underlying C integer sizes.
|
|
5
|
+
module Native
|
|
6
|
+
# On big-endian systems, the unpack will equal +0x00AA+.
|
|
7
|
+
IS_LITTLE_ENDIAN: untyped
|
|
8
|
+
|
|
9
|
+
# Helper method to fetch the endianness of the underlying system.
|
|
10
|
+
#
|
|
11
|
+
# @rbs () -> (:little | :big)
|
|
12
|
+
def self?.endianness: () -> (:little | :big)
|
|
13
|
+
|
|
14
|
+
alias self.endian self.endianness
|
|
15
|
+
|
|
16
|
+
# Returns +true+ when on a little endian system.
|
|
17
|
+
#
|
|
18
|
+
# @rbs () -> bool
|
|
19
|
+
def self?.little_endian?: () -> bool
|
|
20
|
+
|
|
21
|
+
# Returns +true+ when on a big endian system.
|
|
22
|
+
#
|
|
23
|
+
# @rbs () -> bool
|
|
24
|
+
def self?.big_endian?: () -> bool
|
|
25
|
+
|
|
26
|
+
class SCHAR < Base
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class UCHAR < Base
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class SHORT < Base
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class USHORT < Base
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class INT < Base
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class UINT < Base
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
class LONG < Base
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class ULONG < Base
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class LONG_LONG < Base
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
class ULONG_LONG < Base
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
class VOIDP < Base
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
class SIZE_T < Base
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
class SSIZE_T < Base
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
class PTRDIFF_T < Base
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
class INTPTR_T < Base
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
class UINTPTR_T < Base
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Generated from lib/bitint/overflow_error.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module BitInt
|
|
4
|
+
# Indicates that +BitInt::Base.create+ was called with an integer that was too large.
|
|
5
|
+
class OverflowError < RuntimeError
|
|
6
|
+
attr_reader integer: untyped
|
|
7
|
+
|
|
8
|
+
attr_reader range: untyped
|
|
9
|
+
|
|
10
|
+
def initialize: (untyped integer, untyped range) -> untyped
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Generated from lib/bitint/refinements.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module BitInt
|
|
4
|
+
# Refinements to +Integer+ for easy "+BitInt+ literals" (eg +puts(12.u8)+)
|
|
5
|
+
module Refinements
|
|
6
|
+
# Converts +self+ into an unsigned +bits+-bit integer.
|
|
7
|
+
#
|
|
8
|
+
# Any additional arguments are forwarded to +BitInt#new+
|
|
9
|
+
#
|
|
10
|
+
# === Examples
|
|
11
|
+
# puts BitInt::U(16)::MAX #=> 65535
|
|
12
|
+
#
|
|
13
|
+
def u: (untyped bits) -> untyped
|
|
14
|
+
|
|
15
|
+
# Converts +self+ into a signed +bits+-bit integer.
|
|
16
|
+
#
|
|
17
|
+
# If no arguments are given, this instead forwards to Numeric#i.
|
|
18
|
+
#
|
|
19
|
+
# Any additional arguments are forwarded to +BitInt#new+
|
|
20
|
+
def i: (?untyped bits) -> untyped
|
|
21
|
+
|
|
22
|
+
# Converts +self+ into an unsigned 8-bit integer.
|
|
23
|
+
#
|
|
24
|
+
# Any additional arguments are forwarded to +BitInt#new+
|
|
25
|
+
def u8: () -> untyped
|
|
26
|
+
|
|
27
|
+
# Converts +self+ into an unsigned 16-bit integer.
|
|
28
|
+
#
|
|
29
|
+
# Any additional arguments are forwarded to +BitInt#new+
|
|
30
|
+
def u16: () -> untyped
|
|
31
|
+
|
|
32
|
+
# Converts +self+ into an unsigned 32-bit integer.
|
|
33
|
+
#
|
|
34
|
+
# Any additional arguments are forwarded to +BitInt#new+
|
|
35
|
+
def u32: () -> untyped
|
|
36
|
+
|
|
37
|
+
# Converts +self+ into an unsigned 64-bit integer.
|
|
38
|
+
#
|
|
39
|
+
# Any additional arguments are forwarded to +BitInt#new+
|
|
40
|
+
def u64: () -> untyped
|
|
41
|
+
|
|
42
|
+
# Converts +self+ into an unsigned 128-bit integer.
|
|
43
|
+
#
|
|
44
|
+
# Any additional arguments are forwarded to +BitInt#new+
|
|
45
|
+
def u128: () -> untyped
|
|
46
|
+
|
|
47
|
+
# Converts +self+ into a signed 8-bit integer.
|
|
48
|
+
#
|
|
49
|
+
# Any additional arguments are forwarded to +BitInt#new+
|
|
50
|
+
def i8: () -> untyped
|
|
51
|
+
|
|
52
|
+
# Converts +self+ into a signed 16-bit integer.
|
|
53
|
+
#
|
|
54
|
+
# Any additional arguments are forwarded to +BitInt#new+
|
|
55
|
+
def i16: () -> untyped
|
|
56
|
+
|
|
57
|
+
# Converts +self+ into a signed 32-bit integer.
|
|
58
|
+
#
|
|
59
|
+
# Any additional arguments are forwarded to +BitInt#new+
|
|
60
|
+
def i32: () -> untyped
|
|
61
|
+
|
|
62
|
+
# Converts +self+ into a signed 64-bit integer.
|
|
63
|
+
#
|
|
64
|
+
# Any additional arguments are forwarded to +BitInt#new+
|
|
65
|
+
def i64: () -> untyped
|
|
66
|
+
|
|
67
|
+
# Converts +self+ into a signed 128-bit integer.
|
|
68
|
+
#
|
|
69
|
+
# Any additional arguments are forwarded to +BitInt#new+
|
|
70
|
+
def i128: () -> untyped
|
|
71
|
+
end
|
|
72
|
+
end
|