Skip to main content

fp_div

Function fp_div 

Source
pub fn fp_div(a: u128, b: u128) -> Result<u128, SolMathError>
Expand description

Unsigned fixed-point division: (a * SCALE) / b.

Both a and b are u128 values at SCALE (1e12). Returns the quotient at SCALE. Error: 1 ULP max (truncation toward zero).

Returns Err(DivisionByZero) if b == 0, or Err(Overflow) if the result exceeds u128::MAX.

ยงExample

use solmath::{fp_div, SCALE};
let result = fp_div(10 * SCALE, 2 * SCALE).unwrap();
assert_eq!(result, 5 * SCALE);