fma
On this page

fma()

Function in Builtins

fma(a, b, c): fused multiply-add, a·b + c.

import { fma } from 'typeshade'

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

Syntax

const fma: <K extends FloatKey>(
a: ReadonlyNode<K>,
b: NoInfer<ArithArg<K>>,
c: NoInfer<ArithArg<K>>,
) => Node<K>

Parameters

a ReadonlyNode<K>
b NoInfer<ArithArg<K>>
c NoInfer<ArithArg<K>>

Return value

Node<K>

Description

WGSL emits the hardware fma, a single rounding that a driver’s fast-math cannot distribute or reassociate, unlike a.mul(b).add(c). GLSL ES 3.00 has no fma, so the GLSL output is the unfused (a * b + c). Use it only where the single rounding is the point, such as the error term fma(a, b, -a*b) of an exact product, which some GPU compilers fold away when it is built from separate operations.

Targets

TargetSupportNotes
WGSL (WebGPU) Supported

fma(a, b, c).

GLSL ES 3.00 (WebGL2) Supported

((a) * (b) + (c)).

CPU oracle Supported

Evaluated in f64 by the oracle.

Source

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

Edit this page Report a problem