dot
On this page

dot()

Function in Builtins

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

import { dot } from 'typeshade'

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

Syntax

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, 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

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

Targets

TargetSupportNotes
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

See also

Source

src/core/ir/node.ts, line 1821, at commit 26de7be8

Edit this page Report a problem