length()
Function in Builtins
length(v): Euclidean vector magnitude, |v|.
import { length } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
function length<K extends `vec${number}<f64>`>(v: ReadonlyNode<K>): Node<'f64'>;function length<K extends `vec${number}<f32>`>(v: ReadonlyNode<K>): Node<'f32'>;Parameters
vReadonlyNode<K>
Return value
Node<'f64'>
Description
The return precision follows the operand: an
f32 vector (vec2, vec3 or vec4) returns f32, and an emulated-double vec${N}<f64> returns
f64, so an f64 operand keeps its precision without a cast.
Examples
Example
import { fn, length, vec2, f32T } from 'typeshade'
const mag = fn('mag', { x: f32T, y: f32T }, ({ x, y }) => length(vec2(x, y)))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 1797, at commit 26de7be8