Issue #682: Part I does not say how integer / and % round, and does not list div_euclid/rem_euclid

Open and answer this issue on GitHub.

language, ready · opened 2026-10-19 · updated 2026-10-19 · 1 comment

Where it came from

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:

What is decided already:

Neither decides which way the result rounds.

What a decision has to say

  1. What / 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.
  2. Whether 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.

Recommendation

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.

Comments

keywan-ghadami, 2026-10-19

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

Back to Open Issues