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

# `max()`

Function in Builtins

`max(a, b)`: component-wise maximum, the partner of `min(/api/min/)`.

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

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

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

## Syntax

```ts
const max: <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`. A common floor idiom is `max(x, f32(1e-6))`, which keeps a divisor or a `sqrt` or `log` argument off zero without a branch.

## Examples

### Example

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

const safe = fn('safe', { x: f32T }, ({ x }) => max(x, f32(1e-6)))
```

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Supported | `max(a, b)`. Over `f64` operands the fp64 pass rewrites it into its `df64` helper. |
| GLSL ES 3.00 (WebGL2) | Supported | `max(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

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

## Source

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