Skip to content

Serialize xs:double/xs:float negative zero as -0#2639

Merged
ChristianGruen merged 1 commit intoBaseXdb:mainfrom
GuntherRademacher:serialize-negative-0
Apr 21, 2026
Merged

Serialize xs:double/xs:float negative zero as -0#2639
ChristianGruen merged 1 commit intoBaseXdb:mainfrom
GuntherRademacher:serialize-negative-0

Conversation

@GuntherRademacher
Copy link
Copy Markdown
Member

While reviewing qtspecs PR #2522 for changes requiring implementation in BaseX, some inconsistency was detected in how BaseX handles negative zero (-0) for xs:double and xs:float.

Casting is already correct - xs:double('-0') preserves the negative zero value internally, as confirmed by 1 div xs:double('-0') returning -INF. However, serialization is not correct: negative zero was output as 0 for xs:double, while it was output as -0 for xs: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 -0 is consistent with preserving the sign bit. Canonical JSON is the exception: RFC 8785 (referenced by the spec) mandates 0 there.

This PR fixes Dbl.string to return -0 for negative zero, and adds a canonical-mode check in JsonSerializer to 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).

@ChristianGruen ChristianGruen merged commit 0be3cea into BaseXdb:main Apr 21, 2026
1 check passed
@ChristianGruen ChristianGruen deleted the serialize-negative-0 branch April 21, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants