BinOp
Type in IR
The operator tag on Expr.binop: arithmetic (+ - * /), remainder (%) and bitwise.
import type { BinOp } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
type BinOp = '+' | '-' | '*' | '/' | '%' | '&' | '|' | '^' | '<<' | '>>';Description
Each is spelled the same way in WGSL and GLSL and evaluated
the same way by the CPU backend. On floats % is a truncating remainder, so its sign
follows the dividend: WGSL’s native % behaves this way, and the GLSL backend writes
a - b * trunc(a / b) because GLSL ES 3.00’s own % is integer-only. When a negative
operand is possible and a floor modulo is wanted, use mod, which is floor-mod on
every target; the .mod() method on Node emits this truncating %. For integer
operands the CPU backend follows WGSL: two’s-complement wrap, truncating / with
x / 0 = x and x % 0 = 0, and <</>> as logical shifts on u32, with >> on
i32 an arithmetic (sign-preserving) shift.
See also
Source
src/core/ir/nodes.ts, line 28, at commit 26de7be8