[−][src]Module fraction::division
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
DivisionState | Division state encapsulates remainder and divisor |
Functions
divide_integral | Divide two numbers and produce every single digit of the whole part of the resulting number |
divide_rem | Produces the fractional part of the decimal from a rest part left after division |
divide_rem_resume | divide_rem co-routine implementation |
divide_to_ascii_vec | Divide a fraction into a |
divide_to_callback | Calculate the division result and pass every character into the callback |
divide_to_string | Divide a fraction into a |
divide_to_writeable | Divide a fraction into a writeable target implementing |
division_result_max_char_length | Calculate the max possible length of division in characters (including floating point) This may be useful for string/vector pre-allocations |
write_digit | A helper function to use in conjunction with divide_to_callback |