add
On this page

add()

Function in Builtins

a + b as a free function, the spelling for an expression whose left operand is a literal.

import { add } from 'typeshade'

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

Syntax

function add<E extends string, N extends number>(
a: ReadonlyNode<E>,
b: ReadonlyNode<`vec${N}<${E}>`>,
): Node<`vec${N}<${E}>`>;
function add<K extends string>(a: ReadonlyNode<K>, b: ArithArg<K>): Node<K>;
function add<K extends string>(a: number, b: ReadonlyNode<K>): Node<K>;

Parameters

a ReadonlyNode<E>
b ReadonlyNode<`vec${N}<${E}>`>

Return value

Node<`vec${N}<${E}>`>

Exceptions

TypeError

both operands are plain numbers.

Description

add(1, x) is f32(1).add(x) without the wrapper, and emits the same (1.0 + x).

Whichever operand is a node types the other: add(1, u32node) emits 1u, the same typed lift u32node.add(1) performs. Two bare numbers are rejected — fold those on the host.

Examples

Example

import { fn, add, f32T } from 'typeshade'
const shifted = fn('shifted', { x: f32T }, ({ x }) => add(0.5, x))

In the guide

See also

Source

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

Edit this page Report a problem