clamp
On this page

clamp()

Function in Builtins

clamp(x, lo, hi): restricts x to [lo, hi], component-wise.

import { clamp } from 'typeshade/core/ir'

This export returns an IR node. A "use typeshade" file calls the builtin itself: clamp()

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

Syntax

const clamp: <K extends FloatKey | IntKey>(
x: ReadonlyNode<K>,
lo: NoInfer<ArithArg<K>>,
hi: NoInfer<ArithArg<K>>,
) => Node<K>

Parameters

x ReadonlyNode<K>
lo NoInfer<ArithArg<K>>
hi NoInfer<ArithArg<K>>

Return value

Node<K>

Description

lo and hi may be scalar broadcasts against a vector x. It is the standard guard before asin and acos, whose domain is [-1, 1], keeping float rounding from pushing an in-range value a hair past its bound.

Examples

Example

import { fn, clamp, f32T } from 'typeshade/core/ir'
const norm = fn('norm', { x: f32T }, ({ x }) => clamp(x, 0, 1))

Targets

TargetSupportNotes
WGSL (WebGPU) Supported

clamp(x, lo, hi).

GLSL ES 3.00 (WebGL2) Supported

clamp(x, lo, hi).

CPU oracle Supported

Evaluated in f64 by the oracle.

See also

Source

src/core/ir/node.ts, line 1476, at commit af54ddad5

Edit this page Report a problem