---
title: "div(): IR builder function in typeshade/core/ir, TypeShade"
description: "div, an IR builder function in typeshade/core/ir. a / b as a free function, for a literal numerator: div(1, x) is the reciprocal, and emits (1.0 / x)."
url: https://typeshade.dev/api/div/
language: en
---

# `div()`

Function in Builtins

a / b as a free function, for a literal numerator: div(1, x) is the reciprocal, and emits (1.0 / x).

`import { div } from 'typeshade/core/ir'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
function div<E extends string, N extends number>(
  a: ReadonlyNode<E>,
  b: ReadonlyNode<`vec${N}<${E}>`>,
): Node<`vec${N}<${E}>`>;
function div<K extends string>(a: ReadonlyNode<K>, b: ArithArg<K>): Node<K>;
function div<K extends string>(a: number, b: ReadonlyNode<K>): Node<K>;
```

## Parameters

**`a` `ReadonlyNode<E>`**

**`b` ``ReadonlyNode<`vec${N}<${E}>`>``**

## Return value

``Node<`vec${N}<${E}>`>``

## Exceptions

**`TypeError`**

both operands are plain numbers.

## Description

Whichever operand is a node types the other. Two bare numbers are rejected.

## Examples

### Example

```ts
import { fn, div, f32T } from 'typeshade/core/ir'

const recip = fn('recip', { x: f32T }, ({ x }) => div(1, x))
```

## See also

- [`ReadonlyNode`](https://typeshade.dev/api/readonlynode/)
- [`div`](https://typeshade.dev/api/div/)

## Source

[`src/core/ir/node.ts`, line 1040](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/node.ts#L1040), at commit af54ddad5
