[Fix](nereids) Preserve negative zero sign in SIGNBIT constant folding#63954
Merged
Conversation
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Collaborator
Author
|
/review |
Collaborator
Author
|
run buildall |
Contributor
There was a problem hiding this comment.
Reviewed the actual GitHub PR diff for PR #63954 (4 changed files). No blocking issues found.
Critical checkpoint conclusions:
- Goal and tests: The change preserves the sign of negative zero in Nereids constant folding for SIGNBIT. The added unit test and regression test cover +0.0 and -0.0, including fold-constant coverage.
- Scope: The actual PR diff is small and focused on SIGNBIT constant folding plus expected results.
- Concurrency and lifecycle: Not applicable; this is pure constant-folding logic with no shared mutable state or lifecycle changes.
- Configuration and compatibility: No config, storage format, wire protocol, or incompatible persistence changes.
- Parallel paths: Runtime SQL behavior is already expected to preserve signbit semantics; this aligns FE constant folding with that behavior.
- Special conditions: Using Double.doubleToRawLongBits checks the IEEE sign bit directly, which correctly distinguishes -0.0 from +0.0.
- Test coverage: Existing additions cover FE executable function behavior and SQL regression output for constants. No additional user-provided review focus was supplied.
- Observability, transactions, data writes, FE-BE variable passing, and memory tracking: Not applicable to this change.
- Performance: No concern; the replacement is constant-time and only used during constant folding.
Contributor
FE UT Coverage ReportIncrement line coverage |
Contributor
|
PR approved by at least one committer and no changes requested. |
Contributor
|
PR approved by anyone and no changes requested. |
Contributor
FE Regression Coverage ReportIncrement line coverage |
Contributor
TPC-H: Total hot run time: 29315 ms |
Contributor
TPC-DS: Total hot run time: 170634 ms |
github-actions Bot
pushed a commit
that referenced
this pull request
Jun 2, 2026
#63954) Problem Summary: `signbit` in Nereids FE constant folding used `value < 0` to determine the sign, which treats `-0.0` as non-negative and folds it to `false`. This is inconsistent with: - the runtime BE implementation, which uses `std::signbit` - the documented `signbit` behavior, which distinguishes `+0.0` and `-0.0` `+0.0` and `-0.0` compare equal numerically, so `value < 0` cannot distinguish them. Their difference is only recorded in the floating-point sign bit. Using raw bits makes FE constant folding consistent with BE runtime semantics. before: ```text Doris> set debug_skip_fold_constant=true; Query OK, 0 rows affected (0.024 sec) Doris> select signbit(cast('+0.0' as double)) , signbit(cast('-0.0' as double)); +---------------------------------+---------------------------------+ | signbit(cast('+0.0' as double)) | signbit(cast('-0.0' as double)) | +---------------------------------+---------------------------------+ | 0 | 1 | +---------------------------------+---------------------------------+ 1 row in set (0.108 sec) Doris> set debug_skip_fold_constant=false; Query OK, 0 rows affected (0.002 sec) Doris> select signbit(cast('+0.0' as double)) , signbit(cast('-0.0' as double)); +---------------------------------+---------------------------------+ | signbit(cast('+0.0' as double)) | signbit(cast('-0.0' as double)) | +---------------------------------+---------------------------------+ | 0 | 0 | +---------------------------------+---------------------------------+ ``` now: ```text Doris> set debug_skip_fold_constant=true; Query OK, 0 rows affected (0.012 sec) Doris> select signbit(cast('+0.0' as double)) , signbit(cast('-0.0' as double)); +---------------------------------+---------------------------------+ | signbit(cast('+0.0' as double)) | signbit(cast('-0.0' as double)) | +---------------------------------+---------------------------------+ | 0 | 1 | +---------------------------------+---------------------------------+ 1 row in set (0.070 sec) Doris> set debug_skip_fold_constant=false; Query OK, 0 rows affected (0.002 sec) Doris> select signbit(cast('+0.0' as double)) , signbit(cast('-0.0' as double)); +---------------------------------+---------------------------------+ | signbit(cast('+0.0' as double)) | signbit(cast('-0.0' as double)) | +---------------------------------+---------------------------------+ | 0 | 1 | +---------------------------------+---------------------------------+ 1 row in set (0.010 sec) ```
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.
Problem Summary:
signbitin Nereids FE constant folding usedvalue < 0to determine the sign, which treats-0.0as non-negative and folds it tofalse. This is inconsistent with:std::signbitsignbitbehavior, which distinguishes+0.0and-0.0+0.0and-0.0compare equal numerically, sovalue < 0cannot distinguish them. Their difference is only recorded in the floating-point sign bit. Using raw bits makes FE constant folding consistent with BE runtime semantics.before:
now: