Function fraction::division::divide_rem
source · pub fn divide_rem<I, Consumer>(
dividend: I,
divisor: I,
consumer: Consumer,
) -> Result<DivisionState<I>, DivisionError>where
Consumer: FnMut(DivisionState<I>, u8) -> Result<Result<DivisionState<I>, DivisionState<I>>, DivisionError>,
I: Clone + GenericInteger,
Expand description
Produces the fractional part of the decimal from a rest part left after division
WARNING: Negative numbers as arguments are not supported.
Returns remainder of the division
If the consumer returns Ok(Ok(state))
keeps on calculation
If the consumer returns Ok(Err(state))
stops calculation and returns the remainder
If the consumer returns Err(_)
the calculation will be stopped and the error will be passed as the result value
§Examples
use fraction::division::divide_rem;
let mut result: [u8; 2] = [0; 2];
let mut ptr: usize = 0;
let state = divide_rem(3, 4, |state, digit| {
result[ptr] = digit;
ptr += 1;
Ok(Ok(state))
}).unwrap();
assert_eq!(state.remainder, 0);
assert_eq!(state.divisor, 4);
assert_eq!(result, [7, 5]); // 3/4 == 0.75