API reference
GD.math.bits
Integer math entry for uint64 bit counts, rotations, reversals, and operations with carry.
Methods
len64(x: int) -> intleading_zeros64(x: int) -> inttrailing_zeros64(x: int) -> intones_count64(x: int) -> introtate_left64(x: int, k: int) -> intreverse64(x: int) -> intreverse_bytes64(x: int) -> intadd64(x: int, y: int, carry: int) -> Arraysub64(x: int, y: int, borrow: int) -> Arraymul64(x: int, y: int) -> Array
len64
len64(x: int) -> intOperate on the bit counts and layout of uint64 values.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | int | Required | 64-bit word represented by a script integer. |
Return value
int
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
leading_zeros64
leading_zeros64(x: int) -> intCount leading zero bits.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | int | Required | 64-bit word represented by a script integer. |
Return value
int
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
trailing_zeros64
trailing_zeros64(x: int) -> intCount trailing zero bits.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | int | Required | 64-bit word represented by a script integer. |
Return value
int
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
ones_count64
ones_count64(x: int) -> intCount set bits.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | int | Required | 64-bit word represented by a script integer. |
Return value
int
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
rotate_left64
rotate_left64(x: int, k: int) -> intRotate left within 64 bits, accepting negative shifts.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | int | Required | 64-bit word represented by a script integer. |
k | int | Required | Bit rotation amount; negative values rotate in the opposite direction. |
Return value
int
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
reverse64
reverse64(x: int) -> intReverse all 64 bits.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | int | Required | 64-bit word represented by a script integer. |
Return value
int
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
reverse_bytes64
reverse_bytes64(x: int) -> intReverse the order of eight bytes.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | int | Required | 64-bit word represented by a script integer. |
Return value
int
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
add64
add64(x: int, y: int, carry: int) -> ArrayReturn uint64 arithmetic with carry or borrow as two-element arrays.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | int | Required | 64-bit word represented by a script integer. |
y | int | Required | Second 64-bit word for the arithmetic operation. |
carry | int | Required | Incoming carry bit, either 0 or 1. |
Return value
Array
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
sub64
sub64(x: int, y: int, borrow: int) -> ArraySubtract uint64 values and return borrow.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | int | Required | 64-bit word represented by a script integer. |
y | int | Required | Second 64-bit word for the arithmetic operation. |
borrow | int | Required | Incoming borrow bit, either 0 or 1. |
Return value
Array
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
mul64
mul64(x: int, y: int) -> ArrayReturn the high and low halves of a uint64 product.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | int | Required | 64-bit word represented by a script integer. |
y | int | Required | Second 64-bit word for the arithmetic operation. |
Return value
Array
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.