Skip to main content

fp_mul

Function fp_mul 

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

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

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

Returns Err(Overflow) if the result exceeds u128::MAX.

§Example

use solmath::{fp_mul, SCALE};
let result = fp_mul(2 * SCALE, 3 * SCALE).unwrap();
assert_eq!(result, 6 * SCALE);