mod()
함수, 내장 함수 분류
Floor modulo: x - y * floor(x / y), with identical semantics on both targets.
import { mod } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
const mod: <K extends FloatKey>( x: ReadonlyNode<K>, y: NoInfer<ArithArg<K>>,) => Node<K>매개변수
xReadonlyNode<K>the value to wrap.
yNoInfer<ArithArg<K>>the modulus, a vector of the same shape or a scalar to broadcast.
반환값
Node<K>
the wrapped value, in [0, y) for a positive y.
설명
Use it
wherever a negative operand is possible, which is what domain repetition and angle folds
need: the result takes the sign of y, so for a positive y every input wraps into
[0, y) and mod(-1, 4) is 3.
The .mod method and % are the other modulo, truncated modulo, whose result takes the
sign of x: there (-1) % 4 is -1. That is WGSL’s % semantics, and since GLSL ES
3.00 keeps % for integers only, the GLSL writer spells the float case as
a - b * trunc(a / b). This free function is the portable float modulo of the two. It is
deliberately not named fmod, which in C and HLSL means the truncated one.
Component-wise. y may be a scalar broadcast over a vector x.
예제
예제
import { fn, mod, f32T } from 'typeshade'
// Fold an angle into one revolution, whatever sign it arrives with.const wrap = fn('wrap_angle', { a: f32T }, ({ a }) => mod(a, 6.283185307179586))대상별 지원
| 대상 | 지원 | 비고 |
|---|---|---|
| WGSL (WebGPU) | 지원 |
|
| GLSL ES 3.00 (WebGL2) | 지원 |
|
| CPU 오라클 | 지원 | Evaluated in f64 by the oracle. |
관련 가이드
함께 보기
소스
src/core/ir/node.ts, 1695행, 커밋 c66579bf 기준