distance
On this page

distance()

Function in Builtins

distance(a, b): |a − b|, vector to scalar; the built-in form of length(a.sub(b)).

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

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

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

Syntax

function distance<K extends `vec${number}<f64>`>(
a: ReadonlyNode<K>,
b: NoInfer<ReadonlyNode<K>>,
): Node<'f64'>;
function distance<K extends `vec${number}<f32>`>(
a: ReadonlyNode<K>,
b: NoInfer<ReadonlyNode<K>>,
): Node<'f32'>;

Parameters

a ReadonlyNode<K>
b NoInfer<ReadonlyNode<K>>

Return value

Node<'f64'>

Description

Returns f32 for f32 vectors and f64 for emulated-double vectors.

Targets

TargetSupportNotes
WGSL (WebGPU) Supported

distance(a, b). Over f64 operands the fp64 pass rewrites it into its df64 helper.

GLSL ES 3.00 (WebGL2) Supported

distance(a, b). Over f64 operands the fp64 pass rewrites it into its df64 helper.

CPU oracle Supported

Evaluated in f64 by the oracle.

In the guide

See also

Source

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

Edit this page Report a problem