abs()
Function in Builtins
abs(x): absolute value, component-wise.
import { abs } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
const abs: <K extends FloatKey | Float64Key | IntKey>( x: ReadonlyNode<K>,) => Node<K>Parameters
xReadonlyNode<K>
Return value
Node<K>
Description
An unsigned operand takes the absU id rather than the portable abs one, because GLSL ES
3.00 has no abs(uint) overload and a WebGL2 driver refuses the call. The choice is
divergentIntegerId, shared with the "use typeshade" front end so both authoring
surfaces emit the same thing; every other operand keeps the portable spelling.
Examples
Example
import { fn, abs, f32T } from 'typeshade'
const magnitude = fn('magnitude', { x: f32T }, ({ x }) => abs(x))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
Source
src/core/ir/node.ts, line 1472, at commit 26de7be8