Procs
proc `&&`(x`gensym6, y`gensym6: distinct AnyInteger): Integer {.inline.}
- Source Edit
proc `&&=`(x`gensym0: var Integer; y`gensym0: AnyInteger) {.inline.}
- Source Edit
func `&<<`(val`gensym26, n`gensym26: distinct AnyInteger): Integer {.inline.}
- Source Edit
func `&<<=`(val`gensym26: var Integer; n`gensym26: AnyInteger) {.inline.}
- Source Edit
func `&>>`(val`gensym24, n`gensym24: distinct AnyInteger): Integer {.inline.}
- Source Edit
func `&>>=`(val`gensym24: var Integer; n`gensym24: AnyInteger) {.inline.}
- Source Edit
proc `&^`(x`gensym12, y`gensym12: distinct AnyInteger): Integer {.inline.}
- Source Edit
proc `&^=`(x`gensym4: var Integer; y`gensym4: AnyInteger) {.inline.}
- Source Edit
proc `&|`(x`gensym9, y`gensym9: distinct AnyInteger): Integer {.inline.}
- Source Edit
proc `&|=`(x`gensym2: var Integer; y`gensym2: AnyInteger) {.inline.}
- Source Edit
proc `and`(x`gensym15, y`gensym15: distinct AnyInteger): Integer {.inline.}
- Source Edit
func nbits(val: Integer): int {.inline, ...raises: [], tags: [], forbids: [].}
-
Returns the number of bits needed to represent the absolute value of the given integer.
Returns 0 in the special case of zero.
Equivalent to floor(log2(n)) + 1 for positive numbers.
Equivalent to Python's int.bit_length().
Example:
assert nbits(10'gmp) == 4 assert nbits(0'gmp) == 0 # special case assert nbits(1'gmp) == 1 assert nbits(255'gmp) == 8 assert nbits(256'gmp) == 9
Source Edit proc `or`(x`gensym18, y`gensym18: distinct AnyInteger): Integer {.inline.}
- Source Edit
proc scanOne(val: Integer; start: int = 0): int {....raises: [], tags: [], forbids: [].}
-
Returns the index of first 1-bit on or after the given optional index (defaults to 0).
Indices run from least significant to most significant.
Returns -1 if no bits are set after the given index.
Note that negative numbers behave as if they have an infinite number of 1-bits.
Example:
assert 11.scanOne() == 0 assert 8.scanOne() == 3 assert 4.scanOne(3) == -1 assert (-2).scanOne(100) == 100 # 0b..∞..11111110
Source Edit proc scanZero(val: Integer; start: int = 0): int {....raises: [], tags: [], forbids: [].}
-
Returns the index of first 0-bit on or after the given optional index (defaults to 0).
Indices run from least significant to most significant.
Returns -1 if all bits are set after the given index (can only happen with negative numbers).
Example:
assert 11.scanZero() == 2 assert 8.scanZero(1) == 1 assert (-1).scanZero() == -1
Source Edit proc `xor`(x`gensym21, y`gensym21: distinct AnyInteger): Integer {.inline.}
- Source Edit
Iterators
iterator items(n: Integer): int {.inline, ...raises: [], tags: [], forbids: [].}
-
Iterates over the positions of 1-bits in the given Integer n, going from least significant to most significant.
For example for i in 10'gmp would repeat the loop body twice, first with i=1 followed by i=3, as 10 = 2^1 + 2^3.
Note: Giving a negative number yielsds an infinte loop of ever-increasing indices, negative numbers act as if they're two's-complement of infinite size.Source Edit
Exports
-
<=%, <, <=, getOrDo, >=, ==, >%, ^, >, //=, >=%, +=, setNegative, -, >=%, !=%, *=, ==%, newInteger, getUnsafe, //, *=, //=, %=, Integer, -, <=%, <=, -, ==, isNonZero, addMul, 'gmp, mod, initInteger, *, div, newInteger, -=, %=, >%, subMul, getOr, div, setDivMod, isNatural, %, //, <=, toInteger, +, >=, abs, <=%, >=%, >%, pred, !=%, inc, //, dec, !=, !=, isNegative, %, cmpAbs, ==, -=, %, <, divMod, +, ==%, assign, mod, AnyInteger, !=%, -, <%, <, newInteger, >, ==%, >, isZero, cmp, *, +, div, isPositive, mod, !=, >=, +=, <%, setAbs, *, succ, cmp, newInteger, <%