fix: preserve negative zero in JSONB floating-point values - #7821
Open
DarrenChangJR wants to merge 1 commit into
Open
fix: preserve negative zero in JSONB floating-point values#7821DarrenChangJR wants to merge 1 commit into
DarrenChangJR wants to merge 1 commit into
Conversation
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.
What this PR does and why
JSONB currently changes
-0.0Fand-0.0Dinto positive zero. The writer'scompact integer encodings use numeric equality, under which negative zero equals
zero, and discard the IEEE-754 sign bit.
This change recognizes negative zero using raw bits and bypasses only the
integer/zero compact encodings. It then uses the existing
BC_FLOATorBC_DOUBLErepresentation, which preserves the sign. Positive zero, one, andother integral floating-point values remain compact.
The behavior matters even though
-0.0 == 0.0: raw-bit APIs distinguish thevalues, division produces infinities with different signs, and Fastjson2's text
path already preserves negative zero.
Tests
NegativeZeroTestcovers bothfloatanddoublethrough:Validation performed:
NegativeZeroTest;mvn -pl core clean testsuite: 7,977 tests, no failures;with all unrelated findings unchanged.
Checklist
中文说明
修改内容和原因
JSONB 当前会把
-0.0F和-0.0D编码成正零。writer 的紧凑整数编码使用数值相等判断,而负零与正零在该判断下相等,因此 IEEE-754 符号位会丢失。
本修改使用原始位识别负零,并且只让负零绕过整数/零的紧凑编码,继续使用现有
BC_FLOAT或BC_DOUBLE表示。正零、1 和其他可紧凑表示的浮点整数保持不变。回归测试覆盖 float/double 的无类型和显式类型标量、primitive/boxed 数组以及
primitive/boxed bean 字段,并用原始 IEEE-754 位比较结果。focused test、clean
full core 7,977 项测试和外部 JSONB invariant matrix 均通过。