All arithmetic is integer arithmetic on codes with truncation toward zero, and the result keeps the wider of the two operand types. Literals are quantized first (see Exactness).
Add and subtract
Exact on codes, saturating at the edge. Never underflows.
Multiply
The product of two codes divided by the scale, truncated toward zero. It can never overflow (both inputs are below 1) but it can underflow to 0.
Divide
a / b computes k_a × scale / k_b, truncated. Because every value is below 1, the quotient fits only when |a| < |b|; otherwise it overflows. Dividing by zero is a divide event.
x / x always overflows, because 1 is not representable. If you need a ratio that may reach 1, scale the numerator down first or compute on the host in floats and quantize the result.
sf.div(a, b, where=mask) on arrays divides only where the mask is true and never raises for the other elements. Arrays: elementwise →
Fused multiply-add
sf.fma(a, b, c) is a * b + c with the product truncated once, then one saturating add. It gives the same bits as writing a * b + c, which is tested on every width; it exists because the chip has an fma instruction and reductions are built from it.
Square root
isqrt(k × scale), truncated. A negative input is an invalid event with device value 0.
Negation, absolute value, powers
** accepts integer exponents of 1 or more only. The chain stops as soon as it reaches 0, so a large exponent is cheap.
Precedence
Python’s. a * b + c is the product, truncated, then the add, and matches sf.fma. There is no reassociation: (a + b) + c and a + (b + c) can differ by saturation, exactly as on the chip.
What raises SFUnsupportedError
//, %, bitwise operators, round(), and ** with a non-integer or negative exponent. Each would silently produce a non-Superfloat result; use x.code if you want integer arithmetic on the code.