Operators & Expressions

Precedence follows C.

component-wise on vectors/matrices; % works on floats too (sign follows dividend, like fmod) component-wise; result is a bool vector

HLSL 2021: scalar only, short-circuiting; use and(), or() for vectors integers only; shift amount is masked to the bit width

HLSL 2021: scalar condition only; use select(c, a, b) for vector conditions swizzle, struct member, array/vector/matrix index (type)expr, type(expr) DXC, compile-time

Precedence follows C. Integer division by zero is undefined; float division by zero yields ±INF or NaN.

float3 a = float3(1, 2, 3);
bool3  m = a > 1.5;                         // (false, true, true)
float3 r = select(m, a, 0);                 // HLSL 2021: (0, 2, 3)
// Pre-2021 equivalent: float3 r = m ? a : 0;   (component-wise ternary, no short-circuit)
bool3  both = and(a > 0, a < 3);            // (true, true, false)
float  rem = fmod(-5.5, 2.0);               // -1.5
uint   packed = (r8 << 24) | (g8 << 16) | (b8 << 8) | a8;