---
title: "min(): IR builder function in typeshade/core/ir, TypeShade"
description: "min, an IR builder function in typeshade/core/ir. min(a, b): component-wise minimum."
url: https://typeshade.dev/api/min/
language: en
---

# `min()`

Function in Builtins

`min(a, b)`: component-wise minimum.

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

This export returns an IR node. A `"use typeshade"` file calls the builtin itself: [`min()`](https://typeshade.dev/reference/functions/min/)

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

## Syntax

```ts
const min: <K extends FloatKey | Float64Key | IntKey>(
  a: ReadonlyNode<K>,
  b: NoInfer<ArithArg<K>>,
) => Node<K>
```

## Parameters

**`a` `ReadonlyNode<K>`**

**`b` `NoInfer<ArithArg<K>>`**

## Return value

`Node<K>`

## Description

`b` may be a scalar broadcast against a vector `a`, the same rule as the arithmetic methods, so `min(color, 1)` caps every channel against one literal without unrolling per component.

## Examples

### Example

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

const capped = fn('capped', { x: f32T }, ({ x }) => min(x, 1))
```

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Supported | `min(a, b)`. Over `f64` operands the fp64 pass rewrites it into its `df64` helper. |
| GLSL ES 3.00 (WebGL2) | Supported | `min(a, b)`. Over `f64` operands the fp64 pass rewrites it into its `df64` helper. |
| CPU oracle | Supported | Evaluated in `f64` by the oracle. |

## In the guide

- [The CPU oracle](https://typeshade.dev/guide/internals/the-cpu-oracle/)
- [fp64](https://typeshade.dev/guide/internals/fp64/)

## See also

- [`min()`](https://typeshade.dev/reference/functions/min/)

## Source

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