Fix math.round to use HALF_UP to match doc, cel-go/cel-cpp#1054
Merged
Conversation
3 tasks
l46kok
approved these changes
May 15, 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.
Summary
math.roundusesHALF_EVEN(banker's rounding) internally, but cel-java's own function declaration, cel-go's reference implementation, and cel-cpp's reference implementation all specify "ties round away from zero". cel-java is the outlier among the three official reference clients; this PR brings it into alignment by switching the binding toHALF_UP.±0.5,±2.5). The existing tie cases±1.5round to±2under bothHALF_UPandHALF_EVENand so could not catch the bug.Cross-implementation status
math.Round(float64(v))atext/math.go:6291.5/-1.5only)std::round(value)atmath_ext.cc:204math.round(42.5) == 43.0atmath_ext_test.cc:552DoubleMath.roundToLong(x, HALF_EVEN)atCelMathExtensions.java:8771.5/-1.5only)DoubleMath.roundToLong(x, HALF_UP)cel-cpp's test
math.round(42.5) == 43.0is the canonical discriminator: underHALF_EVENit would round to42(since 42 is even) and the test would fail. cel-cpp's suite would catch this bug today; cel-java's and cel-go'ssuites would not — both probe only
±1.5, which rounds to±2under either mode.