---
title: "distance(): IR builder function in typeshade/core/ir"
description: "distance, an IR builder function in typeshade/core/ir. distance(a, b): |a − b|, vector to scalar; the built-in form of length(a.sub(b))."
url: https://typeshade.dev/api/distance/
language: en
---

# `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()`](https://typeshade.dev/reference/functions/distance/)

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

## Syntax

```ts
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

| Target | Support | Notes |
| --- | --- | --- |
| 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

- [fp64](https://typeshade.dev/guide/internals/fp64/)

## See also

- [`distance()`](https://typeshade.dev/reference/functions/distance/)

## Source

[`src/core/ir/node.ts`, line 1614](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/node.ts#L1614), at commit af54ddad5
