max
On this page

max()

Function in Builtins

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

import { max } from 'typeshade'

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

Syntax

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

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

Targets

TargetSupportNotes
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

See also

Source

src/core/ir/node.ts, line 1650, at commit 26de7be8

Edit this page Report a problem