div_exact!
Static element-wise integer division that fails unless the divisor divides evenly. Integer and field arithmetic
div_exact! lhs, rhs
Divides lhs by rhs element-wise, taking each field element as its canonical integer in [0, p). Compilation fails if any quotient is not exact, which makes div_exact! a checked way to compute sizes such as the number of blocks in a vector.
Arguments
lhs- Static vector (or scalar) of dividends.
rhs- Static vector of divisors, the same length as
lhs. There is no broadcasting: dividing a vector by one number needs a divisor vector of the same length.
Returns
A static vector of quotients, the same length as the inputs. Expression form only.
Constraints
None. Both inputs must be static, so the result is computed at compile time.
Example
(let x) static n = div_exact! 12, 4 x * n
A divisor that does not divide evenly is a compile error:
(let x) static n = div_exact! 10, 4 x * n
Notes
Errors with inputs must be static for witness arguments and arguments are of mismatched dimension for unequal lengths. A zero divisor is not checked and panics inside the compiler. See also div_floor! and div_ceil!.
Used in the standard library
bdlop/bdlop_linear_nizk_verify, bdlop/bdlop_r1cs_verify, bits/add32_bits, bits/rotl32_bits, blake3/blake3_compress, blake3/blake3_core, blake3/blake3_g, blake3/blake3_rotate_rows, blake3/blake3_rotate_words, chacha/chacha_block, dilithium/mldsa/mldsa44_w_approx, dilithium/mldsa/mldsa44_w_approx_static, dilithium/mldsa/mldsa_intt_native, dilithium/mldsa/mldsa_ntt_native, ext/ext_eq_table, ext/ext_poly_eval, ext/ext_recompose, fields/assert_dilithium, fields/assert_mersenne61, fields/assert_milli32, keccak/keccak_sponge_shake, mat_transpose, mat_vec_mul, mersenne61/mldsa/mldsa_intt, mersenne61/mldsa/mldsa_ntt_q, mersenne61/mldsa/mldsa_pointwise, mersenne61/poseidon/poseidon_mersenne61_16_8_config, milli/mldsa/mldsa_ct1, milli/mldsa/mldsa_intt_sub, milli/mldsa/mldsa_ntt_z, milli/mldsa/mldsa_pointwise, milli/poseidon/poseidon_milli_16_16_config, milli/poseidon/poseidon_milli_16_1_config, milli/poseidon/poseidon_milli_32_16_config, milli/poseidon/poseidon_milli_40_16_config, polynomial/intt_negacyclic_vec, polynomial/ntt, polynomial/ntt_negacyclic_vec, polynomial/vec_poly_scalar_mul, polynomial/vec_polynomial_coef_mul, r1cs/r1cs_assert_field, r1cs/r1cs_compose_vertical, r1cs/r1cs_from_vec, slip/slip_r1cs_arg_verify, sym_mat_index, typed/typed_lattice_digest_bits