add
이 페이지에서

add()

함수, 내장 함수 분류

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

import { add } from 'typeshade'

시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.

구문

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

매개변수

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

반환값

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

예외

TypeError

both operands are plain numbers.

설명

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.

예제

예제

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

관련 가이드

함께 보기

소스

src/core/ir/node.ts, 1164행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고