Add flooring division (//) and modulus (%) operators#273
Open
AaronWebster wants to merge 1 commit into
Open
Conversation
Adds integer `//` (flooring division) and `%` (flooring modulus) to the Emboss expression language, following doc/design_docs/division_and_modulus.md. - Front end: `//`/`%` tokens; grammar splits the multiplicative tier into a `*`-chain and a `//`/`%`-chain that may not be mixed without parentheses (per the design doc); type check; and expression bounds. - Semantics: flooring, matching Python 3 (`-7 // 2 == -4`, `-7 % 2 == 1`). Constant folding reuses Python's `//`/`%`; the runtime FlooringQuotient / FlooringRemainder helpers convert C++'s truncating `/` and `%` for signed types (unsigned needs no conversion). - Division by zero: this initial rollout does not yet track an `undefined` value through the type system, so a divisor whose range includes zero is rejected at compile time. constant_value() folds `//`/`%` totally (a zero divisor yields no value instead of raising), so the diagnostic is reported cleanly rather than as a traceback. - Docs, unit tests (tokenizer, grammar, bounds, constraints, constant-folding, runtime arithmetic), an integration schema and golden, and formatter coverage.
This was referenced Jul 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 1 of 3 of the integer division/modulus series (base:
master), followingdoc/design_docs/division_and_modulus.md.Adds integer
//(flooring division) and%(flooring modulus) to the Embossexpression language.
What this does
///%tokens; the grammar splits the multiplicative tierinto a
*-chain and a///%-chain that may not be mixed withoutparentheses (per the design doc); type checking; and expression-bounds
computation.
-7 // 2 == -4,-7 % 2 == 1).Constant folding reuses Python's
///%; the runtimeFlooringQuotient/FlooringRemainderhelpers convert C++'s truncating/and%for signedtypes (unsigned needs no conversion).
undefinedvalue through the type system, so a divisor whose range includes zero is
rejected at compile time.
constant_value()folds///%totally (a zerodivisor yields no value instead of raising), so the diagnostic is reported
cleanly rather than as a traceback.
runtime arithmetic), an integration schema + golden, and formatter coverage.
Series
undefinedvalue.IsComplete()returns true for a division-by-zero size.Supersedes the stale WIP #263.
bazel test //...is green.PR chain (merge in order): #273 (this) → #274 → #275