SV3 logo

mulDiv

Unsigned multiply-divide with optional ceil.

(x * y) / d, or ceil. Token math in this SDK is integer-only. Full precision uses bigint — there is no intermediate overflow beyond JS bigint limits.

Import

import { mulDiv } from "@repo/contract-client/math";

Usage

import { mulDiv } from "@repo/contract-client/math";

const down = mulDiv(x, y, d);
const up = mulDiv(x, y, d, true);

Return Value

bigint

Parameters

x

  • Type: bigint

Non-negative.

mulDiv(x, y, d);

y

  • Type: bigint

Non-negative.

denominator

  • Type: bigint

Must be > 0.

mulDiv(amount, 1_250_000n, 100_000_000n, true);

ceil (optional)

  • Type: boolean
  • Default: false

Round up when true.

mulDiv(x, y, d, true);

Error

InvalidAmountError on signed inputs or denominator <= 0.