Serialize xs:double/xs:float negative zero as -0#2639
Merged
ChristianGruen merged 1 commit intoBaseXdb:mainfrom Apr 21, 2026
Merged
Serialize xs:double/xs:float negative zero as -0#2639ChristianGruen merged 1 commit intoBaseXdb:mainfrom
ChristianGruen merged 1 commit intoBaseXdb:mainfrom
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.
While reviewing qtspecs PR
#2522for changes requiring implementation in BaseX, some inconsistency was detected in how BaseX handles negative zero (-0) forxs:doubleandxs:float.Casting is already correct -
xs:double('-0')preserves the negative zero value internally, as confirmed by1 div xs:double('-0')returning-INF. However, serialization is not correct: negative zero was output as0forxs:double, while it was output as-0forxs:float.The serialization spec recommends that negative zero be output with a leading minus sign in non-canonical JSON serialization. For other output methods, outputting
-0is consistent with preserving the sign bit. Canonical JSON is the exception: RFC 8785 (referenced by the spec) mandates0there.This PR fixes
Dbl.stringto return-0for negative zero, and adds a canonical-mode check inJsonSerializerto suppress the minus sign when required. Tests are added across the affected serialization paths (adaptive, BaseX, JSON direct/attributes/W3,fn:serialize, string cast,bin:unpack-double,json:parse).