---
title: "dot(): IR builder function in typeshade/core/ir, TypeShade"
description: "dot, an IR builder function in typeshade/core/ir. dot(a, b): dot product, vector to scalar."
url: https://typeshade.dev/api/dot/
language: en
---

# `dot()`

Function in Builtins

`dot(a, b)`: dot product, vector to scalar.

`import { dot } from 'typeshade/core/ir'`

This export returns an IR node. A `"use typeshade"` file calls the builtin itself: [`dot()`](https://typeshade.dev/reference/functions/dot/)

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

## Syntax

```ts
function dot<K extends `vec${number}<f64>`>(
  a: ReadonlyNode<K>,
  b: NoInfer<ReadonlyNode<K>>,
): Node<'f64'>;
function dot<K extends `vec${number}<i32>`>(
  a: ReadonlyNode<K>,
  b: NoInfer<ReadonlyNode<K>>,
): Node<'i32'>;
function dot<K extends `vec${number}<u32>`>(
  a: ReadonlyNode<K>,
  b: NoInfer<ReadonlyNode<K>>,
): Node<'u32'>;
function dot<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

Like [`length`](https://typeshade.dev/api/length/), the return precision follows the operand key: `f32` vectors return `f32`, emulated-double `vec${N}<f64>` vectors return `f64`. Both operands share one key, so `dot(v2, v3)` is a `tsc` error.

An integer dot returns that integer kind and takes the `dotI` / `dotU` id, because GLSL ES 3.00 has no integer `dot` at all and a WebGL2 driver refuses the call; the ids carry a GLSL column that expands to the multiply-add the spelling is missing. The choice is `divergentIntegerId`, shared with the `"use typeshade"` front end.

## Examples

### Example

```ts
import { fn, dot, vec3, f32T } from 'typeshade/core/ir'

const luma = fn('luma', { x: f32T }, ({ x }) => dot(vec3(x, x, x), vec3(0.2, 0.7, 0.1)))
```

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Supported | `dot(a, b)`. Over `f64` operands the fp64 pass rewrites it into its `df64` helper. |
| GLSL ES 3.00 (WebGL2) | Supported | `dot(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

- [`dot()`](https://typeshade.dev/reference/functions/dot/)
- [`length`](https://typeshade.dev/api/length/)

## Source

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