Skip to main content Module wide_math Copy item path Source I256 OverI128Magnitude ADL delta_K representability check error. U256 ceil_div_positive_checked Spec section 4.6: positive ceiling division.
ceil(n / d) = (n + d - 1) / d, but we use the remainder form to avoid overflow:
ceil(n / d) = trunc(n / d) + (1 if n % d != 0 else 0). checked_mul_div_ceil_u256 Checked variant of mul_div_ceil_u256.
Returns None if the quotient doesn’t fit in U256. fee_debt_u128_checked Spec section 4.6: checked fee-debt conversion.
If fee_credits < 0, the account owes fees. Returns the unsigned debt.
If fee_credits >= 0, returns 0 (no debt). floor_div_signed_conservative Spec section 4.6: signed floor division with positive denominator. floor_div_signed_conservative_i128 Native i128 floor division: floor(n / d) for positive d, rounding toward
negative infinity. Mirrors floor_div_signed_conservative but uses native
i128/u128 arithmetic for the funding-term computation (spec §5.4). mul_div_ceil_u128 Native multiply-divide ceil. Product a*b must not overflow u128. Panics on d==0. mul_div_ceil_u256 Spec section 4.6: exact wide product then ceiling divide.
Computes ceil(a * b / d) using a U512 intermediate. mul_div_floor_u128 Native multiply-divide floor. Product a*b must not overflow u128. Panics on d==0. mul_div_floor_u256 Spec section 4.6: exact wide product then floor divide.
Computes floor(a * b / d) using a U512 intermediate to avoid overflow. mul_div_floor_u256_with_rem Like mul_div_floor_u256 but also returns the remainder.
Returns (floor(a * b / d), (a * b) mod d). saturating_mul_u128_u64 Saturating multiply for warmup cap computation. saturating_mul_u256_u64 Spec section 4.6: saturating multiply for warmup cap. wide_mul_div_ceil_u128_or_over_i128max ADL delta_K representability check.
Returns Ok(v) if the ceil result fits in i128 magnitude, Err otherwise. wide_mul_div_floor_u128 Exact wide multiply-divide floor using U256 intermediate.
Used for haircut paths where a*b can exceed u128::MAX. wide_signed_mul_div_floor Spec section 1.5 item 11: wide signed mul-div for pnl_delta. wide_signed_mul_div_floor_from_k_pair Safe K-difference settlement (spec §4.8 lines 720-732).
Computes K-difference in wide intermediate, then multiplies and divides.