/ and % round, and does not list div_euclid/rem_euclidOpen and answer this issue on GitHub.
language, ready · opened 2026-10-19 · updated 2026-10-19 · 1 comment
The 1BRC programs were changed to round the mean the way the official baseline does (Math.round, halves toward +∞; commit 02453be). In exact integer arithmetic that is floor((2*sum + count) / (2*count)), which needs a floor division when the numerator is negative. Nikaia accepts .div_euclid(…) on i64, and tools/*.nika already use it. The specification, however, says nothing about either point:
/ and % round on integers. Today they lower to Rust’s / and %, so the quotient rounds toward zero and the remainder takes the dividend’s sign: -7 / 2 == -3, -7 % 2 == -1. Part I does not state this. The only place the specification mentions rounding toward zero is a float’s truncating_i32().div_euclid and rem_euclid work, but the specification does not list them, so a program that uses them depends on behaviour nobody has decided.What is decided already:
checked_div and checked_rem return null on a zero divisor.Neither decides which way the result rounds.
/ and % on integers mean. Rounding toward zero, as in C, Rust, Java and Go, or toward −∞, as in Python. The overflow of MIN / -1 is ADR-285’s.div_euclid and rem_euclid, or a floor division and modulo, are part of std, under which names, and how they behave on a zero divisor and on overflow.Keep / and % as they are: rounding toward zero, with the remainder taking the dividend’s sign. That is what every program written so far assumes, and what C, Rust, Java and Go readers expect. Then state it in Part I and list div_euclid and rem_euclid (always ≥ 0 for rem), so that a floor or “always positive” result is written explicitly and does not rely on behaviour nobody decided.
This is bookkeeping: nothing is blocked by it. The 1BRC programs use div_euclid, and that runs today.
following the recommendation : What / and % on integers mean. Rounding toward zero, as in C, Rust, Java and Go because near to hardware, make migration easier. div_euclid and rem_euclid are part of std