length()
함수, 내장 함수 분류
length(v): Euclidean vector magnitude, |v|.
import { length } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
function length<K extends `vec${number}<f64>`>(v: ReadonlyNode<K>): Node<'f64'>;function length<K extends `vec${number}<f32>`>(v: ReadonlyNode<K>): Node<'f32'>;매개변수
vReadonlyNode<K>
반환값
Node<'f64'>
설명
The return precision follows the operand: an
f32 vector (vec2, vec3 or vec4) returns f32, and an emulated-double vec${N}<f64> returns
f64, so an f64 operand keeps its precision without a cast.
예제
예제
import { fn, length, vec2, f32T } from 'typeshade'
const mag = fn('mag', { x: f32T, y: f32T }, ({ x, y }) => length(vec2(x, y)))대상별 지원
| 대상 | 지원 | 비고 |
|---|---|---|
| WGSL (WebGPU) | 지원 |
|
| GLSL ES 3.00 (WebGL2) | 지원 |
|
| CPU 오라클 | 지원 | Evaluated in f64 by the oracle. |
관련 가이드
함께 보기
소스
src/core/ir/node.ts, 1797행, 커밋 c66579bf 기준