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
xReadonlyNode<K>loNoInfer<ArithArg<K>>hiNoInfer<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
| Target | Support | Notes |
|---|---|---|
| WGSL (WebGPU) | Supported |
|
| GLSL ES 3.00 (WebGL2) | Supported |
|
| CPU oracle | Supported | Evaluated in |
See also
Source
src/core/ir/node.ts, line 1476, at commit af54ddad5