Expand description
Lossless integer division
- The algorithm uses stack only, no introduced heap allocations for calculation (although underlying integer type implementation may perform those)
- Linear complexity, O(n)
- Abstract from a particular integer implementation, may be used on primitive types (as i32 or u32) as well as complex ones (num::BigInt, num::BigUint) Thus can be efficiently used on any integer type implementing a bunch of required traits (which all primitive ints and num::bigint implement out of the box). Although in that case the underlying math will be using heap.
Structs§
- Division state encapsulates remainder and divisor
Functions§
- Divide two numbers and produce every single digit of the whole part of the resulting number
- Produces the fractional part of the decimal from a rest part left after division
- divide_rem co-routine implementation
Performs the division, changes the state and returns it - Divide a fraction into a
Vec<u8>
of ASCII(utf8) chars - Calculate the division result and pass every character into the callback
Returns the remainder of the division - Divide a fraction into a
String
- Divide a fraction into a writeable target implementing
std::fmt::Write
Returns the remainder of the division - Calculate the max possible length of division in characters (including floating point) This may be useful for string/vector pre-allocations
- A helper function to use in conjunction with divide_to_callback