Managed
An arbitrary-precision big integer along with an allocator which manages the memory.
Memory is allocated as needed to ensure operations never overflow. The range is bounded only by available memory.
Fields of this type
Fields
Creates a new `Managed`.
Functions
- init
- Creates a new `Managed`.
- initSet
- Creates a new `Managed` with value `value`.
- initCapacity
- Creates a new Managed with a specific capacity.
- len
- Returns the number of limbs currently in use.
- isPositive
- Returns whether an Managed is positive.
- setSign
- Sets the sign of an Managed.
- setLen
- Sets the length of an Managed.
- ensureCapacity
- Ensures an Managed has enough space allocated for capacity limbs.
- deinit
- Frees all associated memory.
- clone
- Returns a `Managed` with the same value.
- copy
- Copies the value of the integer to an existing `Managed` so that they both have the same value.
- swap
- Efficiently swap a `Managed` with another.
- dump
- Debugging tool: prints the state to stderr.
- negate
- Negate the sign.
- abs
- Make positive.
- bitCountAbs
- Returns the number of bits required to represent the absolute value of an integer.
- bitCountTwosComp
- Returns the number of bits required to represent the integer in twos-complement form.
- fits
- Returns whether self can fit into an integer of the requested type.
- sizeInBaseUpperBound
- Returns the approximate size of the integer in the given base.
- set
- Sets an Managed to value.
- toInt
- Convert `self` to `Int`.
- toFloat
- Convert `self` to `Float`.
- setString
- Set self from the string representation `value`.
- setTwosCompIntLimit
- Set self to either bound of a 2s-complement integer.
- toString
- Converts self to a string in the requested base.
- format
- To allow `std.fmt.format` to work with `Managed`.
- formatNumber
- If the absolute value of integer is greater than or equal to `pow(2, 64 * @sizeOf(usize) * 8)`,
- orderAbs
- Returns math.Order.lt, math.Order.eq, math.Order.gt if |a| < |b|, |a| ==
- order
- Returns math.Order.lt, math.Order.eq, math.Order.gt if a < b, a == b or a > b
- eqlZero
- Returns true if a == 0.
- eqlAbs
- Returns true if |a| == |b|.
- eql
- Returns true if a == b.
- normalize
- Normalize a possible sequence of leading zeros.
- addScalar
- r = a + scalar
- add
- r = a + b
- addWrap
- r = a + b with 2s-complement wrapping semantics.
- addSat
- r = a + b with 2s-complement saturating semantics.
- sub
- r = a - b
- subWrap
- r = a - b with 2s-complement wrapping semantics.
- subSat
- r = a - b with 2s-complement saturating semantics.
- mul
- rma = a * b
- mulWrap
- rma = a * b with 2s-complement wrapping semantics.
- divFloor
- q = a / b (rem r)
- divTrunc
- q = a / b (rem r)
- shiftLeft
- r = a << shift, in other words, r = a * 2^shift
- shiftLeftSat
- r = a <<| shift with 2s-complement saturating semantics.
- shiftRight
- r = a >> shift
- bitNotWrap
- r = ~a under 2s-complement wrapping semantics.
- bitOr
- r = a | b
- bitAnd
- r = a & b
- bitXor
- r = a ^ b
- gcd
- rma may alias x or y.
- sqr
- r = a * a
- sqrt
- r = ⌊√a⌋
- truncate
- r = truncate(Int(signedness, bit_count), a)
- saturate
- r = saturate(Int(signedness, bit_count), a)
- popCount
- r = @popCount(a) with 2s-complement semantics.
Error sets in this namespace
Error Sets
= 1 << (@typeInfo(usize).int.bits - 1)
Values
- sign_bit
- = 1 << (@typeInfo(usize).int.bits - 1)
- default_capacity
- Default number of limbs to allocate on creation of a `Managed`.