clamp()
Function in Builtins
clamp(x, lo, hi): restricts x to [lo, hi], component-wise.
import { clamp } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
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'
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 f64 by the oracle. |
In the guide
See also
Source
src/core/ir/node.ts, line 1711, at commit 26de7be8