---
title: mulDiv
description: Unsigned multiply-divide with optional ceil.
---

> **For AI agents:** the complete documentation index is at [llms.txt](/llms.txt). Append `.md` to any page URL for its markdown version.

`(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

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

## Usage

```ts
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.

```ts
mulDiv(x, y, d);
```

### y

- **Type:** `bigint`

Non-negative.

### denominator

- **Type:** `bigint`

Must be `> 0`.

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

### ceil (optional)

- **Type:** `boolean`
- **Default:** `false`

Round up when `true`.

```ts
mulDiv(x, y, d, true);
```

## Error

`InvalidAmountError` on signed inputs or `denominator <= 0`.
