---
title: "sub(): IR builder function in typeshade/core/ir, TypeShade"
description: "sub, an IR builder function in typeshade/core/ir. a - b as a free function."
url: https://typeshade.dev/api/sub/
language: en
---

# `sub()`

Function in Builtins

a - b as a free function.

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

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

## Syntax

```ts
function sub<E extends string, N extends number>(
  a: ReadonlyNode<E>,
  b: ReadonlyNode<`vec${N}<${E}>`>,
): Node<`vec${N}<${E}>`>;
function sub<K extends string>(a: ReadonlyNode<K>, b: ArithArg<K>): Node<K>;
function sub<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

`sub(1, smoothstep(e0, e1, x))` is the inverted-ramp idiom the method form has to spell `f32(1).sub(...)`; both emit `(1.0 - smoothstep(...))`.

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

## Examples

### Example

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

const rim = fn('rim', { d: f32T }, ({ d }) => sub(1, smoothstep(0, 1, d)))
```

## See also

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

## Source

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