Function fraction::division::divide_to_callback

source ·
pub fn divide_to_callback<I, C>(
    dividend: I,
    divisor: I,
    precision: usize,
    trail_zeroes: bool,
    callback: C,
) -> Result<I, DivisionError>
Expand description

Calculate the division result and pass every character into the callback
Returns the remainder of the division

  • Makes no allocations

Uses divide_integral and divide_rem functions internally.

WARNING: Negative numbers as arguments are not supported.

§Callback

Callback receives every digit of the result as a u8 value. The floating point character (dot) is passed to the callback as 10u8. If the callback returns Ok(true), the function keeps on calculation If the callback returns Ok(false), the function stops calculation and returns the remainder If the callback returns Err(_) the calculation will be stopped and the error will propagate as the result value

§Examples

use fraction::division::divide_to_callback;

let mut result = Vec::new();

// calculate 7/4, which is 1.75
divide_to_callback(7, 4, 2, false, |d| { result.push(d as i32); Ok(true) }).ok();

assert_eq!(&result, &[1, 10, 7, 5]);